Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import javax.swing.*;
- import java.awt.*;
- import java.beans.Statement;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- public class GUI{
- private JFrame f;
- private JPanel p;
- private JButton b1;
- private JButton b2;
- private JLabel lab;
- private Connection con;
- private Statement stmt;
- PreparedStatement ps=null;
- ResultSet result;
- JComboBox player;
- public GUI() {
- kitchengui();
- }
- public void kitchengui() {
- f = new JFrame("Kichen");
- f.setVisible(true);
- f.setSize(600,400);
- f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- p=new JPanel();
- b1 =new JButton("button1");
- b2 =new JButton("button2");
- lab =new JLabel();
- player=new JComboBox();
- p.add(b1);
- p.add(b2);
- p.add(lab);
- p.add(player);
- f.add(p);
- try {
- Class.forName("com.mysql.jdbc.Driver");
- con =DriverManager.getConnection("jdbc:mysql://localhost:3306/realmadrid","root","");
- stmt = (Statement) con.createStatement();
- result =((java.sql.Statement) stmt).executeQuery("SELECT * FROM players");
- while(result.next()) {
- String playername = result.getString("Name");
- player.addItem(playername);
- }
- }catch(SQLException e1){
- JOptionPane.showMessageDialog(null, "ERROR in SQL !");
- }catch(ClassNotFoundException e1){
- JOptionPane.showMessageDialog(null, "Class not found Error !");
- }
- }
- public static void main(String[]args) {
- new GUI();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement