Créé dans le cadre du projet de fin d'année de la promo 2018 de CIR2 de l'ISEN Brest/Rennes, le Burger Quizz est une adaptation numérique du jeu télévisé éponyme, plus précisément d'une épreuve spécifique de ce jeu : le "Sel ou Poivre".

NouvelleReponseDialog.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. package InterfaceGraphique.DialogBoxes;
  2. import javax.swing.*;
  3. import java.awt.*;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. public class NouvelleReponseDialog extends JDialog implements ActionListener
  7. {
  8. private JTextField rep1;
  9. private JTextField rep2;
  10. private JButton ok;
  11. private JButton annuler;
  12. private boolean mofidEffectues;
  13. private JComboBox comboCat;
  14. public NouvelleReponseDialog(String title, String defRep1, String defRep2, String defCategorie, String[] tabCategorie,JFrame parent)
  15. {
  16. super(parent, title, true);
  17. mofidEffectues = false;
  18. createInterface(defRep1, defRep2, defCategorie, tabCategorie);
  19. pack();
  20. setLocationRelativeTo(null);
  21. setResizable(false);
  22. }
  23. private void createInterface(String defRep1, String defRep2, String defCategorie, String[] tabCategorie)
  24. {
  25. JPanel champs = new JPanel();
  26. JPanel boutons = new JPanel();
  27. rep1 = new JTextField(defRep1,15);
  28. rep2 = new JTextField(defRep2,15);
  29. rep1.setBackground(Color.WHITE);
  30. rep2.setBackground(Color.WHITE);
  31. ok = new JButton("OK");
  32. annuler = new JButton("Annuler");
  33. ok.addActionListener(this);
  34. annuler.addActionListener(this);
  35. GridLayout gridLayout = new GridLayout(2, 2);
  36. champs.setLayout(gridLayout);
  37. champs.add(new JLabel("Réponse 1:"));
  38. champs.add(rep1);
  39. champs.add(new JLabel("Réponse 2:"));
  40. champs.add(rep2);
  41. if(defCategorie != null)
  42. {
  43. comboCat = new JComboBox();
  44. comboCat.setOpaque(true);
  45. for(int i=0; i< tabCategorie.length; i++)
  46. {
  47. comboCat.addItem(tabCategorie[i]);
  48. if(tabCategorie[i].equals(defCategorie))
  49. {
  50. comboCat.setSelectedIndex(i);
  51. }
  52. }
  53. gridLayout.setRows(3);
  54. champs.add(new JLabel("Catégorie:"));
  55. champs.add(comboCat);
  56. }
  57. boutons.add(annuler);
  58. boutons.add(ok);
  59. getContentPane().setLayout(new BorderLayout());
  60. getContentPane().add(champs, BorderLayout.CENTER);
  61. getContentPane().add(boutons, BorderLayout.SOUTH);
  62. }
  63. public boolean afficher()
  64. {
  65. setVisible(true);
  66. return mofidEffectues;
  67. }
  68. public void actionPerformed(ActionEvent e)
  69. {
  70. if(e.getSource() == annuler)
  71. {
  72. mofidEffectues = false;
  73. setVisible(false);
  74. }
  75. else if(e.getSource() == ok) {
  76. if(rep1.getText().isEmpty() || rep2.getText().isEmpty())
  77. {
  78. JOptionPane.showMessageDialog(this, "Les champs ne doivent pas être vide.", "Champs non remplis", JOptionPane.WARNING_MESSAGE);
  79. return;
  80. }
  81. mofidEffectues = true;
  82. setVisible(false);
  83. }
  84. }
  85. public String getRep2() {
  86. return rep2.getText();
  87. }
  88. public String getRep1() {
  89. return rep1.getText();
  90. }
  91. public String getCat() {
  92. return comboCat.getSelectedItem().toString();
  93. }
  94. }