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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
mport java.awt.Color;
import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.Font;
import java.util.Random;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
public class Aire_disquz extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JLabel TextInfo;
private JTextField ValeurATester;
private JLabel Enoncer;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Aire_disquz frame = new Aire_disquz();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public Aire_disquz() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 686, 397);
contentPane = new JPanel();
contentPane.setForeground(Color.BLUE);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.add(getTextInfo());
//contentPane.add(getBoutonCalcul());
contentPane.setLayout(null);
// contentPane.add(getValeurATester());
// contentPane.add(getBtnNewButton_1());
contentPane.add(getEnoncer());
contentPane.add(buildContentPane());
contentPane.add(getTextField_1());
contentPane.add(getBtnNewButton());
}
//affichage enoncer
private JLabel getEnoncer() {
if (Enoncer == null) {
Enoncer = new JLabel("Ecrivez en chiffre le nombre qui s'affiche :");
Enoncer.setBounds(120, 11, 505, 64);
Enoncer.setForeground(new Color(199, 21, 133));
Enoncer.setFont(new Font("Curlz MT", Font.PLAIN, 24));
}
return Enoncer;
}
//déclaration de la variable random z1
Random r = new Random();
int z1 = r.nextInt(10000);
private JLabel getTextInfo() {
if (TextInfo == null) {
String [] vingt = {"zéro","un","deux","trois","quatre","cinq","six","sept","huit","neuf","dix","onze","douze","treize","quatorze","quinze","seize","dix-sept","dix-huit","dix-neuf","vingt",
" vingt-et-un","vingt-deux","vingt-trois","vingt-quatre","vingt-cinq","vingt-six","vingt-sept","vingt-huit","vingt-neuf","trente","trente-et-un","trente-deux","trente-trois","trente-quatre","trente-cinq",
"trente-six","trente-sept","trente-huit","trente-neuf","quarante","quarante-et-un","quarante-deux","quarante-trois","quarante-quatre","quarante-cinq","quarante-six","quarante-sept","quarante-huit","quarante-neuf","cinquante",
"cinquante-et-un","cinquante-deux","cinquante-trois","cinquante-quatre","cinquante-cinq","cinquante-six","cinquante-sept","cinquante-huit","cinquante-neuf","soixante","soixante-et-un","soixante-deux","soixante-trois",
"soixante-quatre","soixante-cinq","soixante-six","soixante-sept","soixante-huit","soixante-neuf","soixante-dix","soixante-et-onze","soixante-douze","soixante-treize","soixante-quatorze","soixante-quinze","soixante-seize",
"soixante-dix-sept","soixante-dix-huit","soixante-dix-neuf","quatre vingt un","quatre vingt deux","quatre vingt trois","quatre vingt quatre","quatre vingt cinq","quatre vingt six","quatre vingt sept","quatre vingt huit","quatre vingt neuf",
"quatre vingt dix","quatre vingt onze","quatre vingt douze","quatre vingt treize","quatre vingt quatorze","quatre vingt quinze","quatre vingt seize","quatre vingt dix-sept","quatre vingt dix-huit","quatre vingt dix-neuf"};
String [] centaine = {"","cent","deux cent ","trois cent ","quatre cent ","cinq cent ","six cent ","sept cent ","huit cent ","neuf cent "};
String [] mille = {"","mille ","deux mille ","trois mille ","quatre mille ","cinq mille ","six mille ","sept mille ","huit mille ","neuf mille "};
//valeur léttrée de la variable z tiré au sort(random) grâce aux tableaux
int n = z1 % 1000;
int a = n % 100;
int m = z1 / 1000;
int c = n/100;
String nombrer1 = mille[m] + centaine[c] + vingt[a];
TextInfo = new JLabel(nombrer1 );
TextInfo.setFont(new Font("Curlz MT", Font.PLAIN, 24));
TextInfo.setForeground(new Color(199, 21, 133));
TextInfo.setBounds(109, 57, 551, 109);
}
return TextInfo;
}
private JTextField textField_1;
private JButton btnNewButton;
private JPanel buildContentPane(){
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout());
JTextField textField = new JTextField();
textField.setColumns(10);
textField = new JTextField();
panel.add(textField);
return panel;
}
private JTextField getTextField_1() {
if (textField_1 == null) {
textField_1 = new JTextField();
textField_1.setBounds(209, 161, 218, 44);
textField_1.setColumns(10);
ligne 142 String str = ValeurATester.getText();
Valeur = Integer.parseInt(str);
}
return textField_1;
}
int Valeur;
private JButton getBtnNewButton() {
if (btnNewButton == null) {
btnNewButton = new JButton("Valider");
btnNewButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
if(z1== Valeur) {
System.out.println("Bravo");
}
}
}
);
btnNewButton.setBounds(235, 244, 148, 78);
}
return btnNewButton;
}
} |
Partager