Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JTextPane;
- import java.awt.Color;
- import javax.swing.JButton;
- import javax.swing.JTextField;
- import java.awt.event.ActionListener;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.Statement;
- import java.awt.event.ActionEvent;
- public class prog extends JFrame {
- private Panel contentPane;
- private JTextField textField;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- prog frame = new prog();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public prog() {
- setTitle("\u0418\u0433\u0440\u0430 - \u041F\u0440\u0435\u0434\u0441\u043A\u0430\u0437\u0430\u043D\u0438\u0435.");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 532, 513);
- contentPane = new Panel();
- contentPane.setBackground(Color.RED);
- contentPane.setForeground(Color.RED);
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- JButton button = new JButton("\u0423\u0437\u043D\u0430\u0442\u044C");
- button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- Connection con;
- try{
- String driverName = "com.mysql.jdbc.Driver";
- Class.forName(driverName);
- String serverName = "localhost";
- String mybase = "game";
- String url_="jdbc:mysql://"+serverName+"/"+mybase;
- String username = "root";
- String password = "";
- con = DriverManager.getConnection(url_, username, password);
- int rez = (int)(Math.random()*5)+1;
- String query = "SELECT * FROM game00 WHERE (id="+rez+")";
- Statement stmt = con.createStatement();
- ResultSet rs = stmt.executeQuery(query);
- String temp;
- while(rs.next()){
- temp = rs.getString("text");
- textField.setText(temp);
- }
- con.close();
- }
- catch(Exception exp){}
- }});
- button.setBounds(61, 202, 89, 23);
- contentPane.add(button);
- textField = new JTextField();
- textField.setBounds(0, 11, 415, 187);
- contentPane.add(textField);
- textField.setColumns(10);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement