Advertisement
Guest User

Untitled

a guest
Nov 15th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.88 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.JButton;
  8. import java.awt.GridLayout;
  9.  
  10. import java.sql.*;
  11. import javax.sql.*;
  12. import javax.swing.JLabel;
  13. import javax.swing.JTextField;
  14. import java.awt.event.ActionListener;
  15. import java.awt.event.ActionEvent;
  16.  
  17. public class frmHallgato extends JFrame {
  18.  
  19.     private JPanel contentPane;
  20.  
  21.     /**
  22.      * Launch the application.
  23.      */
  24.     public static final String USER="root";
  25.     public static final String PASS="root";
  26.     public static final String DB_URL="jdbc:mysql://localhost:3311/egyetem";
  27.     public static Connection kapcsolat;
  28.     public static ResultSet rs;
  29.     public static Statement lekerdezes;
  30.    
  31.     private JTextField txtSzak;
  32.     private JTextField txtTagozat;
  33.     private JTextField txtHid;
  34.     private JTextField txtHNeve;
  35.     private JTextField txtEvfolyam;
  36.     public static void main(String[] args) {
  37.         EventQueue.invokeLater(new Runnable() {
  38.             public void run() {
  39.                 try {
  40.                     Class.forName("com.mysql.jdbc.Driver");
  41.                     kapcsolat = DriverManager.getConnection(DB_URL,USER,PASS);
  42.                     String sql = "select  * from hallgato inner join szak"
  43.                             + " on szak.Szakazonosito=hallgato.Szakazonosito "
  44.                             + " where evfolyam='I'";
  45.                     lekerdezes = kapcsolat.createStatement();
  46.                     rs  = lekerdezes.executeQuery(sql);
  47.                     while(rs.next())
  48.                     {
  49.                         int hId = rs.getInt(1);
  50.                         String hNeve = rs.getString(2);
  51.                         String hEvfolyam = rs.getString("Evfolyam");
  52.                         String szNeve = rs.getString(7);
  53.                         String ki = String.format("%s(%d):%s,%s",
  54.                                 hNeve,hId,szNeve,hEvfolyam);
  55.                         System.out.println(ki);
  56.                     }
  57.                     rs.first();
  58.                    
  59.                     frmHallgato frame = new frmHallgato();
  60.                     frame.setVisible(true);
  61.                 } catch (Exception e) {
  62.                     e.printStackTrace();
  63.                 }
  64.             }
  65.         });
  66.     }
  67.  
  68.     /**
  69.      * Create the frame.
  70.      */
  71.     public frmHallgato() {
  72.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  73.         setBounds(100, 100, 450, 300);
  74.         contentPane = new JPanel();
  75.         contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  76.         contentPane.setLayout(new BorderLayout(0, 0));
  77.         setContentPane(contentPane);
  78.        
  79.         JPanel pNav = new JPanel();
  80.         contentPane.add(pNav, BorderLayout.SOUTH);
  81.         pNav.setLayout(new GridLayout(0, 4, 0, 0));
  82.        
  83.         JButton btnElso = new JButton("Els\u0151");
  84.         btnElso.addActionListener(new ActionListener() {
  85.             public void actionPerformed(ActionEvent arg0) {
  86.             try {
  87.                 rs.first();
  88.                 betolt();
  89.             } catch (SQLException e) {
  90.                 // TODO Auto-generated catch block
  91.                 e.printStackTrace();
  92.             }
  93.            
  94.             }
  95.         });
  96.         pNav.add(btnElso);
  97.        
  98.         JButton btnElozo = new JButton("El\u00F6z\u0151");
  99.         btnElozo.addActionListener(new ActionListener() {
  100.             public void actionPerformed(ActionEvent e) {
  101.                   try {
  102.                         rs.previous();
  103.                         betolt();
  104.                     } catch (SQLException h) {
  105.                         // TODO Auto-generated catch block
  106.                         h.printStackTrace();
  107.                     }
  108.             }
  109.         });
  110.         pNav.add(btnElozo);
  111.        
  112.         JButton btnKovetkezo = new JButton("K\u00F6vetkez\u0151");
  113.         btnKovetkezo.addActionListener(new ActionListener() {
  114.             public void actionPerformed(ActionEvent arg0) {
  115.                try {
  116.                 rs.next();
  117.                 betolt();
  118.             } catch (SQLException e) {
  119.                 // TODO Auto-generated catch block
  120.                 e.printStackTrace();
  121.             }
  122.                
  123.             }
  124.  
  125.  
  126.         });
  127.         pNav.add(btnKovetkezo);
  128.        
  129.         JButton btnUtolso = new JButton("Utols\u00F3");
  130.         btnUtolso.addActionListener(new ActionListener() {
  131.             public void actionPerformed(ActionEvent e) {
  132.                   try {
  133.                         rs.last();
  134.                         betolt();
  135.                     } catch (SQLException h) {
  136.                         // TODO Auto-generated catch block
  137.                         h.printStackTrace();
  138.                     }
  139.             }
  140.         });
  141.         pNav.add(btnUtolso);
  142.        
  143.         JPanel pAdatok = new JPanel();
  144.         contentPane.add(pAdatok, BorderLayout.CENTER);
  145.         pAdatok.setLayout(new GridLayout(5, 2, 0, 0));
  146.        
  147.         JLabel lblNewLabel = new JLabel("Hallgat\u00F3 azonos\u00EDt\u00F3");
  148.         pAdatok.add(lblNewLabel);
  149.        
  150.         txtHid = new JTextField();
  151.         pAdatok.add(txtHid);
  152.         txtHid.setColumns(10);
  153.        
  154.         JLabel lblNewLabel_1 = new JLabel("Hallgat\u00F3 neve");
  155.         pAdatok.add(lblNewLabel_1);
  156.        
  157.         txtHNeve = new JTextField();
  158.         pAdatok.add(txtHNeve);
  159.         txtHNeve.setColumns(10);
  160.        
  161.         JLabel lblNewLabel_2 = new JLabel("\u00C9vfolyam");
  162.         pAdatok.add(lblNewLabel_2);
  163.        
  164.         txtEvfolyam = new JTextField();
  165.         pAdatok.add(txtEvfolyam);
  166.         txtEvfolyam.setColumns(10);
  167.        
  168.         JLabel lblNewLabel_3 = new JLabel("Tagozat");
  169.         pAdatok.add(lblNewLabel_3);
  170.        
  171.         txtTagozat = new JTextField();
  172.         pAdatok.add(txtTagozat);
  173.         txtTagozat.setColumns(10);
  174.        
  175.         JLabel lblNewLabel_4 = new JLabel("Szak neve");
  176.         pAdatok.add(lblNewLabel_4);
  177.        
  178.         txtSzak = new JTextField();
  179.         pAdatok.add(txtSzak);
  180.         txtSzak.setColumns(10);
  181.     }
  182.  
  183.     protected void betolt() throws SQLException {
  184.         // TODO Auto-generated method stub
  185.         String h = rs.getString(2);
  186.         txtHNeve.setText(h);
  187.     }
  188.  
  189. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement