于 2007-05-15 11:47
希望能在按下Button后,调用TextField中的值,并修改Button上显示的名字,但不知如何处理。
程序如下:
import java.awt.*;
public class myButtons {
public static void main(String[] args) {
Frame f=new Frame("SoftPhone");
f.setLayout(new FlowLayout());
TextField tf1=new TextField("Tserver IP",30);
TextField tf2=new TextField("Tserver Port",20);
TextField tf3=new TextField("PlaceID",20);
TextField tf4=new TextField("AgentID",20);
TextField tf5=new TextField("PhoneNumber",20);
ConnectButton button0=new ConnectButton("Connect");
Button button1=new Button("Login");
Button button2=new Button("Ready");
Button button3=new Button("Make call");
Button button4=new Button("Release call");
MyButton button5=new MyButton("sub test");
f.add(tf1);
f.add(tf2);
f.add(button0);
f.add(tf3);
f.add(tf4);
f.add(button1);
f.add(button2);
f.add(tf5);
f.add(button3);
f.add(button4);
f.add(button5);
f.setSize(550,150);
f.setVisible(true);
}
}
class ConnectButton extends Button{
ConnectButton(String lable){
super(lable);
}
public boolean action(Event e,Object arg){
//String s=tf1.getText;
System.out.println("Pressed ConnectButton: "+arg);
System.out.println("Event: "+e);
return true;
}
}
class MyButton extends Button{
MyButton(String lable){
super(lable);
}
public boolean action(Event e,Object arg){
System.out.println("Pressed Button: "+arg);
System.out.println("Event: "+e);;
return true;
}
}