/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package feuille.scripting;
/**
*
* @author The Wingate 2940
*/
public class MCQDialog extends javax.swing.JDialog {
private ButtonPressed bp = ButtonPressed.NONE;
/**
* Creates new form MCQDialog
*/
public MCQDialog(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
jRadioButton1.setVisible(false);
jRadioButton2.setVisible(false);
jRadioButton3.setVisible(false);
jRadioButton4.setVisible(false);
jRadioButton5.setVisible(false);
jRadioButton6.setVisible(false);
}
public enum ButtonPressed{
NONE, OK_BUTTON, CANCEL_BUTTON;
}
/**
* 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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
buttonGroup1 = new javax.swing.ButtonGroup();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
jRadioButton1 = new javax.swing.JRadioButton();
jRadioButton2 = new javax.swing.JRadioButton();
jRadioButton3 = new javax.swing.JRadioButton();
jRadioButton4 = new javax.swing.JRadioButton();
jRadioButton5 = new javax.swing.JRadioButton();
jRadioButton6 = new javax.swing.JRadioButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
jButton1.setText("OK");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("Annuler");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jLabel1.setText("Sujet du questionnaire :");
jPanel1.setBackground(new java.awt.Color(255, 255, 255));
jPanel1.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(51, 0, 204), 1, true));
jRadioButton1.setBackground(new java.awt.Color(255, 255, 255));
buttonGroup1.add(jRadioButton1);
jRadioButton1.setSelected(true);
jRadioButton1.setText("Une réponse qui n'est pas forcémment courte !");
jRadioButton2.setBackground(new java.awt.Color(255, 255, 255));
buttonGroup1.add(jRadioButton2);
jRadioButton2.setText("Une réponse qui n'est pas forcémment courte !");
jRadioButton3.setBackground(new java.awt.Color(255, 255, 255));
buttonGroup1.add(jRadioButton3);
jRadioButton3.setText("Une réponse qui n'est pas forcémment courte !");
jRadioButton4.setBackground(new java.awt.Color(255, 255, 255));
buttonGroup1.add(jRadioButton4);
jRadioButton4.setText("Une réponse qui n'est pas forcémment courte !");
jRadioButton5.setBackground(new java.awt.Color(255, 255, 255));
buttonGroup1.add(jRadioButton5);
jRadioButton5.setText("Une réponse qui n'est pas forcémment courte !");
jRadioButton6.setBackground(new java.awt.Color(255, 255, 255));
buttonGroup1.add(jRadioButton6);
jRadioButton6.setText("Une réponse qui n'est pas forcémment courte !");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jRadioButton1)
.addComponent(jRadioButton2)
.addComponent(jRadioButton3)
.addComponent(jRadioButton4)
.addComponent(jRadioButton5)
.addComponent(jRadioButton6))
.addContainerGap(170, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jRadioButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jRadioButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jRadioButton3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jRadioButton4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jRadioButton5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jRadioButton6)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(0, 0, Short.MAX_VALUE))
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
bp = ButtonPressed.OK_BUTTON;
dispose();
}//GEN-LAST:event_jButton1ActionPerformed
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
bp = ButtonPressed.CANCEL_BUTTON;
dispose();
}//GEN-LAST:event_jButton2ActionPerformed
public int showDialog(){
pack();
setLocationRelativeTo(null);
setVisible(true);
if(bp.equals(ButtonPressed.OK_BUTTON)){
//Si on a appuyé sur OK alors on renvoie le nombre du choix
if(jRadioButton1.isSelected()){
return 1;
}else if(jRadioButton2.isSelected()){
return 2;
}else if(jRadioButton3.isSelected()){
return 3;
}else if(jRadioButton4.isSelected()){
return 4;
}else if(jRadioButton5.isSelected()){
return 5;
}else if(jRadioButton6.isSelected()){
return 6;
}
return -1; //Si on arrive là, il y a une erreur
}else{
return -1; //On a appuyé sur Annuler
}
}
public void setQuestion(String question){
jLabel1.setText(question);
}
public void setAnswer1(String answer){
jRadioButton1.setText(answer);
jRadioButton1.setVisible(true);
}
public void setAnswer2(String answer){
jRadioButton2.setText(answer);
jRadioButton2.setVisible(true);
}
public void setAnswer3(String answer){
jRadioButton3.setText(answer);
jRadioButton3.setVisible(true);
}
public void setAnswer4(String answer){
jRadioButton4.setText(answer);
jRadioButton4.setVisible(true);
}
public void setAnswer5(String answer){
jRadioButton5.setText(answer);
jRadioButton5.setVisible(true);
}
public void setAnswer6(String answer){
jRadioButton6.setText(answer);
jRadioButton6.setVisible(true);
}
public void setOKText(String text){
jButton1.setText(text);
}
public void setCancelText(String text){
jButton2.setText(text);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(MCQDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MCQDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MCQDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MCQDialog.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the dialog */
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
MCQDialog dialog = new MCQDialog(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JRadioButton jRadioButton1;
private javax.swing.JRadioButton jRadioButton2;
private javax.swing.JRadioButton jRadioButton3;
private javax.swing.JRadioButton jRadioButton4;
private javax.swing.JRadioButton jRadioButton5;
private javax.swing.JRadioButton jRadioButton6;
// End of variables declaration//GEN-END:variables
}