关于FocusListener监听问题
我做了两个单选按钮,想点击某个的时候获得其值.比方说我想获得all的”所有人”程序如下,可是测试了很久一直找不到正确的方法,谁能帮我看看吗?
paramString()不行,点all输出的是n1的内容,而且内容很长.
import java.net.*;
import java.awt.event.*;
import java.awt.*;
import java.sql.*;
public class Test implements FocusListener{
public void dd() {
CheckboxGroup nlst = new CheckboxGroup();
Checkbox all = new Checkbox("所有人", nlst, false);
Checkbox n1 = new Checkbox("测试", nlst, false);
all.addFocusListener(this);
n1.addFocusListener(this);
Label lab=new Label("");
lab.setBackground(Color.lightGray);
System.out.print(all.getLabel());
Panel p=new Panel();
Frame f=new Frame("hi");
f.setSize(300,300);
p.add(all);
p.add(n1);
p.add(lab);
f.add(p);
f.setVisible(true);
}
public static void main(String[] args) {
Test t = new Test();
t.dd();
}
public void focusGained(FocusEvent e) {
System.out.println(e.paramString());
}
public void focusLost(FocusEvent e) {
}
}
paramString()不行,点all输出的是n1的内容,而且内容很长.
import java.net.*;
import java.awt.event.*;
import java.awt.*;
import java.sql.*;
public class Test implements FocusListener{
public void dd() {
CheckboxGroup nlst = new CheckboxGroup();
Checkbox all = new Checkbox("所有人", nlst, false);
Checkbox n1 = new Checkbox("测试", nlst, false);
all.addFocusListener(this);
n1.addFocusListener(this);
Label lab=new Label("");
lab.setBackground(Color.lightGray);
System.out.print(all.getLabel());
Panel p=new Panel();
Frame f=new Frame("hi");
f.setSize(300,300);
p.add(all);
p.add(n1);
p.add(lab);
f.add(p);
f.setVisible(true);
}
public static void main(String[] args) {
Test t = new Test();
t.dd();
}
public void focusGained(FocusEvent e) {
System.out.println(e.paramString());
}
public void focusLost(FocusEvent e) {
}
}