Hi guys,
I have a class (DrawPanel) which extends Jpanel.This class generates random shapes (lines,recangles and ovals) . I am suppose to add a statusbar to this class but I can't add even a simple lable to this panel... I am so frustrated and would be so appreciate if anyone can help me to figure it out.
Thanks
Hany
public class DrawPanel extends JPanel {
private MyShape shapes[];
private Random randomNumber;
private int shapeType;
int lineCount=0, rectCount=0, ovalCount=0;
public DrawPanel(){
randomNumber = new Random();
int count = 1+randomNumber.nextInt(10);
shapes = new MyShape[count];
for(int i=0; i<count;i++){
/* Generate random coordinates */
int x1 = randomNumber.nextInt(300);
int y1 = randomNumber.nextInt(300);
int x2 = randomNumber.nextInt(300);
int y2 = randomNumber.nextInt(300);
Color color = new Color(randomNumber.nextInt(256),randomNumber.nextInt(256),randomNumber.nextInt(256));
/* Initiate Shapes */
shapeType =randomNumber.nextInt(3);
if (shapeType==0){ // Line
lineCount++;
shapes[i] = new MyLine(x1,y1,x2,y2,color);
}
else if (shapeType==1){ // Rectangle
rectCount++;
shapes[i] = new MyRectangle(x1,y1,x2,y2,color,true);
}
else { // Oval
ovalCount++;
shapes[i] = new MyOval(x1,y1,x2,y2,color,true);
}
}
}
public void paint(Graphics g){
for (MyShape shape:shapes)
shape.draw(g);
}
}
--------------------------------------- TestClass------------------------------
public class TestDraw {
public static void main (String[] args){
DrawPanel panel = new DrawPanel();
JFrame frame = new JFrame();
frame.setBackground(Color.white);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(panel);
frame.setSize(300,300);
frame.setVisible(true);
}
}