Advertisement
Guest User

m2_12_3

a guest
Apr 12th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.38 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.EventQueue;
  3.  
  4. import javax.swing.JFrame;
  5. import javax.swing.JPanel;
  6. import javax.swing.border.EmptyBorder;
  7. import javax.swing.JLabel;
  8. import java.awt.Font;
  9. import java.awt.event.ActionEvent;
  10. import java.awt.event.ActionListener;
  11.  
  12. import javax.swing.JButton;
  13. import javax.swing.JTextField;
  14.  
  15. import java.sql.*;
  16.  
  17. public class prog extends JFrame {
  18.  
  19.     //private JPanel contentPane;
  20.     private panel contentPane;
  21.     private JTextField textField;
  22.    
  23.     /**
  24.      * Launch the application.
  25.      */
  26.     public static void main(String[] args) {
  27.         EventQueue.invokeLater(new Runnable() {
  28.             public void run() {
  29.                 try {
  30.                     prog frame = new prog();
  31.                     frame.setVisible(true);
  32.                 } catch (Exception e) {
  33.                     e.printStackTrace();
  34.                 }
  35.             }
  36.         });
  37.     }
  38.  
  39.     /**
  40.      * Create the frame.
  41.      */
  42.     public prog() {
  43.         setTitle("\u041F\u0440\u0435\u0434\u0441\u043A\u0430\u0437\u0430\u043D\u0438\u0435 \u0431\u0443\u0434\u0443\u0449\u0435\u0433\u043E");
  44.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  45.         setBounds(100, 100, 523, 564);
  46.         //contentPane = new JPanel();
  47.         contentPane = new panel();
  48.         contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  49.         setContentPane(contentPane);
  50.         contentPane.setLayout(null);
  51.        
  52.         JLabel lblNewLabel = new JLabel("\u041F\u043E\u0441\u043C\u043E\u0442\u0440\u0438\u0442\u0435 \u043D\u0430 \u043C\u0430\u0433\u0438\u0447\u0435\u0441\u043A\u0438\u0439 \u043A\u0432\u0430\u0434\u0440\u0430\u0442...");
  53.         lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 18));
  54.         lblNewLabel.setBounds(46, 23, 342, 23);
  55.         contentPane.add(lblNewLabel);
  56.        
  57.         JLabel label = new JLabel("\u0412\u0433\u043B\u044F\u0434\u0438\u0442\u0435\u0441\u044C \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u0435..");
  58.         label.setFont(new Font("Tahoma", Font.PLAIN, 15));
  59.         label.setBounds(46, 58, 342, 23);
  60.         contentPane.add(label);
  61.        
  62.         JLabel label_1 = new JLabel("\u041F\u043E\u0434\u0443\u043C\u0430\u0439\u0442\u0435 \u043E \u0442\u043E\u043C, \u0447\u0442\u043E \u0432\u044B \u0445\u043E\u0442\u0438\u0442\u0435...");
  63.         label_1.setFont(new Font("Tahoma", Font.PLAIN, 17));
  64.         label_1.setBounds(46, 365, 342, 23);
  65.         contentPane.add(label_1);
  66.        
  67.         JButton btnNewButton = new JButton("\u0423\u0437\u043D\u0430\u0442\u044C");
  68.         btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 20));
  69.         btnNewButton.setBounds(304, 399, 134, 23);
  70.        
  71.         btnNewButton.addActionListener(new ActionListener() {
  72.             public void actionPerformed(ActionEvent e) {
  73.                
  74.                 //Переменная типа - подключение
  75.                 Connection connect;
  76.                
  77.                 try
  78.                 {
  79.                     String driverName = "com.mysql.jdbc.Driver";
  80.                     Class.forName(driverName);
  81.                    
  82.                     String serverName = "localhost";
  83.                     String mybase = "game";
  84.                     String url_ = "jdbc:mysql://"+serverName+"/"+mybase;
  85.                    
  86.                     //Имя пользователя
  87.                     String username = "root";
  88.                     String password = "";
  89.                    
  90.                     //Установление подключения к базе данных
  91.                     connect = DriverManager.getConnection(url_,username,password);
  92.                 }
  93.                 catch (Exception ex) {
  94.                     // TODO: handle exception
  95.                 }
  96.                
  97.             }
  98.         });
  99.        
  100.         contentPane.add(btnNewButton);
  101.        
  102.         textField = new JTextField();
  103.         textField.setBounds(23, 437, 457, 66);
  104.         contentPane.add(textField);
  105.         textField.setColumns(10);
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement