2013年12月17日星期二

setColor problem

Will prawn why following procedures rectangle is drawn black border ?

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

class DrawRectangle extends JFrame
{
public static void main (String [] args)
{
DrawRectangle dr = new DrawRectangle ();
dr.setSize (200,200);
dr.setDefaultCloseOperation (dr.EXIT_ON_CLOSE);
dr.add (new MyPanel ());
dr.setVisible (true);

}
}

class MyPanel extends JPanel
{
public void paint (Graphics g)
{
super.paint (g);
g.drawRect (20,20,40,40);
g.setColor (Color.RED);
}
}
------ Solution ----------------------------------- ---------
g.drawRect(20,20,40,40);
g.setColor(Color.RED);
changed
g.setColor(Color.RED);
g.drawRect(20,20,40,40);
on ok ( first set the color and then drawing , remember Yo ), lz knot paste it
------ For reference only ---------------- -----------------------
drawing with canvas

没有评论:

发表评论