Advertisement
Guest User

Untitled

a guest
May 26th, 2017
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.20 KB | None | 0 0
  1. import java.awt.event.*;
  2. import java.util.*;
  3. import javax.swing.*;
  4. import java.sql.*;
  5. import java.awt.*;
  6. import javax.swing.event.*;
  7.  
  8. public class FinalProject extends JFrame implements ActionListener {
  9.     Connection koneksi = null;
  10.     Statement stat = null;
  11.     ResultSet hasil = null;
  12.     private String [] menu = {"List Film", "Input Data", "Output Data"};
  13.    
  14. JTabbedPane tab = new JTabbedPane();
  15.    
  16. JApplet apl = new JApplet();
  17.    
  18. JButton next = new JButton(">>");
  19. JButton prev = new JButton("<<");
  20. JButton input = new JButton("INPUT");
  21. JButton del = new JButton("DELETE");
  22.  
  23. JTextField tf1 = new JTextField(20);
  24. JTextField tf2 = new JTextField(20);
  25. JTextField tf3 = new JTextField(8);
  26. JTextField tf4 = new JTextField(8);
  27.  
  28. JMenuBar bar = new JMenuBar();
  29.  
  30. JMenu menu1 = new JMenu("Help");
  31.  
  32. JMenuItem mi1 = new JMenuItem("About");
  33.  
  34. JPanel p1 = new JPanel();
  35. JPanel p2 = new JPanel();
  36. JPanel p3 = new JPanel();
  37. JPanel p4 = new JPanel();
  38. JPanel p5 = new JPanel();
  39. JPanel p6 = new JPanel();
  40.  
  41.  
  42. JTextArea ta1 = new JTextArea();
  43. JTextArea ta2 = new JTextArea();
  44.  
  45. ImageIcon ikon = new ImageIcon("movie.jpg");
  46.  
  47.     public FinalProject() {
  48.         koneksiDatabase();
  49.         data();
  50.         setMenu();
  51.         tab();
  52.         setTampilan();
  53.     }
  54.  
  55. public void setTampilan(){
  56.     setTitle("Movie Organizer");
  57.     setIconImage(ikon.getImage());
  58.     setVisible(true);
  59.     setJMenuBar(bar);
  60.     bar.add(menu1);
  61.     menu1.add(mi1);
  62.     setSize(400,240);
  63.     setDefaultCloseOperation(EXIT_ON_CLOSE);
  64.    
  65.     next.addActionListener(this);
  66.     prev.addActionListener(this);
  67.     input.addActionListener(this);
  68.     del.addActionListener(this);
  69. }
  70.  
  71. public void koneksiDatabase(){
  72.     try{
  73.         Class.forName("com.mysql.jdbc.Driver");
  74.         koneksi = DriverManager.getConnection("jdbc:mysql://localhost/finalproject","root","");
  75.         stat = koneksi.createStatement();
  76.    
  77.     }catch(Exception e){
  78.         System.out.println(e.getMessage());
  79.     }
  80. }
  81.  
  82. public void data(){
  83.     try{
  84.         hasil = stat.executeQuery("Select * from mslist");
  85.        
  86.         if(hasil.next()){
  87.            
  88.             tf1.setText(hasil.getString(1));
  89.             tf2.setText(hasil.getString(2));
  90.  
  91.             }
  92.     }catch(Exception e){
  93.        
  94.     }
  95. }
  96.  
  97. public void tab(){
  98.            
  99.               tab.addTab(menu[0],p3);
  100.               tab.addTab(menu[1],p4);
  101.               //tab.addTab(menu[2],p3);
  102.              
  103.             tab.addChangeListener(new ChangeListener() {
  104.               public void stateChanged(ChangeEvent e) {
  105.               }
  106.             });
  107.             Container cp = getContentPane();
  108.             //cp.add(BorderLayout.NORTH,tf1);
  109.             cp.add(tab);
  110.             }
  111.    
  112. public void setMenu(){
  113.  
  114.     p1.setLayout(new GridLayout(3,2));
  115.     p1.add(new JLabel("Kode Film"));
  116.     p1.add(tf1);
  117.     p1.add(new JLabel("JudulFilm"));
  118.     p1.add(tf2);
  119.    
  120.     p2.setLayout(new FlowLayout());
  121.     p2.add(prev);
  122.     p2.add(new JLabel(""));
  123.     p2.add(next);
  124.    
  125.     p3.setLayout(new BorderLayout());
  126.     p3.add(p1,"North");
  127.     p3.add(p2,"South");
  128.    
  129.     p4.setLayout(new BorderLayout());
  130.    
  131.     p5.setLayout(new GridLayout(2,2));
  132.     p5.add(new JLabel("Add new movie code : "));
  133.     p5.add(tf3);
  134.     p5.add(new JLabel("Add new movie list : "));
  135.     p5.add(tf4);
  136.    
  137.     p6.setLayout(new FlowLayout());
  138.     p6.add(input);
  139.     p6.add(new JLabel(""));
  140.     p6.add(del);
  141.    
  142.     p4.add(p5,"North");
  143.     p4.add(p6,"South");
  144. }
  145.     public static void main(String[] args) {
  146.         new FinalProject();
  147.     }
  148.  
  149.     @Override
  150.     public void actionPerformed(ActionEvent e){
  151.         if(e.getSource()==next){
  152.             try{
  153.             hasil.next();
  154.             tf1.setText(hasil.getString(1));
  155.             tf2.setText(hasil.getString(2));
  156.             }catch(Exception f){
  157.                 JOptionPane.showMessageDialog(null, f.getMessage(), "SQL Exception", JOptionPane.ERROR_MESSAGE);
  158.             }
  159.            
  160.             }else if(e.getSource()==prev){
  161.                 try{
  162.                 hasil.previous();
  163.                 tf1.setText(hasil.getString(1));
  164.                 tf2.setText(hasil.getString(2));
  165.     }catch(Exception a){
  166.         JOptionPane.showMessageDialog(null, a.getMessage(), "SQL Exception", JOptionPane.ERROR_MESSAGE);
  167.     }
  168.     }else if(e.getSource()==input){
  169.         String temp = tf3.getText();
  170.         String temp2 = tf4.getText();
  171.         try{
  172.             stat.executeUpdate("INSERT INTO mslist VALUES (\"" + temp + "\", \"" +temp2 + "\")");
  173.             JOptionPane.showMessageDialog(null, "Success!","Attention!",JOptionPane.INFORMATION_MESSAGE);
  174.         }catch(Exception v){
  175.              JOptionPane.showMessageDialog(null, v.getMessage(), "SQL Exception", JOptionPane.ERROR_MESSAGE);
  176.         }
  177.        
  178.     }
  179.     }
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement