I am just starting to learn a little java graphics and have a small problem. When i set the stroke colour or fill colour nothing happens, the shape is drawn with a standard colour and is never filled. I have two classes, draw() and shapes() the code for both is shown. what am i missing people?
draw,
package drawingShapes;
import java.awt.*;
import javax.swing.JPanel;
public class draw extends JPanel {
public void drawing() {
repaint();
}
public void paintComponent (Graphics g){
this.paintComponent(g);
g.setColor(Color.green);
g.fillRect(10, 15, 100, 20);
}
}
shapes,
package drawingShapes;
import javax.swing.JFrame;
/**
*
* @author robert
*/
public class shapes {
public static void main (String[] args){
JFrame frame = new JFrame("test frame");
frame.setVisible(true);
frame.setSize(400, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
draw yourObject = new draw();
frame.add(yourObject);
yourObject.drawing();
}
}
First to solve wins a thumbs up!

New Topic/Question
Reply




MultiQuote






|