Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import java.sql.*;
- import javax.swing.*;
- class gametest2dummy
- {
- public static void main (String[]pop)
- {
- try
- {
- String url = "jdbc:mysql://localhost/game_test";
- Connection koneksi=DriverManager.getConnection(url,"root","");
- try
- {
- Statement st = koneksi.createStatement();
- String sql = "SELECT * FROM gamequest ORDER BY RAND() LIMIT 1";
- ResultSet rs = st.executeQuery(sql);
- JFrame nez=new JFrame();
- String question = rs.getString("questions");
- String hint = rs.getString("hints");
- JLabel hintx = new JLabel("Hint : "+hint);
- nez.add(hintx); hintx.setBounds(20,20,80,25);
- if(rs.next())
- {
- String[] question_explode = question.split("");
- int jumlah = question_explode.length;
- JTextField[] fields=new JTextField[jumlah];
- int n = 0;
- for (int i=1; i<jumlah; i++)
- {
- if (i==3 || i==7)
- {
- fields[i] = new JTextField(question_explode[i]);
- fields[i].setEditable(false);
- }
- else
- {
- fields[i] = new JTextField();
- }
- nez.add(fields[i]);
- fields[i].setBounds(n=(n+35),50,25,25);
- }
- nez.setSize(480,500);
- nez.setLayout(null);
- nez.setVisible(true);
- }
- }
- catch (Exception ae)
- {
- javax.swing.JOptionPane.showMessageDialog(null,"Query SQL?","Whyy :((",
- javax.swing.JOptionPane.ERROR_MESSAGE);
- }
- }
- catch (Exception ex)
- {
- javax.swing.JOptionPane.showMessageDialog(null,"Check database connection!","Failed to connect!",
- javax.swing.JOptionPane.ERROR_MESSAGE);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement