📄 pushcounter.java
字号:
//********************************************************************// 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -