复件 pushcounter.java
来自「java源程序 对初学者有很大的帮助 从简单到复杂」· Java 代码 · 共 56 行
JAVA
56 行
//********************************************************************// PushCounter.java Authors: Lewis/Loftus//// Demonstrates a graphical user interface and an event listener.//********************************************************************import java.awt.*;import java.awt.event.*;import javax.swing.*;public class PushCounter extends JApplet{ private int APPLET_WIDTH = 300, APPLET_HEIGHT = 35; private int pushes; private JLabel label; private JButton push; //----------------------------------------------------------------- // Sets up the GUI. //----------------------------------------------------------------- public void init () { pushes = 0; push = new JButton ("Push Me!"); push.addActionListener (new ButtonListener()); label = new JLabel ("Pushes: " + Integer.toString (pushes)); Container cp = getContentPane(); cp.setBackground (Color.cyan); cp.setLayout (new FlowLayout()); cp.add (push); cp.add (label); setSize (APPLET_WIDTH, APPLET_HEIGHT); } //***************************************************************** // Represents a listener for button push (action) events. //***************************************************************** private class ButtonListener implements ActionListener { //-------------------------------------------------------------- // Updates the counter when the button is pushed. //-------------------------------------------------------------- public void actionPerformed (ActionEvent event) { pushes++; label.setText("Pushes: " + Integer.toString (pushes)); repaint (); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?