Results 1 to 3 of 3
  1. #1
    ngansamuel is offline Member
    Join Date
    Mar 2009
    Posts
    2
    Rep Power
    0

    Default How to draw a rectangle in the JPanel by inserting the X and Y

    I have done some of the program,but there are some fill in the blanks in it,i don't know what can i type in it.Please help me to fill in it.There are two programs.Thanks a lot.

    // PanalDraw.java
    import java.awt.Graphics;
    import javax.swing.JPanel;
    public class PanelDraw extends JPanel
    {
    _______ Rectangle rectangleList[] = new Rectangle[____];
    _______ int index = 0;
    static final long serialVersionUID=0; // avoid anymore warning
    public PanelDraw(Rectangle rect){
    addRect(_________);
    }
    public void ________(Rectangle ______){
    rectangleList[_______] = rect;
    index++;
    }
    public void paintComponent( Graphics g ){
    super.paintComponent( g );
    for (int i=0; i<_________; i++)
    rectangleList[i].paintComponent(g);
    }
    }


    // PanelDrawTest.java
    import java.awt.Graphics;
    import javax.swing.JPanel;
    public class PanelDrawTest {
    public static void main(String[] args) {
    String x1 = JOptionPane.showInputDialog("Enter x1");
    String y1 = JOptionPane.showInputDialog("Enter y1");
    String x2 = JOptionPane.showInputDialog("Enter x2");
    String y2 = JOptionPane.showInputDialog("Enter y2");
    Point point1 = new Point(Integer.parseInt(x1), Integer.parseInt(y1));
    Point point2 = new Point(Integer.parseInt(x2), Integer.parseInt(y2));
    PanelDraw myPanel = new PanelDraw(new Rectangle(point1, point2));
    JFrame application = new JFrame(__________); // creates a new JFrame
    application.setLocation(100, 100);
    application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    application.add(myPanel); // add the panel to the frame
    application.setSize( 300, 300 ); // set the desired size
    application.setVisible(true); // show the frame
    }
    }
    Last edited by ngansamuel; 03-22-2009 at 02:53 PM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    wishing you lots of _________ on this one.

    Seriously: The way this works is that first make a serious attempt at answering all the questions, then come here for help. Otherwise you're just appearing lazy, and I know you don't want to do that, right?

  3. #3
    ngansamuel is offline Member
    Join Date
    Mar 2009
    Posts
    2
    Rep Power
    0

    Default

    I have done it more than before ,but the space i really don't know the answer!Please help

Similar Threads

  1. Replies: 4
    Last Post: 08-28-2009, 07:50 PM
  2. Replies: 7
    Last Post: 04-14-2009, 08:12 PM
  3. how to draw x-y graph in Jpanel.--not in APPLET.
    By vincent2001@gmail.com in forum New To Java
    Replies: 2
    Last Post: 08-24-2008, 06:01 AM
  4. How to Draw a Rectangle in Java
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-23-2008, 12:09 AM
  5. Draw on JPanel, Help
    By carl in forum Java 2D
    Replies: 1
    Last Post: 07-31-2007, 07:56 AM

Posting Permissions

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