Button bu = new Button("按我"); bu.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e){ System.out.println(((Button)e.getSource()).getLabel()); }
});
Button bu = new Button("按我"); TextField tf = new TextField(); bu.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e){ System.out.println(((Button)e.getSource()).getLabel()); tf.setText("嘎嘎嘎嘎嘎嘎"); }});
借用一下楼上的 少打几个字 Button bu = new Button("按我"); JTextField text = new JTextField(); bu.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e){ text.setText("你想要的文字"); } });
bu.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
System.out.println(((Button)e.getSource()).getLabel());
}
});
TextField tf = new TextField();
bu.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
System.out.println(((Button)e.getSource()).getLabel());
tf.setText("嘎嘎嘎嘎嘎嘎");
}});
Button bu = new Button("按我");
JTextField text = new JTextField();
bu.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
text.setText("你想要的文字");
}
});
textInfo.append("想追加的文字");
text.setText(textInfo.toString());