Advertisement
Guest User

ohjelmistotuotanto

a guest
Sep 10th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package gui;
  6.  
  7. /**
  8. *
  9. * @author ilmarir
  10. */
  11. import java.util.logging.Level;
  12. import java.util.logging.Logger;
  13. import javax.swing.*;
  14. import java.awt.*;
  15. import java.sql.*;
  16.  
  17. public class Gui {
  18.  
  19. /**
  20. * @param args the command line arguments
  21. */
  22. public static void main(String[] args) throws SQLException {
  23.  
  24. try {
  25. Class.forName("com.mysql.jdbc.Driver");
  26. } catch (ClassNotFoundException e) {
  27. System.err.println("JDBC-ajurin lataus epäonnistui");
  28. System.exit(-1); // lopetus heti virheen vuoksi
  29. }
  30.  
  31. final String URL = "jdbc:mysql://10.114.32.18/tilanvaraus";
  32. final String USERNAME = "tilanvaraus";
  33. final String PASSWORD = "mysteerikuutioR5";
  34.  
  35. Connection conn =DriverManager.getConnection(URL, USERNAME, PASSWORD);
  36.  
  37. Statement stmt = conn.createStatement();
  38. String query = "select name FROM Room";
  39. ResultSet rs = stmt.executeQuery(query);
  40. String[] nimet = new String[20];
  41. int i = 0;
  42. while (rs.next()) {
  43. nimet[i] = rs.getString("name");
  44. i++;
  45. }
  46. rs.close();
  47. stmt.close();
  48. conn.close();
  49.  
  50. JList list;
  51. JFrame f=new JFrame();//creating instance of JFrame
  52. JPanel p = new JPanel();
  53.  
  54. //JButton b=new JButton("click");//creating instance of JButton
  55. //b.setBounds(130,100,100, 40);//x axis, y axis, width, height
  56. //f.add(b);//adding button in JFrame
  57.  
  58. list = new JList(nimet); //data has type Object[]
  59. //list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
  60. //list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
  61. //list.setVisibleRowCount(-1);
  62. //JScrollPane listScroller = new JScrollPane(list);
  63. //listScroller.setPreferredSize(new Dimension(250, 80));
  64.  
  65. f.add(p);
  66. p.add(list);
  67.  
  68. f.pack();
  69. //f.setSize(600,700);//400 width and 500 height
  70. f.setLayout(null);//using no layout managers
  71. f.setVisible(true);//making the frame visible
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement