Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- /**
- *
- * @author hp123
- */
- public class NewJFrame extends javax.swing.JFrame {
- public static String questions[][] = new String[4][5];
- public static int choices[] = new int[4];
- public static Random gerador = new Random();
- public static int numero;
- public static int dinheiros;
- public void initialize_questions(){
- questions[0][0] = "Qual animal que lê linguagens de programação?";
- questions[0][1] = "Leopardo";
- questions[0][2] = "Javali";
- questions[0][3] = "Tigre";
- questions[0][4] = "Gato";
- questions[0][5] = "b";
- questions[1][0] = "1Qual animal que lê linguagens de programação?";
- questions[1][1] = "Leopardo";
- questions[1][2] = "Javali";
- questions[1][3] = "Tigre";
- questions[1][4] = "Gato";
- questions[1][5] = "b";
- questions[2][0] = "2Qual animal que lê linguagens de programação?";
- questions[2][1] = "Leopardo";
- questions[2][2] = "Javali";
- questions[2][3] = "Tigre";
- questions[2][4] = "Gato";
- questions[2][5] = "b";
- questions[3][0] = "3Qual animal que lê linguagens de programação?";
- questions[3][1] = "Leopardo";
- questions[3][2] = "Javali";
- questions[3][3] = "Tigre";
- questions[3][4] = "Gato";
- questions[3][5] = "b";
- questions[4][0] = "4Qual animal que lê linguagens de programação?";
- questions[4][1] = "Leopardo";
- questions[4][2] = "Javali";
- questions[4][3] = "Tigre";
- questions[4][4] = "Gato";
- questions[4][5] = "b";
- for (int n = 0; n < choices.length; n++){
- choices[n] = n;
- }
- }
- public NewJFrame() {
- 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.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jButton1 = new javax.swing.JButton();
- jRadioButton2 = new javax.swing.JRadioButton();
- jRadioButton3 = new javax.swing.JRadioButton();
- jRadioButton4 = new javax.swing.JRadioButton();
- jRadioButton5 = new javax.swing.JRadioButton();
- jLabel1 = new javax.swing.JLabel();
- jButton2 = new javax.swing.JButton();
- jButton3 = new javax.swing.JButton();
- jLabel2 = new javax.swing.JLabel();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- addWindowListener(new java.awt.event.WindowAdapter() {
- public void windowOpened(java.awt.event.WindowEvent evt) {
- formWindowOpened(evt);
- }
- });
- jButton1.setText("Confirmar");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jRadioButton2.setText("Resposta 1");
- jRadioButton2.setName("rdn1"); // NOI18N
- jRadioButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jRadioButton2ActionPerformed(evt);
- }
- });
- jRadioButton3.setText("Resposta 2");
- jRadioButton3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jRadioButton3ActionPerformed(evt);
- }
- });
- jRadioButton4.setText("Resposta 3");
- jRadioButton4.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jRadioButton4ActionPerformed(evt);
- }
- });
- jRadioButton5.setText("Resposta 4");
- jRadioButton5.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jRadioButton5ActionPerformed(evt);
- }
- });
- jLabel1.setText("E a pergunta e :D??");
- jButton2.setText("Iniciar");
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- jButton3.setText("Reiniciar Jogo");
- jButton3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton3ActionPerformed(evt);
- }
- });
- jLabel2.setText("Dinheiros:");
- jLabel2.setToolTipText("");
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(24, 24, 24)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jRadioButton4)
- .addComponent(jLabel1)
- .addComponent(jRadioButton5)
- .addComponent(jRadioButton3)
- .addComponent(jRadioButton2)))
- .addGroup(layout.createSequentialGroup()
- .addGap(155, 155, 155)
- .addComponent(jButton2)))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 40, Short.MAX_VALUE)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(33, 33, 33))
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addComponent(jButton1)
- .addGap(57, 57, 57))
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
- .addComponent(jButton3)
- .addGap(45, 45, 45)))))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGap(32, 32, 32)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jLabel1)
- .addComponent(jButton3))
- .addGap(41, 41, 41)
- .addComponent(jRadioButton2)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jRadioButton3)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jRadioButton4)
- .addComponent(jButton1))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jRadioButton5)
- .addGap(38, 38, 38)
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton2)
- .addComponent(jLabel2))
- .addContainerGap(47, Short.MAX_VALUE))
- );
- jButton1.getAccessibleContext().setAccessibleName("btnConfirmar");
- jRadioButton2.getAccessibleContext().setAccessibleName("rdn1");
- jRadioButton3.getAccessibleContext().setAccessibleName("rdn2");
- jRadioButton4.getAccessibleContext().setAccessibleName("rdn3");
- jRadioButton5.getAccessibleContext().setAccessibleName("rdn4");
- jLabel1.getAccessibleContext().setAccessibleName("lblPergunta");
- pack();
- }// </editor-fold>
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- }
- private void formWindowOpened(java.awt.event.WindowEvent evt) {
- initialize_questions();
- }
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
- for (int n = 0; n < choices.length; n++){
- choices[n] = n;
- }
- start_game();
- }
- private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
- for (int n = 0; n < choices.length; n++){
- choices[n] = n;
- }
- reset_game();
- }
- private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {
- if (!jRadioButton2.isSelected())
- jRadioButton2.setSelected(true);
- jRadioButton3.setSelected(false);
- jRadioButton4.setSelected(false);
- jRadioButton5.setSelected(false);
- }
- private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt) {
- if (!jRadioButton3.isSelected())
- jRadioButton3.setSelected(true);
- jRadioButton2.setSelected(false);
- jRadioButton4.setSelected(false);
- jRadioButton5.setSelected(false);
- }
- private void jRadioButton4ActionPerformed(java.awt.event.ActionEvent evt) {
- if (!jRadioButton4.isSelected())
- jRadioButton4.setSelected(true);
- jRadioButton3.setSelected(false);
- jRadioButton2.setSelected(false);
- jRadioButton5.setSelected(false);
- }
- private void jRadioButton5ActionPerformed(java.awt.event.ActionEvent evt) {
- if (!jRadioButton5.isSelected())
- jRadioButton5.setSelected(true);
- jRadioButton3.setSelected(false);
- jRadioButton4.setSelected(false);
- jRadioButton2.setSelected(false);
- }
- public void reset_game(){
- dinheiros = 0;
- jButton2.setVisible(true);
- jButton3.setVisible(false);
- jButton1.setVisible(false);
- jRadioButton5.setVisible(false);
- jRadioButton2.setVisible(false);
- jRadioButton3.setVisible(false);
- jRadioButton4.setVisible(false);
- }
- public void start_game(){
- choose_answers();
- jButton2.setVisible(false);
- jButton3.setVisible(true);
- jButton1.setVisible(true);
- jRadioButton5.setVisible(true);
- jRadioButton2.setVisible(true);
- jRadioButton3.setVisible(true);
- jRadioButton4.setVisible(true);
- jRadioButton2.setSelected(true);
- }
- public void choose_answers(){
- numero = gerador.nextInt(4);
- while (choices[numero] == -1){
- numero = gerador.nextInt(4);
- }
- choices[numero] = -1;
- System.out.println(questions[1][1]);
- jLabel1.setText(questions[numero][0]);
- jRadioButton2.setText(questions[numero][1]);
- jRadioButton3.setText(questions[numero][2]);
- jRadioButton4.setText(questions[numero][3]);
- jRadioButton5.setText(questions[numero][4]);
- }
- /**
- * @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(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new NewJFrame().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JButton jButton3;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JRadioButton jRadioButton2;
- private javax.swing.JRadioButton jRadioButton3;
- private javax.swing.JRadioButton jRadioButton4;
- private javax.swing.JRadioButton jRadioButton5;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement