Chi vuol essere informatico - Myframe.java
Cerca
 











Myframe.java

Caricato da: Bonny
Scarica il programma completo

  1. package quizzone;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6. import javax.swing.*;
  7.  
  8. public class Myframe extends JFrame {
  9.  
  10.     private JLabel txt = new JLabel();
  11.     private JPanel p = new JPanel();
  12.     private JRadioButton[] risp = new JRadioButton[4];
  13.     private ButtonGroup bg = new ButtonGroup();
  14.     private JButton conferma = new JButton("Conferma");
  15.     private Jdb db;
  16.     private static int indx = 1, numrispesatte = 0;
  17.     private static String rispesatta = "",n="";
  18.  
  19.     public Myframe(String nome) {
  20.  
  21.  
  22.         super("Il Quizzone");
  23.         n = nome;
  24.         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  25.  
  26.         db = new Jdb();
  27.  
  28.         conferma.addActionListener(
  29.                 new ActionListener() {
  30.  
  31.                     public void actionPerformed(ActionEvent event) {
  32.  
  33.                         if (indx == 10) {
  34.                             if (numrispesatte < 6) {
  35.                                 JOptionPane.showMessageDialog(null, numrispesatte + "/10 risposte giuste,devi studiare! ", "msg", JOptionPane.INFORMATION_MESSAGE);
  36.                             } else if (numrispesatte > 5 && numrispesatte < 9) {
  37.                                 JOptionPane.showMessageDialog(null, numrispesatte + "/10 risposte giuste, punteggio buono! ", "msg", JOptionPane.INFORMATION_MESSAGE);
  38.                             } else if (numrispesatte > 8) {
  39.                                 JOptionPane.showMessageDialog(null, numrispesatte + "/10 risposte giuste, bravo ottimo punteggio ", "msg", JOptionPane.INFORMATION_MESSAGE);
  40.                             }
  41.                             db.insert(n, numrispesatte);
  42.                             new Record();
  43.                             setVisible(false);
  44.                         } else {
  45.  
  46.                             ButtonModel f = bg.getSelection();
  47.  
  48.                             if (f != null) {
  49.                                 if (rispesatta.equals(f.getActionCommand())) {
  50.                                     numrispesatte++;
  51.                                 }
  52.                                 indx++;
  53.                                 initx();
  54.  
  55.                             } else {
  56.                                 JOptionPane.showMessageDialog(null,"Devi selezionare una risposta.", "msg", JOptionPane.INFORMATION_MESSAGE);
  57.                             }
  58.                         }
  59.                     }
  60.                 });
  61.  
  62.  
  63.         p.setBackground(Color.blue);
  64.         p.setLayout(new GridLayout(2, 2, 5, 5));
  65.         for (int i = 0; i < 4; i++) {
  66.             risp[i] = new JRadioButton();
  67.             bg.add(risp[i]);
  68.             risp[i].setBackground(new Color(0,64,128));
  69.             risp[i].setForeground(Color.ORANGE);
  70.             risp[i].setFont(new Font("Arial", Font.BOLD, 16));
  71.             p.add(risp[i]);
  72.         }
  73.    
  74.         JPanel pc = new JPanel();
  75.         pc.setBackground(Color.blue);
  76.         pc.add(conferma);
  77.         JPanel pt = new JPanel();
  78.         pt.setBackground(Color.blue);
  79.         txt.setForeground(Color.red);
  80.         txt.setFont(new Font("Arial", Font.BOLD, 20));
  81.         pt.add(txt);
  82.         this.getContentPane().add(pt, "North");
  83.         this.getContentPane().add(p, "Center");
  84.         this.getContentPane().add(pc, "South");
  85.  
  86.         setResizable(false);
  87.         setVisible(true);
  88.         setBounds(200, 200,770,250);
  89.         initx();
  90.     }
  91.  
  92.     public void initx() {
  93.  
  94.         String[] opt = db.estrai(indx);
  95.  
  96.         txt.setText(" " + opt[0]);
  97.  
  98.         for (int i = 0; i < 4; i++) {
  99.  
  100.             risp[i].setText(opt[i + 1]);
  101.             risp[i].setActionCommand(opt[i + 1]);
  102.  
  103.         }
  104.         rispesatta = opt[5];
  105.  
  106.     }
  107. }//fine class
 

Creative Commons License
Il layout di questo sito è concesso sotto licenza Creative Commons.
Per maggiori informazioni sulle licenze dei contenuti del sito, clicca.