JDialog qui ouvre une JDialog
Bonjour,
en faite, j'aimerais avoir une JDialog qui ouvre une JDialog et qui reviens sur la JFrame.
Code:
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
| public class Intro extends javax.swing.JDialog/*MonComponent1*/{protected boolean fermeture=false;Choix jd;
public Intro(java.awt.Frame parent, boolean modal) {
super(parent, modal);
/* this.setImage();
this.repaint();*/
initComponents();
}
public Intro(java.awt.Dialog Parent,boolean modal) {
super(Parent);
setModal(modal);
initComponents();
}
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jToggleButton1 = new javax.swing.JToggleButton();
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
closeDialog(evt);
}
});
getContentPane().setLayout(new java.awt.GridLayout());
jToggleButton1.setText("Nouveau Jeu");
jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jToggleButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 416, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(104, 104, 104)
.addComponent(jToggleButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 208, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(104, Short.MAX_VALUE)))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 311, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(239, Short.MAX_VALUE)
.addComponent(jToggleButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(39, 39, 39)))
);
getContentPane().add(jPanel1);
pack();
}// </editor-fold>
/** Closes the dialog */
private void closeDialog(java.awt.event.WindowEvent evt) {
setVisible(false);
dispose();
}
private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {
fermeture=true;
jd=new Choix(this,true);
jd.setVisible(true);
setVisible(false);
dispose();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
Intro dialog = new Intro(new java.awt.Frame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JPanel jPanel1;
private javax.swing.JToggleButton jToggleButton1;
// End of variables declaration
} |
1ere JDialog
Code:
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 178
| public class Choix extends java.awt.Dialog {
int longueurgrille,largueurgrille,division,nbjeux,nbtour;
public Choix(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
}
public Choix(java.awt.Dialog Parent,boolean modal) {
super(Parent);
setModal(modal);
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
jPanel3 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
Long = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
Larg = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
Div = new javax.swing.JTextField();
jPanel4 = new javax.swing.JPanel();
jLabel4 = new javax.swing.JLabel();
nbTour = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
nbJeux = new javax.swing.JTextField();
jPanel5 = new javax.swing.JPanel();
Valider = new javax.swing.JButton();
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
closeDialog(evt);
}
});
setLayout(new java.awt.GridLayout(2, 2));
add(jPanel1);
add(jPanel2);
jPanel3.setLayout(new java.awt.GridLayout(6, 2));
jLabel1.setText("Longueur de la Grille");
jPanel3.add(jLabel1);
Long.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
LongActionPerformed(evt);
}
});
jPanel3.add(Long);
jLabel2.setText("Largeur de la Grille");
jPanel3.add(jLabel2);
jPanel3.add(Larg);
jLabel3.setText("Nombres de divisions");
jPanel3.add(jLabel3);
jPanel3.add(Div);
add(jPanel3);
jPanel4.setLayout(new java.awt.GridLayout(3, 2));
jLabel4.setText("Nombre de Tour");
jPanel4.add(jLabel4);
jPanel4.add(nbTour);
jLabel5.setText("Nombre de Jeux");
jPanel4.add(jLabel5);
jPanel4.add(nbJeux);
jPanel4.add(jPanel5);
Valider.setText("VALIDER");
Valider.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ValiderActionPerformed(evt);
}
});
jPanel4.add(Valider);
add(jPanel4);
pack();
}// </editor-fold>
/** Closes the dialog */
private void closeDialog(java.awt.event.WindowEvent evt) {
setVisible(false);
dispose();
}
private void LongActionPerformed(java.awt.event.ActionEvent evt) {
}
private void ValiderActionPerformed(java.awt.event.ActionEvent evt) {
int i=Integer.parseInt(Long.getText());
if(i<0)
System.out.println("erreur de la longueur");
else
longueurgrille=i;
int j=Integer.parseInt(Larg.getText());
if(j<0)
System.out.println("erreur de la largueur");
else
largueurgrille=j;
int k=Integer.parseInt(Div.getText());
if(k<0)
System.out.println("erreur de la division");
else
division=k;
int l=Integer.parseInt(nbTour.getText());
if(l<0)
System.out.println("erreur du nombre de tours");
else
nbtour=l;
int m=Integer.parseInt(nbJeux.getText());
if(m<0)
System.out.println("erreur du nombre de jeux");
else
nbjeux=m;
System.out.println(m);
setVisible(false);
dispose();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
Choix dialog = new Choix(new java.awt.Frame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextField Div;
private javax.swing.JTextField Larg;
private javax.swing.JTextField Long;
private javax.swing.JButton Valider;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JPanel jPanel5;
private javax.swing.JTextField nbJeux;
private javax.swing.JTextField nbTour;
// End of variables declaration
} |
2éme JDialog
Code:
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
| public PlateauJeu(){
initComponents();
Intro i=new Intro(this,true); i.setVisible(true);
Choix jd=i.jd;
larg=jd.largueurgrille;
longu=jd.longueurgrille;
System.out.println(larg);System.out.println(longu);
nbto=jd.nbtour;
nbdiv=jd.division;
nbje=jd.nbjeux;
lejeu=new Jeu(longu,larg,nbto,nbdiv,nbje);
restest.setVisible(false);
pp.setVisible(false);
pg.setVisible(false);
pdr.setVisible(false);
ResultatPourc.setVisible(false);
PPerdu.setVisible(false);
PGagne.setVisible(false);
creationJeu();
afficheJeu();
} |
JFrame
En faite la construction des JDialog sa marche le problème c'est que quand tout ferme sa renvoie pas à la JFrame
ou est mon erreur???