所以在我的程序中按按钮不起作用。我有它,如果按下它们,它们会更改一些变量,这些变量反过来会更改文本的标签。据我所知,按下按钮时变量不会添加。我不知道出了什么问题,但是我又是Java新手,所以...
无论如何,这是我的代码:
import javax.swing.JApplet;
import javax.swing.JButton;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JProgressBar;
import javax.swing.JFormattedTextField;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
public class qa extends JApplet {
int y=0;
int x=0;
int q=0;
/**
* Create the applet.
*/
public qa() {
getContentPane().setLayout(null);
JButton btnYes = new JButton("YES");
btnYes.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
y+=1;
q+=1;
}
});
btnYes.setBounds(135, 220, 85, 42);
getContentPane().add(btnYes);
JButton btnNo = new JButton("NO");
btnNo.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
x+=1;
q+=1;
}
});
btnNo.setBounds(230, 220, 85, 42);
getContentPane().add(btnNo);
JLabel lblNewLabel = new JLabel("Do you like pizza?");
lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
lblNewLabel.setBounds(0, 97, 450, 50);
getContentPane().add(lblNewLabel);
if (q>=1)
{
lblNewLabel.setText("Really?");
}
}
}
谢谢你的帮助!