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
| package engine;
import javax.swing.JApplet;
import javax.swing.*;
public class Main extends JApplet {
public void init() {
try{
java.awt.EventQueue.invokeAndWait(new Runnable(){
public void run(){
loginBox(0);
}
});
}catch(Exception e){
// Sorry, but we can't print anything anyway,
// so be a good fisher : catch it and then let it go.
} // catch's
} // init()'s
private void loginBox(int Tries){
getContentPane().removeAll();
repaint();
JLabel Consigne = new JLabel();
Consigne.setBounds(0,0,250,21);
Consigne.setText("Please enter your password :");
JLabel Echec = new JLabel();
Echec.setBounds(60,72,150,21);
Echec.setText("Wrong password.");
JPasswordField Password = new JPasswordField();
Password.setBounds(21,21,208,30);
String pass = new String(Password.getPassword());
JButton Validation = new JButton();
Validation.setBounds(98,51,54,21);
Validation.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
loginRequest("username", loginBox(1).pass);}
});
getContentPane().setLayout(null);
getContentPane().add(Consigne);
getContentPane().add(Password);
getContentPane().add(Validation);
if(Tries != 0){
getContentPane().add(Echec);
}
Validation.setText("Ok"); // We will set an image here later...
} // loginBox's
private void loginRequest(String Username ,String Password){
boolean ServerAnswer = false;
if(Password != "nunavut"){
ServerAnswer = false;
}
else{
ServerAnswer = true;
}
if(ServerAnswer){
initCombatScene();
}
else{
loginBox(1);
}
}
private void initCombatScene(){
getContentPane().removeAll();
repaint();
// To be continued ...
}
} // Class' |
Partager