[158] in java-interest

home help back first fref pref prev next nref lref last post

Re: awt.Graphics why doesn't draw something on the screen

daemon@ATHENA.MIT.EDU (Arthur van Hoff)
Tue May 30 13:33:18 1995

Date: Tue, 30 May 1995 09:57:45 -0700
From: Arthur.Vanhoff@Eng.Sun.COM (Arthur van Hoff)
To: java-interest@java.Eng.Sun.COM

Hi Paul,

> import awt.Graphics;
> import awt.Window;
> import awt.Frame;
> import awt.Color;
> 
> class GraphicsTest {
> public static void main (String argv [])
> 	{
> 	    awt.WServer MyWServer=new awt.WServer ();
> 	    MyWServer.start ();
>             Graphics MyGraphics;
> 	    Window MyWindow;
> 	    Frame MyFrame;
> 
> 	    MyFrame=new Frame (MyWServer,true,false,null,300,300,Color.gray);
> 	    MyFrame.setTitle ("Graphics Test Frame");
> 	    
>             MyWindow=new Window ( MyFrame,"Center",Color.white,200,200);
> 
> 	    MyGraphics = new Graphics (MyWindow);   
> 	    MyFrame.map ();
> 	    MyGraphics.setForeground (Color.black);
> 	    MyGraphics.fillRect (40,40,10,10);
> 	    MyGraphics.drawString ("test",10,10);
> 	    MyWindow.drawRect (10,10,40,40);
> 	    
> 	}; 
> };
> 
> Why doesn't this program draw a Rectangle or a String in the Frame ??
> 
> Please help me out.

In order to draw something in a window you need to subclass it and
overide the paint method. In the program above you are painting into
the window before the window actually has become visible on the
screen. The awt thread needs to run for a bit to make stuff happen
on the screen.

Have fun,

	Arthur van Hoff (avh@eng.sun.com)
	http://java.sun.com/people/avh/

PS: For questions about HotJava and/or Java please use our
mailing lists java-interest@java.sun.com or hotjava-interest@java.sun.com
instead of mailing me directly. Thanks.

-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post