Advertisement
Guest User

Untitled

a guest
May 27th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.28 KB | None | 0 0
  1.     Connection koneksi = null;
  2.     Statement stat = null;
  3.     ResultSet hasil = null;
  4.  
  5. //membuat button
  6. JButton next = new JButton(">>");
  7. JButton prev = new JButton("<<");
  8. JButton input = new JButton("INPUT");
  9. JButton input2 = new JButton("INPUT");
  10. JButton del = new JButton("DELETE");
  11. JButton submit = new JButton("SUBMIT");
  12. JButton view = new JButton("VIEW");
  13.  
  14.  
  15.     public FinalProject() {
  16.         koneksiDatabase();
  17.         data();
  18.         history();
  19.         history2();
  20.         setMenu();
  21.         tab();
  22.         setTampilan();
  23.     }
  24.  
  25. public void koneksiDatabase(){
  26.     try{
  27.         Class.forName("com.mysql.jdbc.Driver");
  28.         koneksi = DriverManager.getConnection("jdbc:mysql://localhost/finalproject","root","");
  29.         stat = koneksi.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
  30.    
  31.     }catch(Exception e){
  32.         System.out.println(e.getMessage());
  33.     }
  34. }
  35.  
  36. public void data(){
  37.     try{
  38.         hasil = stat.executeQuery("Select * from film");
  39.  
  40.         if(hasil.next()){
  41.             tf1.setText(hasil.getString(1));
  42.             tf2.setText(hasil.getString(2));
  43.  
  44.             }
  45.     }catch(Exception e){
  46.         JOptionPane.showMessageDialog(null, e.getMessage(), "SQL Exception", JOptionPane.ERROR_MESSAGE);
  47.     }
  48. }
  49.    
  50. public void setMenu(){
  51.  
  52.     p1.setLayout(new GridLayout(3,2));
  53.     p1.add(new JLabel("Kode Film"));
  54.     p1.add(tf1);
  55.     p1.add(new JLabel("JudulFilm"));
  56.     p1.add(tf2);
  57.    
  58.     p2.setLayout(new FlowLayout());
  59.     p2.add(prev);
  60.     p2.add(new JLabel(""));
  61.     p2.add(next);
  62.    
  63.     p3.setLayout(new BorderLayout());
  64.     p3.add(p1,"North");
  65.     p3.add(p2,"South");
  66.    
  67.     p11.setLayout(new GridLayout(4,2));
  68.     p11.add(new JLabel("Last Movie Registered : "));
  69.     p11.add(new JLabel(tp));
  70.     p11.add(new JLabel("Time : "));
  71.     p11.add(new JLabel(tp2));
  72.     p11.add(new JLabel("Last Member inserted : "));
  73.     p11.add(new JLabel(tp3));
  74.     p11.add(new JLabel("Time : "));
  75.     p11.add(new JLabel(tp4));
  76.    
  77.     p10.add(p11,"North");
  78.    
  79.     p12.setLayout(new BorderLayout());
  80.    
  81.     p14.setLayout(new FlowLayout());
  82.     p14.add(input2);
  83.    
  84.     p12.add(p13,"North");
  85.     p12.add(p14,"South");
  86. }
  87.  
  88. public void history(){
  89.     try{
  90.    
  91.         hasil = stat.executeQuery("Select * from history order by waktu_flm desc");
  92.         hasil.next();
  93.        
  94.     tp = hasil.getString(2);
  95.     tp2 = hasil.getString(5);
  96.    
  97.    
  98. }catch(Exception t){
  99.     JOptionPane.showMessageDialog(null, t.getMessage(), "SQL Exception", JOptionPane.ERROR_MESSAGE);
  100. }
  101. }
  102. public void history2(){
  103.     try{
  104.     hasil = stat.executeQuery("Select * from history order by waktu_member desc");
  105.     hasil.next();
  106.    
  107.     tp3 = hasil.getString(4);
  108.     tp4 = hasil.getString(6);
  109.    
  110. }catch(Exception y){
  111.     JOptionPane.showMessageDialog(null, y.getMessage(), "SQL Exception", JOptionPane.ERROR_MESSAGE);
  112. }
  113. }
  114.  
  115.     public static void main(String[] args) {
  116.         new FinalProject();
  117.     }
  118.  
  119.     //membuat action listener
  120.     @Override
  121.     public void actionPerformed(ActionEvent e){
  122.         if(e.getSource()==next){
  123.            
  124.  
  125.             try{
  126.             hasil.next();
  127.             tf1.setText(hasil.getString(1));
  128.             tf2.setText(hasil.getString(2));
  129.            
  130.             }catch(Exception f){
  131.                 JOptionPane.showMessageDialog(null, f.getMessage(), "SQL Exception", JOptionPane.ERROR_MESSAGE);
  132.             }
  133.             }
  134.        
  135.         else if(e.getSource()==prev){
  136.                 try{
  137.                 hasil.previous();
  138.                 tf1.setText(hasil.getString(1));
  139.                 tf2.setText(hasil.getString(2));
  140.  
  141.     }catch(Exception a){
  142.         JOptionPane.showMessageDialog(null, a.getMessage(), "SQL Exception", JOptionPane.ERROR_MESSAGE);
  143.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement