Advertisement
Guest User

milliomos

a guest
Nov 9th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 11.84 KB | None | 0 0
  1. package legyenonismilliomos;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.DriverManager;
  5. import java.sql.SQLException;
  6. import java.util.List;
  7. import java.util.logging.Level;
  8. import java.util.logging.Logger;
  9. import javax.swing.JOptionPane;
  10. import modell.DbModell;
  11. import modell.Imodel;
  12. import modell.Kerdes;
  13.  
  14.  
  15.  
  16.  
  17. public class KezdoAblak extends javax.swing.JFrame {
  18.     private Imodel model;
  19.     private Kerdes kerdesek;
  20.     Kerdes kerdes;
  21.     int i=1;
  22.     String helyesvalasz="";
  23.    
  24.    
  25.    
  26.     public KezdoAblak() {
  27.         initComponents();
  28.        
  29.    
  30.         setLocationRelativeTo(null);
  31.         setTitle("Legyen ön is milliomos 2016");
  32.        
  33.         String connURL="jdbc:mysql://localhost:3306/java_vizsga";
  34.         String user ="root";
  35.         String pass="1234";
  36.        
  37.        
  38.         try {
  39.             Connection conn= DriverManager.getConnection(connURL, user, pass);
  40.             model=new DbModell(conn);
  41.     }catch(SQLException ex) {
  42.             JOptionPane.showMessageDialog(rootPane, ex.getMessage(), "Adatbázis hiba", JOptionPane.ERROR_MESSAGE);
  43.     }
  44.          
  45.    
  46.        try {
  47.             kerdesek =model.getKerdes(i);
  48.         } catch (SQLException ex) {
  49.             JOptionPane.showMessageDialog(rootPane, ex.getMessage(), "Adatbázis hiba", JOptionPane.ERROR_MESSAGE);
  50.         }
  51.        
  52.            
  53.           jlbKerdesek.setText(kerdesek.getKerdes());
  54.           jButton1.setText(kerdesek.getValasz0());
  55.           jButton2.setText(kerdesek.getValasz1());
  56.           jButton3.setText(kerdesek.getValasz2());
  57.           jButton4.setText(kerdesek.getValasz3());
  58.           helyesvalasz=kerdesek.getValasz3();
  59.            
  60.    
  61.        
  62.        
  63.    
  64.      
  65.        
  66.          
  67.        
  68.     }
  69.  
  70.     /**
  71.      * This method is called from within the constructor to initialize the form.
  72.      * WARNING: Do NOT modify this code. The content of this method is always
  73.      * regenerated by the Form Editor.
  74.      */
  75.     @SuppressWarnings("unchecked")
  76.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  77.     private void initComponents() {
  78.  
  79.         jScrollPane1 = new javax.swing.JScrollPane();
  80.         jlsOsszeg = new javax.swing.JList<>();
  81.         jLabel1 = new javax.swing.JLabel();
  82.         jButton1 = new javax.swing.JButton();
  83.         jButton2 = new javax.swing.JButton();
  84.         jButton3 = new javax.swing.JButton();
  85.         jButton4 = new javax.swing.JButton();
  86.         jlbKerdesek = new javax.swing.JLabel();
  87.         jMenuBar1 = new javax.swing.JMenuBar();
  88.         jMenu1 = new javax.swing.JMenu();
  89.         jMenuItem1 = new javax.swing.JMenuItem();
  90.         jMenu2 = new javax.swing.JMenu();
  91.         jMenuItem2 = new javax.swing.JMenuItem();
  92.         jMenuItem3 = new javax.swing.JMenuItem();
  93.         jMenu3 = new javax.swing.JMenu();
  94.         jMenuItem4 = new javax.swing.JMenuItem();
  95.  
  96.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  97.  
  98.         jlsOsszeg.setModel(new javax.swing.AbstractListModel<String>() {
  99.             String[] strings = { "40000000", "20000000", "10000000", "5000000", "2000000", "1000000", "800000", "500000", "300000", "200000", "100000", "50000", "20000", "10000", "5000", " ", " ", " ", " ", " " };
  100.             public int getSize() { return strings.length; }
  101.             public String getElementAt(int i) { return strings[i]; }
  102.         });
  103.         jScrollPane1.setViewportView(jlsOsszeg);
  104.  
  105.         jButton1.setText("jButton1");
  106.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  107.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  108.                 jButton1ActionPerformed(evt);
  109.             }
  110.         });
  111.  
  112.         jButton2.setText("jButton2");
  113.         jButton2.addActionListener(new java.awt.event.ActionListener() {
  114.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  115.                 jButton2ActionPerformed(evt);
  116.             }
  117.         });
  118.  
  119.         jButton3.setText("jButton3");
  120.  
  121.         jButton4.setText("jButton4");
  122.  
  123.         jMenu1.setText("Fájl");
  124.  
  125.         jMenuItem1.setText("Kilépés");
  126.         jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
  127.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  128.                 jMenuItem1ActionPerformed(evt);
  129.             }
  130.         });
  131.         jMenu1.add(jMenuItem1);
  132.  
  133.         jMenuBar1.add(jMenu1);
  134.  
  135.         jMenu2.setText("Jaték");
  136.  
  137.         jMenuItem2.setText("Új játék");
  138.         jMenu2.add(jMenuItem2);
  139.  
  140.         jMenuItem3.setText("Kilépés");
  141.         jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
  142.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  143.                 jMenuItem3ActionPerformed(evt);
  144.             }
  145.         });
  146.         jMenu2.add(jMenuItem3);
  147.  
  148.         jMenuBar1.add(jMenu2);
  149.  
  150.         jMenu3.setText("Kérdések kezelése");
  151.  
  152.         jMenuItem4.setText("Kérdés szerkesztés");
  153.         jMenu3.add(jMenuItem4);
  154.  
  155.         jMenuBar1.add(jMenu3);
  156.  
  157.         setJMenuBar(jMenuBar1);
  158.  
  159.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  160.         getContentPane().setLayout(layout);
  161.         layout.setHorizontalGroup(
  162.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  163.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  164.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  165.                     .addGroup(layout.createSequentialGroup()
  166.                         .addGap(28, 28, 28)
  167.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  168.                             .addComponent(jButton1)
  169.                             .addComponent(jButton3))
  170.                         .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  171.                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  172.                             .addComponent(jButton2)
  173.                             .addComponent(jButton4))
  174.                         .addGap(16, 16, 16))
  175.                     .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  176.                         .addContainerGap(53, Short.MAX_VALUE)
  177.                         .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 251, javax.swing.GroupLayout.PREFERRED_SIZE))
  178.                     .addGroup(layout.createSequentialGroup()
  179.                         .addContainerGap()
  180.                         .addComponent(jlbKerdesek, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
  181.                 .addGap(18, 18, 18)
  182.                 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  183.                 .addGap(27, 27, 27))
  184.         );
  185.         layout.setVerticalGroup(
  186.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  187.             .addGroup(layout.createSequentialGroup()
  188.                 .addContainerGap()
  189.                 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 288, javax.swing.GroupLayout.PREFERRED_SIZE)
  190.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  191.             .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
  192.                 .addContainerGap(200, Short.MAX_VALUE)
  193.                 .addComponent(jlbKerdesek, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
  194.                 .addGap(18, 18, 18)
  195.                 .addComponent(jLabel1)
  196.                 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  197.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  198.                     .addComponent(jButton1)
  199.                     .addComponent(jButton2))
  200.                 .addGap(18, 18, 18)
  201.                 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  202.                     .addComponent(jButton3)
  203.                     .addComponent(jButton4))
  204.                 .addGap(23, 23, 23))
  205.         );
  206.  
  207.         pack();
  208.     }// </editor-fold>                        
  209.  
  210.     private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  211.         if(model!=null){
  212.             try {
  213.                 model.close();
  214.             } catch (SQLException ex) {
  215.                  JOptionPane.showMessageDialog(rootPane, ex.getMessage(), "Adatbázis hiba", JOptionPane.ERROR_MESSAGE);
  216.             }
  217.         }
  218.        System.exit(0);
  219.     }                                          
  220.  
  221.     private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {                                          
  222.        System.exit(0);
  223.     }                                          
  224.  
  225.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  226.        
  227.        
  228.     }                                        
  229.  
  230.     private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  231.      
  232.        
  233.        
  234.     }                                        
  235.  
  236.    
  237.    
  238.     public static void main(String args[]) {
  239.         /* Set the Nimbus look and feel */
  240.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  241.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  242.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  243.          */
  244.         try {
  245.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  246.                 if ("Nimbus".equals(info.getName())) {
  247.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  248.                     break;
  249.                 }
  250.             }
  251.         } catch (ClassNotFoundException ex) {
  252.             java.util.logging.Logger.getLogger(KezdoAblak.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  253.         } catch (InstantiationException ex) {
  254.             java.util.logging.Logger.getLogger(KezdoAblak.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  255.         } catch (IllegalAccessException ex) {
  256.             java.util.logging.Logger.getLogger(KezdoAblak.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  257.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  258.             java.util.logging.Logger.getLogger(KezdoAblak.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  259.         }
  260.         //</editor-fold>
  261.  
  262.         /* Create and display the form */
  263.         java.awt.EventQueue.invokeLater(new Runnable() {
  264.             public void run() {
  265.                 new KezdoAblak().setVisible(true);
  266.             }
  267.         });
  268.     }
  269.  
  270.     // Variables declaration - do not modify                    
  271.     private javax.swing.JButton jButton1;
  272.     private javax.swing.JButton jButton2;
  273.     private javax.swing.JButton jButton3;
  274.     private javax.swing.JButton jButton4;
  275.     private javax.swing.JLabel jLabel1;
  276.     private javax.swing.JMenu jMenu1;
  277.     private javax.swing.JMenu jMenu2;
  278.     private javax.swing.JMenu jMenu3;
  279.     private javax.swing.JMenuBar jMenuBar1;
  280.     private javax.swing.JMenuItem jMenuItem1;
  281.     private javax.swing.JMenuItem jMenuItem2;
  282.     private javax.swing.JMenuItem jMenuItem3;
  283.     private javax.swing.JMenuItem jMenuItem4;
  284.     private javax.swing.JScrollPane jScrollPane1;
  285.     private javax.swing.JLabel jlbKerdesek;
  286.     private javax.swing.JList<String> jlsOsszeg;
  287.     // End of variables declaration
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement