Ce code est il bon?

Fermé
champity Messages postés 13 Date d'inscription mercredi 8 avril 2009 Statut Membre Dernière intervention 18 mai 2010 - 13 avril 2009 à 11:27
Kharec Messages postés 4146 Date d'inscription dimanche 20 avril 2008 Statut Contributeur Dernière intervention 8 mai 2011 - 13 avril 2009 à 11:57
Bonjour,
je voudrais compiler le code suivant mais lorce que j'appuie sur le bouton "continuer" erreur: at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)



voici le code:



premiere class:

public class ZDialogInfo {

private String login;
char[] password;

public ZDialogInfo(){}
public ZDialogInfo(String login, char[] password){

this.login = login;
this.password = password;
}

//-----------------------------------------
public String getlogin() {
return login;

}

//-------------------------------------

public char[] getpassword() {
return password;
}
//-----------------------------------------


public String toString(){
String str;
if(this.login == "JCVAL") {
str = "login : " + this.login + "\n";
str = "password : " + this.password + "\n";
}

else{

str = "aucune information";
}
return str;


}
}





seconde class:


import javax.swing.*;
import java.awt.*;
import java.awt.event.*;


public class ZDialog extends JDialog {

private ZDialogInfo zInfo = new ZDialogInfo();
private boolean sendData;
private JLabel loginLabel, passwordLabel;
private JComboBox login;
private JPasswordField password;



//**************constructeur*************************
// * *
// *


public ZDialog(JFrame parent, String title, boolean modal){
super(parent, title, modal);
this.pack();
this.setLocationRelativeTo(null);
this.setResizable(false);
this.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
this.initComponent();
this.setVisible(true);
}

// METHODE
// * *
// *


public ZDialogInfo showZDialog(){
this.sendData = false;
this.setVisible(true);
return this.zInfo;
}

// contenue de la boîte
// * *
// *

private void initComponent (){

//le login::
JPanel panLogin = new JPanel() ;
panLogin.setBackground(Color.WHITE);
panLogin.setPreferredSize(new Dimension(50,50));
panLogin.add(loginLabel);
panLogin.add(login);
login.addItem("jérémy");
login.addItem("autres...");


//le password
JPanel panPassword = new JPanel () ;
panPassword.setBackground(Color.WHITE);
password = new JPasswordField();
panPassword.setPreferredSize(new Dimension(50,50));
panPassword.add(passwordLabel);
panPassword.add(password);
final char[] c = password.getPassword();
String s = new String(c);



JPanel content = new JPanel ();
content.setBackground(Color.WHITE);
content.add(panLogin);
content.add(panPassword);


JPanel control = new JPanel ();
JButton okButton = new JButton ("continuer");
JButton cancelButton = new JButton ();
okButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {

zInfo = new ZDialogInfo((String)login.getSelectedItem(), (char [])password.getPassword());

setVisible(false);
}});
cancelButton.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e) {

setVisible(false);
// TODO Auto-generated method stub

}









});
control.add(okButton);
control.add(cancelButton);

this.getContentPane().add(content, BorderLayout.WEST);
this.getContentPane().add(control,BorderLayout.SOUTH);




}


}



troisieme class :


import java.awt.*;
import javax.swing.*;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;




public class Fenetre extends JDialog {
private JButton btn = new JButton ("continuer");

public Fenetre() {
this.setTitle("error");
this.setSize(300, 100);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.setLocationRelativeTo(null);

this.getContentPane().setLayout(new FlowLayout());
this.getContentPane().add(btn);

btn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
ZDialog zd = new ZDialog(null, "reconnection", true);
ZDialogInfo zInfo = zd.showZDialog();
JOptionPane jop = new JOptionPane();
jop.showMessageDialog(null, zInfo.toString(), "Informations personnage", JOptionPane.INFORMATION_MESSAGE);
}

});

this.setVisible(true);

}






/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Fenetre fen = new Fenetre ();
}

}









merci.
A voir également:

1 réponse

Kharec Messages postés 4146 Date d'inscription dimanche 20 avril 2008 Statut Contributeur Dernière intervention 8 mai 2011 509
13 avril 2009 à 11:57
Salut,

Si tu as des erreurs de compil, pourquoi te demande-tu si ton code est bon? :)
0