Advertisement
Guest User

KitchenGUI

a guest
Apr 15th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.64 KB | None | 0 0
  1. package test;
  2.  
  3.  
  4. import javax.swing.*;
  5. import java.awt.*;
  6. import java.beans.Statement;
  7. import java.sql.Connection;
  8. import java.sql.DriverManager;
  9. import java.sql.PreparedStatement;
  10. import java.sql.ResultSet;
  11. import java.sql.SQLException;
  12.  
  13.  
  14.     public class GUI{
  15.        
  16.        
  17.        
  18.        
  19.         private JFrame f;
  20.         private JPanel p;
  21.         private JButton b1;
  22.         private JButton b2;
  23.         private JLabel lab;
  24.         private Connection con;
  25.         private Statement stmt;
  26.         PreparedStatement ps=null;
  27.         ResultSet result;
  28.         JComboBox player;
  29.        
  30.        
  31.        
  32.         public GUI() {
  33.             kitchengui();
  34.         }
  35.         public void kitchengui() {
  36.            
  37.             f = new JFrame("Kichen");
  38.             f.setVisible(true);
  39.             f.setSize(600,400);
  40.             f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  41.            
  42.            
  43.             p=new JPanel();
  44.            
  45.            
  46.            
  47.             b1 =new JButton("button1");
  48.             b2 =new JButton("button2");
  49.             lab =new JLabel();
  50.             player=new JComboBox();
  51.              
  52.             p.add(b1);
  53.             p.add(b2);
  54.             p.add(lab);
  55.             p.add(player);
  56.            
  57.            
  58.             f.add(p);
  59.            
  60.        
  61.         try {
  62.             Class.forName("com.mysql.jdbc.Driver");
  63.            
  64.             con =DriverManager.getConnection("jdbc:mysql://localhost:3306/realmadrid","root","");
  65.            
  66.             stmt = (Statement) con.createStatement();
  67.             result =((java.sql.Statement) stmt).executeQuery("SELECT * FROM players");
  68.         while(result.next()) {
  69.             String playername = result.getString("Name");
  70.             player.addItem(playername);
  71.         }
  72.         }catch(SQLException e1){
  73.            
  74.             JOptionPane.showMessageDialog(null, "ERROR in SQL !");
  75.         }catch(ClassNotFoundException e1){
  76.             JOptionPane.showMessageDialog(null, "Class not found Error !");
  77.         }
  78.         }
  79.     public static void main(String[]args) {
  80.        
  81.         new  GUI();
  82.      } 
  83.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement