我在这里有一个小 JLabel 计数器程序,当我按下“+1”时,它基本上应该向计数器添加一个数字,但是当我尝试运行它时,它说它无法在我的 tCounter.ButtonAction 类中找到主类到目前为止我的代码希望你能帮助我。
package tCounter;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
public class ButtonAction {
static int Zahl = 0;
public static void createAndShowGUI() {
JFrame frame1 = new JFrame("JAVA");
frameg1.setText(String.valueOf(Zahl));
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton button = new JButton("+1");
//Add action listener to button
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
//Execute when button is pressed
//System.out.println("You clicked the button");
Zahl = Zahl +1;
String Penis = Integer.toString(Zahl);
System.out.println(Zahl);
}
});
frame1.getContentPane().add(button);
frame1.pack();
frame1.setVisible(true);
}
private static class frameg1 {
private static void setText(String valueOf) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
public frameg1() {
}
}
}