⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pushcounter.java

📁 java源程序 对初学者有很大的帮助 从简单到复杂
💻 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 + -