import java.awt.event.ActionEvent
import java.awt.event.ActionListener
import javax.swing.JButton
import javax.swing.JFrame
import javax.swing.JTextField
public class ShowButton implements ActionListener{
private JTextField textField = null
private JButton button = null
private JFrame frame = null
public ShowButton(){
frame = new JFrame("显示按钮文字")
button = new JButton("3")
textField = new JTextField("",20)
frame.setLayout(new FlowLayout(FlowLayout.CENTER))
frame.add(textField)
button.addActionListener(this)
frame.add(button)
frame.setSize(400, 100)
frame.setResizable(false)
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
frame.setVisible(true)
}
public void actionPerformed(ActionEvent e) {
textField.setText("")
textField.setText(button.getActionCommand())
System.out.println(button.getActionCommand()+"===")
}
public static void main(String[] args) {
new ShowButton()
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)