Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * 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.
- */
- package database_ii_projcect_lab;
- import java.awt.BorderLayout;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.EventQueue;
- import java.awt.FlowLayout;
- import java.awt.GridLayout;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.Statement;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.JButton;
- import javax.swing.JComboBox;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.UIManager;
- import javax.swing.UnsupportedLookAndFeelException;
- /**
- *
- * @author adelali
- */
- public class MainFrame extends javax.swing.JFrame {
- /**
- * Creates new form MainFrame
- */
- public MainFrame() {
- EventQueue.invokeLater(new Runnable() {
- @Override
- public void run() {
- try {
- UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
- } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
- }
- JFrame frame = new JFrame("Test");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setLayout(new BorderLayout());
- frame.add(new TestPane());
- frame.pack();
- frame.setLocationRelativeTo(null);
- frame.setVisible(true);
- }
- });
- }
- public class TestPane extends JPanel {
- private JComboBox floorList;
- private JPanel buttons=new JPanel(new GridLayout(0, 4));;
- public TestPane() {
- setLayout(new BorderLayout());
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection(
- "jdbc:mysql://localhost:8889/dbproject", "root", "root");
- Statement stmt = con.createStatement();
- // ResultSet rs = stmt.executeQuery("select * from company");
- // while (rs.next()) {
- // System.out.println(rs.getString(1) + " " + rs.getString(2) + " " + rs.getString(3));
- // }
- ResultSet rs = con.getMetaData().getCatalogs();
- while (rs.next()) {
- // System.out.println(rs.getString(1));
- buttons.add(new JButton(rs.getString(1)));
- }
- con.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- // buttons.revalidate();
- JPanel top = new JPanel(new FlowLayout(FlowLayout.CENTER));
- // top.add(floorList);
- // top.add(go);
- // buttons = new JPanel(new GridLayout(0, 4));
- buttons.setPreferredSize(new Dimension(200, 200));
- top.setVisible(true);
- add(top, BorderLayout.NORTH);
- add(buttons);
- }
- }
- /**
- * 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() {
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 296, Short.MAX_VALUE)
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGap(0, 327, Short.MAX_VALUE)
- );
- pack();
- }// </editor-fold>
- /**
- * @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(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(MainFrame.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 MainFrame().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement