[310] in java-interest

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

Re: access to container or window

daemon@ATHENA.MIT.EDU (Lein Ton)
Wed Jun 14 12:32:05 1995

Date: Wed, 14 Jun 1995 12:05:31 -0400
From: ton@cc.gatech.edu (Lein Ton)
To: rizzotti.sven@ch.swissbank.com
Cc: java-interest@java.sun.com

----------
X-Sun-Data-Type: text
X-Sun-Data-Description: text
X-Sun-Data-Name: text
X-Sun-Content-Lines: 21


> ----- Begin Included Message -----
> 
> A lot of the classes like List, TextField etc. need a container which can be  
> a form or a window. where do I get this variable from inside my applet  
> subclass ?
> 
> __Sven

----- End Included Message -----


Included is a program that opens a window within
the hotjava screen. I added a textfield and 
ended up having the same problem that Randy
Gordon had (textfields don't accept input). I hope
the program includes the things you want to know,
otherwise I don't understand your problem.

have fun,
Lein Ton
----------
X-Sun-Data-Type: default
X-Sun-Data-Description: default
X-Sun-Data-Name: LineDrawer.java
X-Sun-Content-Lines: 79

import awt.*;
import browser.*;

class LineDrawer extends Applet {
	int xStart=0;
	int yStart=0;
	int xEnd = 0;
	int yEnd = 0;
	MovingButton aButton;
 	MyWindowClass aWindow;
	TextField aTextField;
   	public void mouseDown(int x, int y) {
		xStart = x;
		yStart = y;
		aWindow.scrollVertically(10);
	}
	public void mouseUp(int x, int y) {
		xEnd = x;
		yEnd = y;
		repaint();
 	}
	public void init() {
		resize(200, 200);
 		aWindow = new MyWindowClass(item.parent);
		aWindow.setSticky(true);
 		aWindow.drawString("I'm fine", 1,1);
		aWindow.map();
		aButton = new MovingButton("press me too" ,"", item.parent);	
		aButton.map();
		aTextField = new TextField(new String(""), new String(""),item.parent, true);
		aTextField.move(150,10);
		aTextField.map();

  	}
	public void stop() {
		aTextField.dispose();
		aButton.dispose();
		aWindow.dispose();
 		super.stop();
	}
	public void destroy() {
// remember to always dispose the items in the reverse order the were created.
		aTextField.dispose();
		aButton.dispose();
		aWindow.dispose();
  		super.destroy();
	}
 	public void paint(Graphics g) {
		g.drawLine(xStart, yStart, xEnd, yEnd); 
	}
};
class MovingButton extends Button {
	int xCoord = 1;
	int yCoord = 1;
	public MovingButton(String l, String n, Window p) {
		super(l, n, p);
	}
	public void selected(Component c, int pos) {
		move((xCoord=xCoord+10),(yCoord=yCoord+10));
		 
	}
}

class MyWindowClass extends DisplayItemWindow {
	MovingButton aButton;
	Scrollbar aScrollbar;
	public MyWindowClass(DisplayItemWindow parent) {
		super(parent, new String(""));
		aButton = new MovingButton("Press Me", "", this);
		aButton.map();
 		setSticky(false);
	}
	public void dispose() {
		aButton.dispose();
		super.dispose();
	}
}
		

-
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