Results 1 to 3 of 3
- 03-21-2009, 05:57 AM #1
Member
- Join Date
- Mar 2009
- Posts
- 2
- Rep Power
- 0
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 01:53 PM.
-
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?
- 03-22-2009, 01:53 PM #3
Member
- Join Date
- Mar 2009
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
How to draw in a JPanel using Netbeans 6.1 GUI maker
By Gatts79 in forum New To JavaReplies: 4Last Post: 08-28-2009, 06:50 PM -
how to draw a fill rectangle using mouse and paintComponent?
By java_fun2007 in forum New To JavaReplies: 7Last Post: 04-14-2009, 07:12 PM -
how to draw x-y graph in Jpanel.--not in APPLET.
By vincent2001@gmail.com in forum New To JavaReplies: 2Last Post: 08-24-2008, 05:01 AM -
How to Draw a Rectangle in Java
By Java Tip in forum java.awtReplies: 0Last Post: 06-22-2008, 11:09 PM -
Draw on JPanel, Help
By carl in forum Java 2DReplies: 1Last Post: 07-31-2007, 06:56 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks