我试图让我的第二个按钮减去起始数字,但我不断收到错误,其中ButtonListener1位于(行23和47),我无法运行我的代码。
我不明白为什么它不起作用。
请联系我,如果我应该添加一些东西到按钮和操作在私人课程或主类。为什么我的第二个按钮不起作用?
package addsubtract;
import javax.swing.JApplet;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SubtractAdd extends JApplet {
private int APPLET_WIDTH = 300, APPLET_HEIGHT = 35;
private int num;
private JLabel label;
private JButton add;
private JButton subtract;
public void init()
{
num = 50;
add = new JButton ("Add");
add.addActionListener (new ButtonListener());
subtract = new JButton ("Subtract");
subtract.addActionListener ((ActionListener) new ButtonListener1());
label = new JLabel("Number: " + Integer.toString (num));
Container cp = getContentPane();
cp.setBackground (Color.PINK);
cp.setLayout (new FlowLayout());
cp.add(add);
cp.add(subtract);
cp.add(label);
setSize (APPLET_WIDTH, APPLET_HEIGHT);
}
private class ButtonListener implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
num++;
label.setText("Number: " + Integer.toString(num));
}
private class ButtonListener1 implements ActionListener
{
public void actionPerfomred (ActionEvent event)
{
num--;
label.setText("Number: " + Integer.toString(num));
}
}
}
}
什么是你得到 – Jobin
'但错误我不断收到错误'什么错误是什么,在哪一行? – user3437460
我们不能帮助您,直到您发布您的错误,它们发生在哪里 –