Results 1 to 4 of 4
  1. #1
    smiles101634 is offline Member
    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0

    Default Very new to Java

    Hello,

    I'm very new to Java and my professor laid this on me on the first week of school.

    import javax.swing.*;
    import java.awt.Graphics;
    import java.awt.Color;

    public class MyDrawing_Start extends JFrame {
    public MyDrawing_Start() {
    add (new MyPanel());
    }

    public static void main (String [] args){
    MyDrawing_Start frame = new MyDrawing_Start();
    frame.setTitle("My drawing demo");
    frame.setLocationRelativeTo(null);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    frame.setSize(250, 350);
    frame.setVisible(true);
    }
    }

    class MyPanel extends JPanel {

    I've sat here all day trying to understand what is going on in this program and he has asked me to alter the program so that it produces multiple lines (Didn't specify how many). He want to do it as a loop. I understand how to create a loop and all but I think my main problem is that I don't get what is going on here so I don't even know where to start. Am I supposed to start the loop in the "class Mypanel extends JPanel area" area. Any guidance would be appreciated. Thanks.

  2. #2
    smiles101634 is offline Member
    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0

    Default Re: Very new to Java

    sorry forgot about this whole section

    class MyPanel extends JPanel {
    protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    // For color use the either the next 2 lines or g.setColor(Color.BLUE);
    Color myColor = new Color(0, 0, 255);
    g.setColor(myColor);
    g.drawLine(10, 20, 50, 50);
    }
    }

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,197
    Rep Power
    19

    Default Re: Very new to Java

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,320
    Rep Power
    25

    Default Re: Very new to Java

    What happens when you compile and execute the program?

    Please edit the post and wrap the code in code tags.
    If you don't understand my response, don't ignore it, ask a question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •