在按钮的相应事件中添加:
JLabel.setText(String.valueOf((Integer.parseInt(JLabel.getText())+1)));

解决方案 »

  1.   


    static int i;
    在action中
    label.setText( "num"+(i++));
      

  2.   


    /*<APPLET CODE="tmp.class" WIDTH=200 HEIGHT=200>
    </APPLET>
    */
    import java.awt.*;
    import java.applet.*;public class tmp extends Applet {  Button button;
      Label l;
    static int i;
     public void init() {
           button = new Button("Erase");
    i=0;
            l=new Label();
            this.add(button);
            this.add(l);
            this.setBackground(Color.white);  // Set background color for scribble
            this.requestFocus();  // Ask for keyboard focus so we get key events
        }    /** Respond to mouse clicks */
       public boolean action (Event evt, Object arg) {
        if(evt.target.equals(button))
          l.setText( "num"+(i++));return true;   }}
      

  3.   

    上面给了个小程序,我给个应用程序,已调试通过!大家互相帮助啊!!!
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;public class ClickTest extends JFrame{
      JPanel contentPane;
      JLabel l=new JLabel("0");
      JButton b=new JButton("点击计数");
      int count;  BorderLayout borderLayout1 = new BorderLayout();  public ClickTest(){
        super("ClickTest");
        contentPane = (JPanel) this.getContentPane();
        contentPane.setLayout(borderLayout1);
        this.setSize(new Dimension(200, 100));    contentPane.add(l, BorderLayout.CENTER);
        contentPane.add(b, BorderLayout.SOUTH);    b.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent e) {
            ++count;
            l.setText(String.valueOf(count));
          }
        });
      }  protected void processWindowEvent(WindowEvent e) {
        super.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
          System.exit(0);
        }
      }  public static void main(String []a){
        ClickTest ct=new ClickTest();
        ct.setVisible(true);
      }
    }