Advertisement
Guest User

Untitled

a guest
Dec 1st, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.10 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package database_ii_projcect_lab;
  7.  
  8. import java.awt.BorderLayout;
  9. import java.awt.Container;
  10. import java.awt.Dimension;
  11. import java.awt.EventQueue;
  12. import java.awt.FlowLayout;
  13. import java.awt.GridLayout;
  14. import java.awt.event.ActionEvent;
  15. import java.awt.event.ActionListener;
  16. import java.sql.Connection;
  17. import java.sql.DriverManager;
  18. import java.sql.ResultSet;
  19. import java.sql.Statement;
  20. import java.util.logging.Level;
  21. import java.util.logging.Logger;
  22. import javax.swing.JButton;
  23. import javax.swing.JComboBox;
  24. import javax.swing.JFrame;
  25. import javax.swing.JPanel;
  26. import javax.swing.UIManager;
  27. import javax.swing.UnsupportedLookAndFeelException;
  28.  
  29. /**
  30. *
  31. * @author adelali
  32. */
  33. public class MainFrame extends javax.swing.JFrame {
  34.  
  35. /**
  36. * Creates new form MainFrame
  37. */
  38. public MainFrame() {
  39. EventQueue.invokeLater(new Runnable() {
  40. @Override
  41. public void run() {
  42. try {
  43. UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  44. } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
  45. }
  46.  
  47. JFrame frame = new JFrame("Test");
  48. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  49. frame.setLayout(new BorderLayout());
  50. frame.add(new TestPane());
  51. frame.pack();
  52. frame.setLocationRelativeTo(null);
  53. frame.setVisible(true);
  54. }
  55. });
  56. }
  57.  
  58. public class TestPane extends JPanel {
  59.  
  60. private JComboBox floorList;
  61. private JPanel buttons=new JPanel(new GridLayout(0, 4));;
  62.  
  63. public TestPane() {
  64. setLayout(new BorderLayout());
  65.  
  66. try {
  67. Class.forName("com.mysql.jdbc.Driver");
  68.  
  69. Connection con = DriverManager.getConnection(
  70. "jdbc:mysql://localhost:8889/dbproject", "root", "root");
  71.  
  72. Statement stmt = con.createStatement();
  73.  
  74. // ResultSet rs = stmt.executeQuery("select * from company");
  75. // while (rs.next()) {
  76. // System.out.println(rs.getString(1) + " " + rs.getString(2) + " " + rs.getString(3));
  77. // }
  78. ResultSet rs = con.getMetaData().getCatalogs();
  79. while (rs.next()) {
  80. // System.out.println(rs.getString(1));
  81. buttons.add(new JButton(rs.getString(1)));
  82. }
  83. con.close();
  84. } catch (Exception e) {
  85. e.printStackTrace();
  86. }
  87.  
  88. // buttons.revalidate();
  89. JPanel top = new JPanel(new FlowLayout(FlowLayout.CENTER));
  90. // top.add(floorList);
  91. // top.add(go);
  92.  
  93. // buttons = new JPanel(new GridLayout(0, 4));
  94. buttons.setPreferredSize(new Dimension(200, 200));
  95. top.setVisible(true);
  96.  
  97. add(top, BorderLayout.NORTH);
  98. add(buttons);
  99.  
  100. }
  101. }
  102.  
  103. /**
  104. * This method is called from within the constructor to initialize the form.
  105. * WARNING: Do NOT modify this code. The content of this method is always
  106. * regenerated by the Form Editor.
  107. */
  108. @SuppressWarnings("unchecked")
  109. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  110. private void initComponents() {
  111.  
  112. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  113.  
  114. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  115. getContentPane().setLayout(layout);
  116. layout.setHorizontalGroup(
  117. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  118. .addGap(0, 296, Short.MAX_VALUE)
  119. );
  120. layout.setVerticalGroup(
  121. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  122. .addGap(0, 327, Short.MAX_VALUE)
  123. );
  124.  
  125. pack();
  126. }// </editor-fold>
  127.  
  128. /**
  129. * @param args the command line arguments
  130. */
  131. public static void main(String args[]) {
  132. /* Set the Nimbus look and feel */
  133. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  134. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  135. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  136. */
  137. try {
  138. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  139. if ("Nimbus".equals(info.getName())) {
  140. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  141. break;
  142. }
  143. }
  144. } catch (ClassNotFoundException ex) {
  145. java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  146. } catch (InstantiationException ex) {
  147. java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  148. } catch (IllegalAccessException ex) {
  149. java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  150. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  151. java.util.logging.Logger.getLogger(MainFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  152. }
  153. //</editor-fold>
  154.  
  155. /* Create and display the form */
  156. java.awt.EventQueue.invokeLater(new Runnable() {
  157. public void run() {
  158. new MainFrame().setVisible(true);
  159. }
  160. });
  161. }
  162.  
  163. // Variables declaration - do not modify
  164. // End of variables declaration
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement