[989] in java-interest

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

Re: stand-alone apps

daemon@ATHENA.MIT.EDU (Paul Beerkens)
Wed Aug 16 08:08:14 1995

From: Paul Beerkens <beerkens@prl.philips.co.uk>
Date: Wed, 16 Aug 1995 08:39:40 +0100
To: java-interest@java.sun.com
Cc: dmath@cs.wustl.edu

> 
> I'm new to the list and apologize if this question
> is inappropriate.
> 
> I'm trying to write a java stand-alone application that
> opens a window and draws in it (the ultimate goal is
> simulation of robot navigation).  Perhaps it's because
> I've done almost no X programming, but I haven't been
> able to do this.  I have been able to open the window
> in an applet and draw in it.  But then I can't use the
> mouse in the window except to press buttons.  
> 
> So, if anyone can offer any suggestions or sample code
> for either opening a window from a stand-alone application
> or using the mouse in an applet spawned window, I would be
> very appreciateve.  Thanks.
>
> David Mathias
> Washington University

Try this:

import awt.Graphics;
import awt.Window;
import awt.Frame;
import awt.Color;

class GraphicsTest {
    static awt.Graphics MyGraphics;
public static void main (String argv [])
	{
	    awt.WServer MyWServer=new awt.WServer ();
	    MyWServer.start ();
            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 ();
	    for (int c=1;c++<1000;); //wait till frame is setup
            MyGraphics.setForeground (Color.black);
	    MyGraphics.fillRect (40,40,10,10);
	    MyGraphics.drawString ("test",10,10);

	    GraphicsOutput test=new GraphicsOutput (MyGraphics);
	    test.start ();
	}; 

public void Draw (Graphics G)
	{
	    MyGraphics.setForeground (Color.black);
	    MyGraphics.fillRect (40,40,10,10);
	    MyGraphics.drawString ("test",10,10);
	    //MyWindow.drawRect (10,10,40,40);    
	};
};


class GraphicsOutput extends Thread
{
    Graphics MyGraphics;
    GraphicsOutput (Graphics G)
	{
	    MyGraphics=G;
	};
public void run ()
	{
	    draw (MyGraphics);
	};
public void draw (Graphics G)
	{
	    System.out.println ("Test");
	};
    
};

Paul Beerkens
Philips Research
beerkens@prl.philips.co.uk
-
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