1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
| import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JCheckBox;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;
import javax.swing.JTextField;
public class Fenetre extends JFrame{
private JPanel ecran = new JPanel();
private JLabel titre= new JLabel("Le nombre Mystere !");
private JLabel text1= new JLabel("Veuillez entrez le Nombre");
private JTextField espace1 = new JTextField("");
private JButton bouton_ok= new JButton("OK");
private int lvl = 0;
private Random rand = new java.util.Random();
private JLabel text2= new JLabel("");
public Fenetre(){
this.setTitle("Le Nombre Mystere...");
this.setSize(400, 400);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
ecran.setBackground(Color.WHITE);
ecran.setLayout(new BorderLayout());
espace1.setPreferredSize(new Dimension(100,20));
bouton_ok.addActionListener(new ok());
//===========================================================
JOptionPane bienvenue;
bienvenue = new JOptionPane();
bienvenue.showMessageDialog(null, "Bienvenue dans le jeu...", "Nombre Mystere", JOptionPane.INFORMATION_MESSAGE);
String[] lvl = {"1-100", "1-500", "1-1000"};
JOptionPane jop = new JOptionPane(), jop2 = new JOptionPane();
String nom = (String)jop.showInputDialog(null, "Veuillez Chisir le niveau !","Niveau",JOptionPane.QUESTION_MESSAGE,null,lvl,lvl[2]);
//===========================================================
if(nom.equals("1-100"))
{
int rand = new Random().nextInt(100);
JOptionPane.showMessageDialog(null,"Le chiffre est: " + rand);
}
if(nom.equals("1-500"))
{
int rand = new Random().nextInt(500);
}
if(nom.equals("1-1000"))
{
}
System.out.println(rand);
JPanel top = new JPanel();
top.add(titre);
top.add(text1);
top.add(espace1);
top.add(bouton_ok);
top.add(text2);
ecran.add(top, BorderLayout.CENTER);
this.setContentPane(ecran);
this.setVisible(true);
}
class ok implements ActionListener{
public void actionPerformed(ActionEvent e) {
if(espace1.getText().equals(rand))
{
System.out.println("true");
}
else
{
System.out.println("False");
}
}
} |
Partager