I want to make a project when you finish clicking 10 times (to 0) it opens a new window.
The code is here:
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class game implements ActionListener{
static int count = 10;
static JLabel label = new JLabel("" + count, SwingConstants.CENTER);
public static void main(String[] args) {
JFrame frame = new JFrame();
JButton button = new JButton("Click me!");
frame.add(label);
frame.setLocationRelativeTo(null);
frame.setSize(500, 400);
frame.setLayout(new GridLayout(0, 1));
frame.add(button);
button.addActionListener(new game());
frame.setVisible(true);
if(count == 0) {
count = 100;
label.setText(count + "");
JFrame win_frame = new JFrame();
JLabel win_label = new JLabel("You win!", SwingConstants.CENTER);
win_frame.add(win_label);
win_frame.setLocationRelativeTo(null);
win_frame.setSize(500, 400);
win_frame.setVisible(true);
}
}
@Override
public void actionPerformed(ActionEvent e) {
label.setText("" + count--);
}
}
and I don't know which variable to use for the if statement. Should I use count
, label
(I can't make it support an int) or make a new variable?
Aucun commentaire:
Enregistrer un commentaire