countbuttonpushes.java

来自「The code to demonstrate simple GUI in Ja」· Java 代码 · 共 30 行

JAVA
30
字号
import java.awt.*;import java.awt.event.*;import javax.swing.*;public class CountButtonPushes extends JFrame implements ActionListener {   private JButton button = new JButton("Press me");   private JLabel total = new JLabel( "Running total:");   private JTextField tally  = new JTextField(10);   private int count    = 0;   public CountButtonPushes() {      super("A Container With Components");      Container cp = getContentPane();      setSize(500,500);      cp.setLayout(new FlowLayout());      cp.add(total);      cp.add(tally);      cp.add (button);      button.addActionListener(this);      setVisible(true);      setDefaultCloseOperation(EXIT_ON_CLOSE);   }   public void actionPerformed( ActionEvent e ) {      count++;   // increment counter      tally.setText(Integer.toString(count));   }   public static void main(String args [] ) {         new CountButtonPushes();   }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?