Advertisement
Guest User

gametes

a guest
Dec 1st, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import java.sql.*;
  4. import javax.swing.*;
  5. class gametest2dummy
  6. {
  7. public static void main (String[]pop)
  8. {
  9.  
  10. try
  11. {
  12. String url = "jdbc:mysql://localhost/game_test";
  13. Connection koneksi=DriverManager.getConnection(url,"root","");
  14. try
  15. {
  16. Statement st = koneksi.createStatement();
  17. String sql = "SELECT * FROM gamequest ORDER BY RAND() LIMIT 1";
  18. ResultSet rs = st.executeQuery(sql);
  19. JFrame nez=new JFrame();
  20. String question = rs.getString("questions");
  21. String hint = rs.getString("hints");
  22. JLabel hintx = new JLabel("Hint : "+hint);
  23. nez.add(hintx); hintx.setBounds(20,20,80,25);
  24. if(rs.next())
  25. {
  26. String[] question_explode = question.split("");
  27. int jumlah = question_explode.length;
  28.  
  29. JTextField[] fields=new JTextField[jumlah];
  30.  
  31. int n = 0;
  32. for (int i=1; i<jumlah; i++)
  33. {
  34. if (i==3 || i==7)
  35. {
  36. fields[i] = new JTextField(question_explode[i]);
  37. fields[i].setEditable(false);
  38. }
  39. else
  40. {
  41. fields[i] = new JTextField();
  42. }
  43.  
  44. nez.add(fields[i]);
  45. fields[i].setBounds(n=(n+35),50,25,25);
  46. }
  47.  
  48. nez.setSize(480,500);
  49. nez.setLayout(null);
  50. nez.setVisible(true);
  51. }
  52. }
  53. catch (Exception ae)
  54. {
  55. javax.swing.JOptionPane.showMessageDialog(null,"Query SQL?","Whyy :((",
  56. javax.swing.JOptionPane.ERROR_MESSAGE);
  57. }
  58. }
  59. catch (Exception ex)
  60. {
  61. javax.swing.JOptionPane.showMessageDialog(null,"Check database connection!","Failed to connect!",
  62. javax.swing.JOptionPane.ERROR_MESSAGE);
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement