[302] in java-interest
It AWT to work!?
daemon@ATHENA.MIT.EDU (Randy Gordon - Sun Victoria SE)
Tue Jun 13 19:12:32 1995
Date: Tue, 13 Jun 1995 15:54:30 -0700
From: randyg@Canada.Sun.COM (Randy Gordon - Sun Victoria SE)
To: java-interest@java.Eng.Sun.COM
Hello,
First of all Java is great!
However, I've run across a problem with keyboard focus that is puzzling
me. If I create a child Window object within another Window object it
appears to capture all keyboard events?!? The program works the way I
expect if the child Window object is not created.
I've included below a standalone app that demonstrates the problem.
Any help would be greatly appreciated! (Using alpha3 for Solaris)
Thanks, Randy
import java.io.*;
import java.util.*;
import awt.*;
class Test2 {
public static void showtree(Component comp, int level) {
Object ch;
for (int i=0;i<level;i++) System.out.print(" ");
if (comp.name == null) {
System.out.print("No Name");
System.out.print("------");
System.out.println(comp.getClass().toString());
}
else {
System.out.print(comp.name);
if (level!=0)
System.out.print(","+comp.parent.name);
System.out.print("------");
System.out.println(comp.getClass().toString());
}
if (comp instanceof Container) {
for (int i=0;i<((Container)comp).children.length();i++) {
ch = ((Container)comp).getChild(i);
showtree((Component)ch,level+1);
}
}
}
public static void main (String args[]) {
Font fnt;
WServer ws = new WServer();
ws.start();
Frame fr = new Frame(ws,false,null,400,400,Color.lightGray);
fr.name = "myframe";
MyWindow win = new MyWindow(fr,"Window",Color.lightGray,400,400);
fnt = win.getFont("Dialog", Font.BOLD, 12);
fr.setDefaultFont(fnt);
fr.setTitle("Randy Gordon");
fr.reshape(100,100,400,400);
MenuBar mbar = new MenuBar(fr);
Menu men = new Menu("File",mbar);
new MenuItem("Foo",men);
new MenuItem("bar",men);
win.setLayout(null);
Hellobutton b = new Hellobutton("Press Me","button1",win);
b.move(100,100);
TextField txt = new TextField(null,"textfield1",win,true);
txt.move(100,200);
TextField txt2 = new TextField(null,"textfield2",win,true);
txt2.move(100,300);
fnt = win.getFont("Helvetica", Font.BOLD, 24);
txt.setFont(fnt);
// Hellobutton b2 = new Hellobutton("Press Me","button2",win);
// b2.move(100,300);
Resizer res = new Resizer(win,"resizer1",Color.red,50,50);
res.move(200,100);
fr.map();
showtree(fr,0);
}
}
class Hellobutton extends Button {
public Hellobutton(String l, String n, Container p) {
super(l,n,p);
}
public void selected(Component c, int pos) {
System.out.println("Hello");
System.out.println(name);
}
}
class MyWindow extends Window {
public MyWindow(Container c, String s, Color col, int x, int y) {
super(c,s,col,x,y);
}
public void handleKeyPress(char ch, boolean asc, int mod) {
System.out.print(ch);
System.out.println("--->MyWindow");
}
}
class Resizer extends Window {
public Resizer(Container c, String s, Color col, int x, int y) {
super(c,s,col,x,y);
}
public void handleKeyPress(char ch, boolean asc, int mod) {
System.out.print(ch);
System.out.println("--->Resizer");
}
/*
public void paint() {
graphics.setForeground(Color.black);
graphics.drawLine(0,0,50,50);
graphics.setForeground(Color.red);
graphics.drawLine(0,50,50,0);
}
*/
}
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com