📄 testgui.java
字号:
import java.awt.*;import java.awt.event.*;import javax.swing.*;public class TestGUI extends JFrame implements ActionListener{ private JButton button1 = new JButton ("Button 1"); private JButton button2 = new JButton ("Button 2"); private JButton button3 = new JButton ("Clear"); private JTextField tally = new JTextField(30); public TestGUI() { super("A Container With Components"); Container cp = getContentPane(); setSize(500,500); cp.setLayout(new FlowLayout()); cp.add (button1); cp.add (button2); cp.add (button3); cp.add(tally); button1.addActionListener(this); button2.addActionListener(this); button3.addActionListener(this); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); } public void actionPerformed( ActionEvent e ){ if (e.getSource() == button1) tally.setText("Button 1 is calling"); if (e.getSource() == button2) tally.setText("Button 2 is calling"); if (e.getSource() == button3) tally.setText(""); } public static void main(String args [] ) { new TestGUI(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -