Can you give sample code to draw rectangle etc., etc.,?
sabapathy
Greenhorn
Joined: Oct 16, 2000
Posts: 10
posted
0
Can any one give a sample and simple code to draw rectangle on the screen using Frames(Applets are not covered by SCJP exam.so please give example in FRAMES). Thanks.
deekasha gunwant
Ranch Hand
Joined: May 06, 2000
Posts: 396
posted
0
Hi sabapathy, similar to applet u'll have to write all your drawing code in paint method of frame.. here is a small example.
sabapathy
Greenhorn
Joined: Oct 16, 2000
Posts: 10
posted
0
Thank You Deekasha....
sabapathy
Greenhorn
Joined: Oct 16, 2000
Posts: 10
posted
0
Hi Deekasha, Can you tell me why the following code is giving compilation error. Thanks for your time. Sakthivel. ---------------------------------------------------------------- import java.awt.*; import java.awt.event.*; class Drawing extends Frame { public static void main(String h[]) { Drawing dr = new Drawing(); dr.setSize(300,300); dr.setVisible(true); addWindowListener(new WindowHandler()); } public void paint(Graphics g) { g.drawRect(0,0,200,100); g.setColor(Color.cyan); g.fillRect(50,50,150,50); g.setColor(Color.black); g.drawString("Hello Sabapathy",60,60); g.drawOval(100,100,25,25); g.setColor(Color.red); g.fillOval(100,100,15,15); } class WindowHandler extends WindowAdapter { public void windowClosing(WindowEvent e) { System.exit(0); } } }
Sunitha Kumar
Greenhorn
Joined: Oct 17, 2000
Posts: 3
posted
0
Hello Sabapathy, In the above code you are instantiating non static inner class Window Handler inside the static main. Non static inner class can be instantiated inside static method like new Outer().new Inner(). This is the reason for the compilation error. Put the WindowHandler class outside the Drawing class and try compiling it. Sunitha
subject: Can you give sample code to draw rectangle etc., etc.,?