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);changed
g.setColor(Color.RED);
g.setColor(Color.RED);on ok ( first set the color and then drawing , remember Yo ), lz knot paste it
g.drawRect(20,20,40,40);
------ For reference only ---------------- -----------------------
drawing with canvas
没有评论:
发表评论