Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.event.*;
- import java.util.*;
- import javax.swing.*;
- import java.sql.*;
- import java.awt.*;
- import javax.swing.event.*;
- public class FinalProject extends JFrame implements ActionListener {
- Connection koneksi = null;
- Statement stat = null;
- ResultSet hasil = null;
- private String [] menu = {"List Film", "Input Data", "Output Data"};
- JTabbedPane tab = new JTabbedPane();
- JApplet apl = new JApplet();
- JButton next = new JButton(">>");
- JButton prev = new JButton("<<");
- JButton input = new JButton("INPUT");
- JButton del = new JButton("DELETE");
- JTextField tf1 = new JTextField(20);
- JTextField tf2 = new JTextField(20);
- JTextField tf3 = new JTextField(8);
- JTextField tf4 = new JTextField(8);
- JMenuBar bar = new JMenuBar();
- JMenu menu1 = new JMenu("Help");
- JMenuItem mi1 = new JMenuItem("About");
- JPanel p1 = new JPanel();
- JPanel p2 = new JPanel();
- JPanel p3 = new JPanel();
- JPanel p4 = new JPanel();
- JPanel p5 = new JPanel();
- JPanel p6 = new JPanel();
- JTextArea ta1 = new JTextArea();
- JTextArea ta2 = new JTextArea();
- ImageIcon ikon = new ImageIcon("movie.jpg");
- public FinalProject() {
- koneksiDatabase();
- data();
- setMenu();
- tab();
- setTampilan();
- }
- public void setTampilan(){
- setTitle("Movie Organizer");
- setIconImage(ikon.getImage());
- setVisible(true);
- setJMenuBar(bar);
- bar.add(menu1);
- menu1.add(mi1);
- setSize(400,240);
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- next.addActionListener(this);
- prev.addActionListener(this);
- input.addActionListener(this);
- del.addActionListener(this);
- }
- public void koneksiDatabase(){
- try{
- Class.forName("com.mysql.jdbc.Driver");
- koneksi = DriverManager.getConnection("jdbc:mysql://localhost/finalproject","root","");
- stat = koneksi.createStatement();
- }catch(Exception e){
- System.out.println(e.getMessage());
- }
- }
- public void data(){
- try{
- hasil = stat.executeQuery("Select * from mslist");
- if(hasil.next()){
- tf1.setText(hasil.getString(1));
- tf2.setText(hasil.getString(2));
- }
- }catch(Exception e){
- }
- }
- public void tab(){
- tab.addTab(menu[0],p3);
- tab.addTab(menu[1],p4);
- //tab.addTab(menu[2],p3);
- tab.addChangeListener(new ChangeListener() {
- public void stateChanged(ChangeEvent e) {
- }
- });
- Container cp = getContentPane();
- //cp.add(BorderLayout.NORTH,tf1);
- cp.add(tab);
- }
- 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");
- p4.setLayout(new BorderLayout());
- p5.setLayout(new GridLayout(2,2));
- p5.add(new JLabel("Add new movie code : "));
- p5.add(tf3);
- p5.add(new JLabel("Add new movie list : "));
- p5.add(tf4);
- p6.setLayout(new FlowLayout());
- p6.add(input);
- p6.add(new JLabel(""));
- p6.add(del);
- p4.add(p5,"North");
- p4.add(p6,"South");
- }
- public static void main(String[] args) {
- new FinalProject();
- }
- @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);
- }
- }else if(e.getSource()==input){
- String temp = tf3.getText();
- String temp2 = tf4.getText();
- try{
- stat.executeUpdate("INSERT INTO mslist VALUES (\"" + temp + "\", \"" +temp2 + "\")");
- JOptionPane.showMessageDialog(null, "Success!","Attention!",JOptionPane.INFORMATION_MESSAGE);
- }catch(Exception v){
- JOptionPane.showMessageDialog(null, v.getMessage(), "SQL Exception", JOptionPane.ERROR_MESSAGE);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement