Advertisement
Raizen

Untitled

Dec 9th, 2014
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 14.92 KB | None | 0 0
  1. import java.util.Random;
  2. /*
  3.  * To change this license header, choose License Headers in Project Properties.
  4.  * To change this template file, choose Tools | Templates
  5.  * and open the template in the editor.
  6.  */
  7.  
  8. /**
  9.  *
  10.  * @author hp123
  11.  */
  12. public class NewJFrame extends javax.swing.JFrame {
  13.     public static String questions[][] = new String[4][5];
  14.     public static int choices[] = new int[4];
  15.     public static Random gerador = new Random();
  16.     public static int numero;
  17.     public static int dinheiros;
  18.     public void initialize_questions(){
  19.        questions[0][0] = "Qual animal que lê linguagens de programação?";
  20.        questions[0][1] = "Leopardo";
  21.        questions[0][2] = "Javali";
  22.        questions[0][3] = "Tigre";
  23.        questions[0][4] = "Gato";
  24.        questions[0][5] = "b";
  25.        
  26.        questions[1][0] = "1Qual animal que lê linguagens de programação?";
  27.        questions[1][1] = "Leopardo";
  28.        questions[1][2] = "Javali";
  29.        questions[1][3] = "Tigre";
  30.        questions[1][4] = "Gato";
  31.        questions[1][5] = "b";
  32.  
  33.        questions[2][0] = "2Qual animal que lê linguagens de programação?";
  34.        questions[2][1] = "Leopardo";
  35.        questions[2][2] = "Javali";
  36.        questions[2][3] = "Tigre";
  37.        questions[2][4] = "Gato";
  38.        questions[2][5] = "b";
  39.        
  40.        questions[3][0] = "3Qual animal que lê linguagens de programação?";
  41.        questions[3][1] = "Leopardo";
  42.        questions[3][2] = "Javali";
  43.        questions[3][3] = "Tigre";
  44.        questions[3][4] = "Gato";
  45.        questions[3][5] = "b";
  46.        
  47.        questions[4][0] = "4Qual animal que lê linguagens de programação?";
  48.        questions[4][1] = "Leopardo";
  49.        questions[4][2] = "Javali";
  50.        questions[4][3] = "Tigre";
  51.        questions[4][4] = "Gato";
  52.        questions[4][5] = "b";
  53.        
  54.        for (int n = 0; n < choices.length; n++){
  55.            choices[n] = n;
  56.        }
  57.     }  
  58.     public NewJFrame() {
  59.         initComponents();
  60.     }
  61.  
  62.     /**
  63.      * This method is called from within the constructor to initialize the form.
  64.      * WARNING: Do NOT modify this code. The content of this method is always
  65.      * regenerated by the Form Editor.
  66.      */
  67.     @SuppressWarnings("unchecked")
  68.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  69.     private void initComponents() {
  70.  
  71.         jButton1 = new javax.swing.JButton();
  72.         jRadioButton2 = new javax.swing.JRadioButton();
  73.         jRadioButton3 = new javax.swing.JRadioButton();
  74.         jRadioButton4 = new javax.swing.JRadioButton();
  75.         jRadioButton5 = new javax.swing.JRadioButton();
  76.         jLabel1 = new javax.swing.JLabel();
  77.         jButton2 = new javax.swing.JButton();
  78.         jButton3 = new javax.swing.JButton();
  79.         jLabel2 = new javax.swing.JLabel();
  80.  
  81.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  82.         addWindowListener(new java.awt.event.WindowAdapter() {
  83.             public void windowOpened(java.awt.event.WindowEvent evt) {
  84.                 formWindowOpened(evt);
  85.             }
  86.         });
  87.  
  88.         jButton1.setText("Confirmar");
  89.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  90.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  91.                 jButton1ActionPerformed(evt);
  92.             }
  93.         });
  94.  
  95.         jRadioButton2.setText("Resposta 1");
  96.         jRadioButton2.setName("rdn1"); // NOI18N
  97.         jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
  98.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  99.                 jRadioButton2ActionPerformed(evt);
  100.             }
  101.         });
  102.  
  103.         jRadioButton3.setText("Resposta 2");
  104.         jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
  105.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  106.                 jRadioButton3ActionPerformed(evt);
  107.             }
  108.         });
  109.  
  110.         jRadioButton4.setText("Resposta 3");
  111.         jRadioButton4.addActionListener(new java.awt.event.ActionListener() {
  112.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  113.                 jRadioButton4ActionPerformed(evt);
  114.             }
  115.         });
  116.  
  117.         jRadioButton5.setText("Resposta 4");
  118.         jRadioButton5.addActionListener(new java.awt.event.ActionListener() {
  119.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  120.                 jRadioButton5ActionPerformed(evt);
  121.             }
  122.         });
  123.  
  124.         jLabel1.setText("E a pergunta e :D??");
  125.  
  126.         jButton2.setText("Iniciar");
  127.         jButton2.addActionListener(new java.awt.event.ActionListener() {
  128.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  129.                 jButton2ActionPerformed(evt);
  130.             }
  131.         });
  132.  
  133.         jButton3.setText("Reiniciar Jogo");
  134.         jButton3.addActionListener(new java.awt.event.ActionListener() {
  135.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  136.                 jButton3ActionPerformed(evt);
  137.             }
  138.         });
  139.  
  140.         jLabel2.setText("Dinheiros:");
  141.         jLabel2.setToolTipText("");
  142.  
  143.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  144.         getContentPane().setLayout(layout);
  145.         layout.setHorizontalGroup(
  146.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  147.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  148.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  149.                     .addGroup(layout.createSequentialGroup()
  150.                         .addGap(24, 24, 24)
  151.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  152.                             .addComponent(jRadioButton4)
  153.                             .addComponent(jLabel1)
  154.                             .addComponent(jRadioButton5)
  155.                             .addComponent(jRadioButton3)
  156.                             .addComponent(jRadioButton2)))
  157.                     .addGroup(layout.createSequentialGroup()
  158.                         .addGap(155, 155, 155)
  159.                         .addComponent(jButton2)))
  160.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40, Short.MAX_VALUE)
  161.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  162.                     .addGroup(layout.createSequentialGroup()
  163.                         .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
  164.                         .addGap(33, 33, 33))
  165.                     .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  166.                         .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  167.                             .addComponent(jButton1)
  168.                             .addGap(57, 57, 57))
  169.                         .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  170.                             .addComponent(jButton3)
  171.                             .addGap(45, 45, 45)))))
  172.         );
  173.         layout.setVerticalGroup(
  174.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  175.             .addGroup(layout.createSequentialGroup()
  176.                 .addGap(32, 32, 32)
  177.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  178.                     .addComponent(jLabel1)
  179.                     .addComponent(jButton3))
  180.                 .addGap(41, 41, 41)
  181.                 .addComponent(jRadioButton2)
  182.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  183.                 .addComponent(jRadioButton3)
  184.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  185.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  186.                     .addComponent(jRadioButton4)
  187.                     .addComponent(jButton1))
  188.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  189.                 .addComponent(jRadioButton5)
  190.                 .addGap(38, 38, 38)
  191.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  192.                     .addComponent(jButton2)
  193.                     .addComponent(jLabel2))
  194.                 .addContainerGap(47, Short.MAX_VALUE))
  195.         );
  196.  
  197.         jButton1.getAccessibleContext().setAccessibleName("btnConfirmar");
  198.         jRadioButton2.getAccessibleContext().setAccessibleName("rdn1");
  199.         jRadioButton3.getAccessibleContext().setAccessibleName("rdn2");
  200.         jRadioButton4.getAccessibleContext().setAccessibleName("rdn3");
  201.         jRadioButton5.getAccessibleContext().setAccessibleName("rdn4");
  202.         jLabel1.getAccessibleContext().setAccessibleName("lblPergunta");
  203.  
  204.         pack();
  205.     }// </editor-fold>                        
  206.  
  207.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  208.  
  209.        
  210.     }                                        
  211.  
  212.     private void formWindowOpened(java.awt.event.WindowEvent evt) {                                  
  213.         initialize_questions();
  214.     }                                
  215.  
  216.     private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  217.        for (int n = 0; n < choices.length; n++){
  218.            choices[n] = n;
  219.        }
  220.         start_game();
  221.     }                                        
  222.  
  223.     private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  224.         for (int n = 0; n < choices.length; n++){
  225.            choices[n] = n;
  226.        }
  227.         reset_game();
  228.     }                                        
  229.  
  230.     private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                              
  231.         if (!jRadioButton2.isSelected())
  232.                 jRadioButton2.setSelected(true);
  233.         jRadioButton3.setSelected(false);
  234.         jRadioButton4.setSelected(false);
  235.         jRadioButton5.setSelected(false);
  236.     }                                            
  237.  
  238.     private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                              
  239.         if (!jRadioButton3.isSelected())
  240.                 jRadioButton3.setSelected(true);
  241.         jRadioButton2.setSelected(false);
  242.         jRadioButton4.setSelected(false);
  243.         jRadioButton5.setSelected(false);
  244.     }                                            
  245.  
  246.     private void jRadioButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                              
  247.         if (!jRadioButton4.isSelected())
  248.                 jRadioButton4.setSelected(true);
  249.         jRadioButton3.setSelected(false);
  250.         jRadioButton2.setSelected(false);
  251.         jRadioButton5.setSelected(false);
  252.     }                                            
  253.  
  254.     private void jRadioButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                              
  255.         if (!jRadioButton5.isSelected())
  256.                 jRadioButton5.setSelected(true);
  257.         jRadioButton3.setSelected(false);
  258.         jRadioButton4.setSelected(false);
  259.         jRadioButton2.setSelected(false);
  260.     }                                            
  261.        
  262.     public void reset_game(){
  263.         dinheiros = 0;
  264.         jButton2.setVisible(true);
  265.         jButton3.setVisible(false);
  266.         jButton1.setVisible(false);
  267.         jRadioButton5.setVisible(false);
  268.         jRadioButton2.setVisible(false);
  269.         jRadioButton3.setVisible(false);
  270.         jRadioButton4.setVisible(false);
  271.     }
  272.     public void start_game(){
  273.         choose_answers();
  274.         jButton2.setVisible(false);
  275.         jButton3.setVisible(true);
  276.         jButton1.setVisible(true);
  277.         jRadioButton5.setVisible(true);
  278.         jRadioButton2.setVisible(true);
  279.         jRadioButton3.setVisible(true);
  280.         jRadioButton4.setVisible(true);
  281.         jRadioButton2.setSelected(true);
  282.     }
  283.    
  284.     public void choose_answers(){
  285.         numero = gerador.nextInt(4);
  286.         while (choices[numero] == -1){
  287.             numero = gerador.nextInt(4);
  288.         }
  289.         choices[numero] = -1;
  290.         System.out.println(questions[1][1]);
  291.         jLabel1.setText(questions[numero][0]);
  292.         jRadioButton2.setText(questions[numero][1]);
  293.         jRadioButton3.setText(questions[numero][2]);
  294.         jRadioButton4.setText(questions[numero][3]);
  295.         jRadioButton5.setText(questions[numero][4]);
  296.     }
  297.     /**
  298.      * @param args the command line arguments
  299.      */
  300.     public static void main(String args[]) {
  301.         /* Set the Nimbus look and feel */
  302.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  303.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  304.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  305.          */
  306.         try {
  307.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  308.                 if ("Nimbus".equals(info.getName())) {
  309.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  310.                     break;
  311.                 }
  312.             }
  313.         } catch (ClassNotFoundException ex) {
  314.             java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  315.         } catch (InstantiationException ex) {
  316.             java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  317.         } catch (IllegalAccessException ex) {
  318.             java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  319.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  320.             java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  321.         }
  322.         //</editor-fold>
  323.  
  324.         /* Create and display the form */
  325.         java.awt.EventQueue.invokeLater(new Runnable() {
  326.             public void run() {
  327.                 new NewJFrame().setVisible(true);
  328.             }
  329.         });
  330.     }
  331.  
  332.     // Variables declaration - do not modify                    
  333.     private javax.swing.JButton jButton1;
  334.     private javax.swing.JButton jButton2;
  335.     private javax.swing.JButton jButton3;
  336.     private javax.swing.JLabel jLabel1;
  337.     private javax.swing.JLabel jLabel2;
  338.     private javax.swing.JRadioButton jRadioButton2;
  339.     private javax.swing.JRadioButton jRadioButton3;
  340.     private javax.swing.JRadioButton jRadioButton4;
  341.     private javax.swing.JRadioButton jRadioButton5;
  342.     // End of variables declaration                  
  343. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement