Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Connection koneksi = null;
- Statement stat = null;
- ResultSet hasil = null;
- //membuat button
- JButton next = new JButton(">>");
- JButton prev = new JButton("<<");
- JButton input = new JButton("INPUT");
- JButton input2 = new JButton("INPUT");
- JButton del = new JButton("DELETE");
- JButton submit = new JButton("SUBMIT");
- JButton view = new JButton("VIEW");
- public FinalProject() {
- koneksiDatabase();
- data();
- history();
- history2();
- setMenu();
- tab();
- setTampilan();
- }
- public void koneksiDatabase(){
- try{
- Class.forName("com.mysql.jdbc.Driver");
- koneksi = DriverManager.getConnection("jdbc:mysql://localhost/finalproject","root","");
- stat = koneksi.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
- }catch(Exception e){
- System.out.println(e.getMessage());
- }
- }
- public void data(){
- try{
- hasil = stat.executeQuery("Select * from film");
- if(hasil.next()){
- tf1.setText(hasil.getString(1));
- tf2.setText(hasil.getString(2));
- }
- }catch(Exception e){
- JOptionPane.showMessageDialog(null, e.getMessage(), "SQL Exception", JOptionPane.ERROR_MESSAGE);
- }
- }
- public void setMenu(){
- p1.setLayout(new GridLayout(3,2));
- p1.add(new JLabel("Kode Film"));
- p1.add(tf1);
- p1.add(new JLabel("JudulFilm"));
- p1.add(tf2);
- p2.setLayout(new FlowLayout());
- p2.add(prev);
- p2.add(new JLabel(""));
- p2.add(next);
- p3.setLayout(new BorderLayout());
- p3.add(p1,"North");
- p3.add(p2,"South");
- p11.setLayout(new GridLayout(4,2));
- p11.add(new JLabel("Last Movie Registered : "));
- p11.add(new JLabel(tp));
- p11.add(new JLabel("Time : "));
- p11.add(new JLabel(tp2));
- p11.add(new JLabel("Last Member inserted : "));
- p11.add(new JLabel(tp3));
- p11.add(new JLabel("Time : "));
- p11.add(new JLabel(tp4));
- p10.add(p11,"North");
- p12.setLayout(new BorderLayout());
- p14.setLayout(new FlowLayout());
- p14.add(input2);
- p12.add(p13,"North");
- p12.add(p14,"South");
- }
- public void history(){
- try{
- hasil = stat.executeQuery("Select * from history order by waktu_flm desc");
- hasil.next();
- tp = hasil.getString(2);
- tp2 = hasil.getString(5);
- }catch(Exception t){
- JOptionPane.showMessageDialog(null, t.getMessage(), "SQL Exception", JOptionPane.ERROR_MESSAGE);
- }
- }
- public void history2(){
- try{
- hasil = stat.executeQuery("Select * from history order by waktu_member desc");
- hasil.next();
- tp3 = hasil.getString(4);
- tp4 = hasil.getString(6);
- }catch(Exception y){
- JOptionPane.showMessageDialog(null, y.getMessage(), "SQL Exception", JOptionPane.ERROR_MESSAGE);
- }
- }
- public static void main(String[] args) {
- new FinalProject();
- }
- //membuat action listener
- @Override
- public void actionPerformed(ActionEvent e){
- if(e.getSource()==next){
- try{
- hasil.next();
- tf1.setText(hasil.getString(1));
- tf2.setText(hasil.getString(2));
- }catch(Exception f){
- JOptionPane.showMessageDialog(null, f.getMessage(), "SQL Exception", JOptionPane.ERROR_MESSAGE);
- }
- }
- else if(e.getSource()==prev){
- try{
- hasil.previous();
- tf1.setText(hasil.getString(1));
- tf2.setText(hasil.getString(2));
- }catch(Exception a){
- JOptionPane.showMessageDialog(null, a.getMessage(), "SQL Exception", JOptionPane.ERROR_MESSAGE);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement