Pages

Rabu, 21 Desember 2011

Program Pengelola Surat

Kelas Datahandler
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package kasusakhirsemester3;

import java.sql.*;
import oracle.jdbc.pool.OracleDataSource;

public class DataHandler {

    // string „localhost‟ anda ganti dengan IP server yang digunakan
    String jdbcUrl = "jdbc:oracle:thin:@localhost:1521:orcl3";
    String userid = "kejut";
    String password = "105314078";
    Connection conn;
    Statement stmt;
    ResultSet rset;
    String query;
    String sqlString;

    public DataHandler() {
    }
    public void getDBConnection() {
        try {
            OracleDataSource ds;
            ds = new OracleDataSource();
            ds.setURL(jdbcUrl);
            conn = ds.getConnection(userid, password);
            System.out.println("Koneksi berhasil");
        } catch (SQLException ex) {
            System.out.println("Masih belum konek");
        }
    }

    public void close() {
        try {
            conn.close();
        } catch (SQLException ex) {
            System.out.println("Tidak bisa tutup koneksi");
        }
    }

    public static void main(String[] args) throws SQLException {
        DataHandler datahandler = new DataHandler();
        datahandler.getDBConnection();
        datahandler.close();
    }
}




Kelas DataSurat
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package kasusakhirsemester3;

import java.sql.Statement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

public class DataSurat {
private int noSurat;
private String perihal;
private String tanggalSurat;
private String tanggalDiterima;
private String pengirim;
private String penerima;

    public DataSurat() {
    }

    public DataSurat(int noSurat, String perihal, String tanggalSurat, String tanggalDiterima, String pengirim, String penerima) {
        this.noSurat = noSurat;
        this.perihal = perihal;
        this.tanggalSurat = tanggalSurat;
        this.tanggalDiterima = tanggalDiterima;
        this.pengirim = pengirim;
        this.penerima = penerima;
    }

    public int getNoSurat() {
        return noSurat;
    }

    public void setNoSurat(int noSurat) {
        this.noSurat = noSurat;
    }

    public String getPerihal() {
        return perihal;
    }

    public void setPerihal(String perihal) {
        this.perihal = perihal;
    }

    public String getTanggalSurat() {
        return tanggalSurat;
    }

    public void setTanggalSurat(String tanggalSurat) {
        this.tanggalSurat = tanggalSurat;
    }

    public String getTanggalDiterima() {
        return tanggalDiterima;
    }

    public void setTanggalDiterima(String tanggalDiterima) {
        this.tanggalDiterima = tanggalDiterima;
    }

    public String getPengirim() {
        return pengirim;
    }

    public void setPengirim(String pengirim) {
        this.pengirim = pengirim;
    }

    public String getPenerima() {
        return penerima;
    }

    public void setPenerima(String penerima) {
        this.penerima = penerima;
    }

    public static ArrayList searchSurat(String keyword) throws SQLException {
            ArrayList result = null;
            DataHandler dataHandler = new DataHandler();
            dataHandler.getDBConnection();
            Connection conn = dataHandler.conn;
            Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
            String query = "SELECT * FROM data_surat where no_surat like '%" + keyword + "%'";
            ResultSet rset = stmt.executeQuery(query);
            result = new ArrayList();
            while (rset.next()) {
                DataSurat temp = new DataSurat(rset.getInt(1), rset.getString(2), rset.getString(3), rset.getString(4), rset.getString(5), rset.getString(6));
                result.add(temp);
            }
            conn.close();
            return result;
        }

     public static ArrayList addSurat(int noSurat, String perihal, String tanggalSurat, String tanggalDiterima, String pengirim, String penerima ) throws SQLException {
        ArrayList result = null;
        DataHandler dataHandler = new DataHandler();
        dataHandler.getDBConnection();
        Connection conn = dataHandler.conn;
        Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
        String query = "insert into data_surat values (" + noSurat + ", '" + perihal + "', '" + tanggalSurat + "', '"+ tanggalDiterima + "', '"+ pengirim + "', '"+ penerima +"')";
        result = new ArrayList();
        try {
            result.add(stmt.execute(query));
        } catch (SQLException ex) {
            System.out.println("Eror:" + ex.getMessage());
        }
        conn.close();
        return result;
    }

     public static ArrayList searchSurat1() throws SQLException {
        ArrayList result = null;
        DataHandler dataHandler = new DataHandler();
        dataHandler.getDBConnection();
        Connection conn = dataHandler.conn;
        Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);

        String query2 = "select * from data_surat";
        result = new ArrayList();
        ResultSet rset = stmt.executeQuery(query2);
        while (rset.next()) {
            DataSurat temp = new DataSurat(rset.getInt(1), rset.getString(2), rset.getString(3), rset.getString(4), rset.getString(5), rset.getString(6));
            result.add(temp);
        }
        conn.close();
        return result;
    }
    
     public static ArrayList removeSurat(String keyword) throws SQLException {
        ArrayList result = null;
        DataHandler dataHandler = new DataHandler();
        dataHandler.getDBConnection();
        Connection conn = dataHandler.conn;
        Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);

        String query3 = "delete from data_surat where no_surat = '" + keyword + "'";
        result = new ArrayList();
        ResultSet rset = stmt.executeQuery(query3);

        conn.close();
        return result;
    }


}



GUI DataSurat
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package kasusakhirsemester3;

import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.*;

public class DataSuratGUI extends JFrame {

    public JMenuBar Proyek;
    //mengeset ukuran frame yang akan kita buat
    private static final int FRAME_WIDTH = 600;
    private static final int FRAME_HEIGHT = 800;
    private static final int FRAME_X_ORIGIN = 20;
    private static final int FRAME_Y_ORIGIN = 20;
    private JMenu fileMenu;
    private ImageIcon icon = new ImageIcon("AngelDanboDA.jpg");
    JLabel label = new JLabel(icon);

    //method bertipe void untuk menampilkan frame luar yang telah kita buat tadi
    public static void main(String[] args) {
        DataSuratGUI frame = new DataSuratGUI();
        frame.setSize(FRAME_HEIGHT, FRAME_WIDTH);
        frame.setLocation(FRAME_Y_ORIGIN, FRAME_X_ORIGIN);
        frame.setVisible(true);
    }

    //method untuk membuat frame lebih detail dan untuk mengeset
    //title dari frame yang telah kita buat tadi
    public DataSuratGUI() {
        Container contentPane;

        setTitle("Data Surat");

        contentPane = getContentPane();
        contentPane.setLayout(new FlowLayout());
        contentPane.add(label);
               

        createFileMenu();

        JMenuBar menuBar = new JMenuBar();
        this.setJMenuBar(menuBar);
        menuBar.add(fileMenu);

        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    //method bertipe void untuk membuat tampilan file dalam menubar
    //dan di dalamnya terdapat menuitem employee1 dan quit
    private void createFileMenu() {
        final JMenuItem Data1, quit, Cari;
        JMenu New;

        fileMenu = new JMenu("File");

        New = new JMenu("New");
        Data1 = new JMenuItem("Search Data");
        Data1.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                DataSurat1();
                label.setVisible(false);
            }
        });
        Cari = new JMenuItem("Data Surat");
        Cari.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                SearchData1();
                label.setVisible(false);
            }
        });
        New.add(Cari);
        New.add(Data1);

        fileMenu.add(New);
        fileMenu.addSeparator();//membuat garis tampilan pada menuitem

        quit = new JMenuItem("Quit");
        quit.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                int ok = JOptionPane.showConfirmDialog(null, "Apakah Anda Yakin Ingin Menutup Jendela?",
                        "Konfirmasi Tutup", JOptionPane.OK_CANCEL_OPTION);
                if (ok == JOptionPane.OK_OPTION) {
                    System.exit(0);
                }
            }
        });
        fileMenu.add(quit);

        fileMenu.setMnemonic(KeyEvent.VK_N);
        Data1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));

        fileMenu.setMnemonic(KeyEvent.VK_N);
        Cari.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, ActionEvent.CTRL_MASK));

        fileMenu.setMnemonic(KeyEvent.VK_P);
        quit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));


    }

    //method bertipe void untuk menampilkan framenya
    private void DataSurat1() {
        JIFDataSurat frameEmp = new JIFDataSurat("Data Surat Search");
        frameEmp.setVisible(true);
        this.add(frameEmp);
    }

    private void SearchData1() {
        JIFDataSuratAdd asd = new JIFDataSuratAdd("Data Surat Add");
        asd.setVisible(true);
        this.add(asd);

    }
    //method untuk membuat actionlistener tombol quit

    private void quitAction() {
        System.exit(0);
    }
}




Kelas DataSuratTableModel
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package kasusakhirsemester3;

import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author user
 */
public class DataSuratTableModel extends AbstractTableModel {
    //employee_id, last_name, email, hire_date, job_id, salary, department_id, manager_id
        String columNames[] = {"No Surat", "Perihal", "Tanggal Surat", "Tanggal Diterima",
                               "Pengirim","Penerima"};
        ArrayList data;

        public DataSuratTableModel(String keyword) throws SQLException {
            DataSurat r=new DataSurat();
            data = r.searchSurat(keyword);
        }
        public int getRowCount() {
            return data.size();
        }
        public int getColumnCount() {
            return columNames.length;
        }

        @Override
        public String getColumnName(int col) {
            return columNames[col];
        }

        public Object getValueAt(int rowIndex, int columnIndex) {
            DataSurat temp = (DataSurat) data.get(rowIndex);
            switch (columnIndex) {
                case 0:return temp.getNoSurat();
                case 1:return temp.getPerihal();
                case 2:return temp.getTanggalSurat();
                case 3:return temp.getTanggalDiterima();
                case 4:return temp.getPengirim();
                case 5:return temp.getPenerima();
        }
        return null;
    }

    @Override
    public Class getColumnClass(int c) {
        return getValueAt(0, c).getClass();
    }
}




Kelas DataSuratTableModelAdd

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package kasusakhirsemester3;

import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author user
 */
public class DataSuratTableModelAdd extends AbstractTableModel {
    //employee_id, last_name, email, hire_date, job_id, salary, department_id, manager_id
        String columNames[] = {"No Surat", "Perihal", "Tanggal Surat", "Tanggal Diterima",
                               "Pengirim","Penerima"};
        ArrayList data,data1;

        public DataSuratTableModelAdd(int noSurat, String perihal, String tanggalSurat, String tanggalDiterima, String pengirim, String penerima) throws SQLException {
            DataSurat r=new DataSurat();
            data = r.addSurat(noSurat, perihal, tanggalSurat, tanggalDiterima, pengirim, penerima); 
            data1 = r.searchSurat1();
        }
        public int getRowCount() {
            return data.size();
        }
        public int getColumnCount() {
            return columNames.length;
        }

        @Override
        public String getColumnName(int col) {
            return columNames[col];
        }

        public Object getValueAt(int rowIndex, int columnIndex) {
            DataSurat temp = (DataSurat) data.get(rowIndex);
            switch (columnIndex) {
                case 0:return temp.getNoSurat();
                case 1:return temp.getPerihal();
                case 2:return temp.getTanggalSurat();
                case 3:return temp.getTanggalDiterima();
                case 4:return temp.getPengirim();
                case 5:return temp.getPenerima();
        }
        return null;
    }

    @Override
    public Class getColumnClass(int c) {
        return getValueAt(0, c).getClass();
    }
}



Kelas JavaInternalFrameDataSurat

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package kasusakhirsemester3;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;

/**
 *
 * @author user
 */
public class JIFDataSurat extends javax.swing.JInternalFrame implements ActionListener{
static int openFrameCount = 0;
    static final int xOffset = 30, yOffset = 30;
    JPanel pa, pb, p1, p2;
    JLabel label1;
    JButton but1,but2;
    JTextField text1;
    JTable jtabel1;

    public JIFDataSurat(String title) {
        super(title + (++openFrameCount), true,true,true,true);
        setSize(800,600);
        addPanel(); //Set the window's location.
        setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
    }

    public void addPanel() {
        pa=new JPanel();
        this.setBackground(Color.cyan);
        pa.setBorder(BorderFactory.createTitledBorder(
                BorderFactory.createLineBorder(Color.pink), "Data Surat"));
        jtabel1=new JTable();
        jtabel1.setPreferredScrollableViewportSize(new Dimension(600, 200));
        JScrollPane scrollPane = new JScrollPane(jtabel1);
        pa.add(scrollPane);
        pb=new JPanel();
        pb.setLayout(new GridLayout(2,1));
        p1=new JPanel();
        p1.setLayout(new FlowLayout());
        p2=new JPanel();
        p2.setLayout(new FlowLayout());
        label1=new JLabel("Masukkan no surat yang ingin dicari : ");
        label1.setForeground(Color.red);
        p1.add(label1);
        text1=new JTextField(15);
        p1.add(text1);
        but1=new JButton("Ok");
        but1.setForeground(Color.red);
        but1.addActionListener(this);
        but2 = new JButton("Delete");
        but2.setForeground(Color.red);
        but2.addActionListener(this);
        p2.add(but1);
        p2.add(but2);
        pb.add(p1);
        pb.add(p2);
        this.setLayout(new GridLayout(2,1));
        this.add(pa);
        this.add(pb);
    }

    public void actionPerformed(ActionEvent event) {
        JButton clickedButton = (JButton) event.getSource();
        if ((clickedButton.getText()).compareTo("Ok") == 0) {
            DataSuratTableModel e;
            try {
//                System.out.println(text1.getText());
                e = new DataSuratTableModel(text1.getText());
                jtabel1.setModel(e);
                jtabel1.revalidate();
            } catch (SQLException ex) {
                Logger.getLogger(DataSuratGUI.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
       
        if ((clickedButton.getText()).compareTo("Delete") == 0) {
            RemoveTableModel e;
            try {
//                System.out.println(text1.getText());
                e = new RemoveTableModel(text1.getText());
                jtabel1.setModel(e);
                jtabel1.revalidate();
            }
                catch (SQLException ex) {
                Logger.getLogger(DataSuratGUI.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}




Kelas JavaInternalFrameDataSuratAdd


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package kasusakhirsemester3;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;

/**
 *
 * @author user
 */
public class JIFDataSurat extends javax.swing.JInternalFrame implements ActionListener{
static int openFrameCount = 0;
    static final int xOffset = 30, yOffset = 30;
    JPanel pa, pb, p1, p2;
    JLabel label1;
    JButton but1,but2;
    JTextField text1;
    JTable jtabel1;

    public JIFDataSurat(String title) {
        super(title + (++openFrameCount), true,true,true,true);
        setSize(800,600);
        addPanel(); //Set the window's location.
        setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
    }

    public void addPanel() {
        pa=new JPanel();
        this.setBackground(Color.cyan);
        pa.setBorder(BorderFactory.createTitledBorder(
                BorderFactory.createLineBorder(Color.pink), "Data Surat"));
        jtabel1=new JTable();
        jtabel1.setPreferredScrollableViewportSize(new Dimension(600, 200));
        JScrollPane scrollPane = new JScrollPane(jtabel1);
        pa.add(scrollPane);
        pb=new JPanel();
        pb.setLayout(new GridLayout(2,1));
        p1=new JPanel();
        p1.setLayout(new FlowLayout());
        p2=new JPanel();
        p2.setLayout(new FlowLayout());
        label1=new JLabel("Masukkan no surat yang ingin dicari : ");
        label1.setForeground(Color.red);
        p1.add(label1);
        text1=new JTextField(15);
        p1.add(text1);
        but1=new JButton("Ok");
        but1.setForeground(Color.red);
        but1.addActionListener(this);
        but2 = new JButton("Delete");
        but2.setForeground(Color.red);
        but2.addActionListener(this);
        p2.add(but1);
        p2.add(but2);
        pb.add(p1);
        pb.add(p2);
        this.setLayout(new GridLayout(2,1));
        this.add(pa);
        this.add(pb);
    }

    public void actionPerformed(ActionEvent event) {
        JButton clickedButton = (JButton) event.getSource();
        if ((clickedButton.getText()).compareTo("Ok") == 0) {
            DataSuratTableModel e;
            try {
//                System.out.println(text1.getText());
                e = new DataSuratTableModel(text1.getText());
                jtabel1.setModel(e);
                jtabel1.revalidate();
            } catch (SQLException ex) {
                Logger.getLogger(DataSuratGUI.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
       
        if ((clickedButton.getText()).compareTo("Delete") == 0) {
            RemoveTableModel e;
            try {
//                System.out.println(text1.getText());
                e = new RemoveTableModel(text1.getText());
                jtabel1.setModel(e);
                jtabel1.revalidate();
            }
                catch (SQLException ex) {
                Logger.getLogger(DataSuratGUI.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}



Kelas MainFrame


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package kasusakhirsemester3;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.KeyStroke;

public class MainFrame extends JFrame {
    private JMenuBar menu ;
    private JMenu file ;
    private JMenu New ;
    private JMenuItem masukkanData ;
    private masukkanData md ;
    private JMenuItem quit ;

    public MainFrame(){
        this.setLocation(100, 100);
        this.setSize(500, 300);
        this.setTitle("Tugas Akhir Semester 3");

        menu = new JMenuBar();
        this.setJMenuBar(menu);

        file = new JMenu("File");
        file.setMnemonic('F');
        New = new JMenu("New");
        New.setMnemonic('N');
        menu.add(file);
       
        masukkanData = new JMenuItem("Masukkan Data");
        masukkanData.setMnemonic('M');
        quit = new JMenuItem("Quit");
        quit.setMnemonic('Q');
        New.add(masukkanData);
        file.add(New);
        file.addSeparator();
        file.add(quit);

        file.setMnemonic(KeyEvent.VK_P);
        masukkanData.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));

        masukkanData.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                md = new masukkanData();
                add(md);
                md.setVisible(true);
            }
        });

        quit.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                int ok = JOptionPane.showConfirmDialog(null, "Apakah Anda Yakin Ingin Menutup Jendela?",
                "Konfirmasi Tutup", JOptionPane.OK_CANCEL_OPTION);
                    if(ok == JOptionPane.OK_OPTION){
                    System.exit(0);
                    }
            }
        });
    }

    public static void main(String[]args){
        MainFrame mf = new MainFrame();
        mf.setVisible(true);
        mf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        System.out.println(System.getProperty("user.dir"));
    }

}




Kelas RemoveTableModel


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package kasusakhirsemester3;

import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

public class RemoveTableModel extends AbstractTableModel {

    String columNames[] = {"No Surat", "Perihal", "Tanggal Surat", "Tanggal Penerimaan", "Pengirim", "Penerima"};
    ArrayList data2;

    public RemoveTableModel(String keyword) throws SQLException {
        DataSurat r = new DataSurat();
        data2 = r.removeSurat(keyword);
    }

    public int getRowCount() {
        return data2.size();
    }

    public int getColumnCount() {
        return columNames.length;
    }

    @Override
    public String getColumnName(int col) {
        return columNames[col];
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        DataSurat temp = (DataSurat) data2.get(rowIndex);
        switch (columnIndex) {
            case 0:
                return temp.getNoSurat();
            case 1:
                return temp.getPerihal();
            case 2:
                return temp.getTanggalSurat();
            case 3:
                return temp.getTanggalDiterima();
            case 4:
                return temp.getPengirim();
            case 5:
                return temp.getPenerima();

        }
        return null;
    }

    @Override
    public Class getColumnClass(int c) {
        return getValueAt(0, c).getClass();
    }
}




Kelas MasukkanData


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package kasusakhirsemester3;

import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
//import kasusakhirsemester3.dataSurat;

/**
 *
 * @author DELL                                                                
 */
public class masukkanData extends JInternalFrame implements ActionListener {
    private JTextField dataEntry1 ;
    private JTextField dataEntry2 ;
    private JTextField dataEntry3 ;
    private JTextField dataEntry4 ;
    private JTextField dataEntry5 ;
    private JTextField dataEntry6 ;
    private JButton ok ;
    private JButton quit ;
    private JButton bersihkan ;

    JPanel panel = new JPanel();
    JLabel nomorSurat = new JLabel("Nomor Surat:");
    JLabel perihal = new JLabel("Perihal:");
    JLabel tglKirim = new JLabel("Tanggal Pengiriman:");
    JLabel tglTerima = new JLabel("Tanggal Penerimaan:");
    JLabel pengirim = new JLabel("Pengirim:");
    JLabel penerima = new JLabel("Penerima:");

    public masukkanData(){
         this.setLocation(100, 100);
         this.setSize(500, 300);

         setContentPane(panel);
         Container contentPane;

         contentPane = getContentPane();
         contentPane.setLayout(new GridLayout(1, 1));

         Color buttons_color = new Color(242,244,241);
         Color background_color = new Color(241,237,222);

         final JPanel dataEntry, panel1, panel2 ;

         dataEntry = new JPanel(new GridLayout(2, 1));
         dataEntry.setBorder(BorderFactory.createTitledBorder("Masukkan Data"));

         panel1 = new JPanel(new GridLayout(6, 2));
         panel1.add(nomorSurat);
         nomorSurat.setForeground(Color.BLUE);
         panel1.add(dataEntry6 = new JTextField(5));
         panel1.add(perihal);
         perihal.setForeground(Color.BLUE);
         panel1.add(dataEntry5 = new JTextField(5));
         panel1.add(tglKirim);
         tglKirim.setForeground(Color.BLUE);
         panel1.add(dataEntry4 = new JTextField(5));
         panel1.add(tglTerima);
         tglTerima.setForeground(Color.BLUE);
         panel1.add(dataEntry3 = new JTextField(5));
         panel1.add(pengirim);
         pengirim.setForeground(Color.BLUE);
         panel1.add(dataEntry2 = new JTextField(5));
         panel1.add(penerima);
         penerima.setForeground(Color.BLUE);
         panel1.add(dataEntry1 = new JTextField(5));

         dataEntry.add(panel1);

         panel2 = new JPanel(new FlowLayout());
         ok = new JButton("OK");
         ok.setForeground(Color.red);
         panel2.add(ok);
         quit = new JButton("Quit");
         quit.setForeground(Color.red);
         panel2.add(quit);
         bersihkan = new JButton("Bersihkan");
         bersihkan.setForeground(Color.red);
         panel2.add(bersihkan);

         dataEntry.add(panel2);

         contentPane.add(dataEntry);

         ok.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
                if (dataEntry6.getText().equals("")) {
                    JOptionPane.showMessageDialog(null, "Isikan Data Terlebih dahulu", "Dialog Peringatan", JOptionPane.INFORMATION_MESSAGE);

                    ok.setEnabled(true);
                    bersihkan.setEnabled(true);
                } else if (dataEntry5.getText().equals("")) {
                    JOptionPane.showMessageDialog(null, "Data Belum Lengkap", "Dialog Peringatan", JOptionPane.INFORMATION_MESSAGE);

                    ok.setEnabled(true);
                    bersihkan.setEnabled(true);
                } else if (dataEntry4.getText().equals("")) {
                    JOptionPane.showMessageDialog(null, "Data Belum Lengkap", "Dialog Peringatan", JOptionPane.INFORMATION_MESSAGE);

                    ok.setEnabled(true);
                    bersihkan.setEnabled(true);
                } else if (dataEntry3.getText().equals("")) {
                    JOptionPane.showMessageDialog(null, "Data Belum Lengkap", "Dialog Peringatan", JOptionPane.INFORMATION_MESSAGE);

                    ok.setEnabled(true);
                    bersihkan.setEnabled(true);
                } else if (dataEntry2.getText().equals("")) {
                    JOptionPane.showMessageDialog(null, "2 Data Belum Terisi", "Dialog Peringatan", JOptionPane.INFORMATION_MESSAGE);

                    ok.setEnabled(true);
                    bersihkan.setEnabled(true);
                } else if (dataEntry1.getText().equals("")) {
                    JOptionPane.showMessageDialog(null, "1 Data Belum Terisi", "Dialog Peringatan", JOptionPane.INFORMATION_MESSAGE);

                    ok.setEnabled(true);
                    bersihkan.setEnabled(true);
                } else if (e.getSource() == ok) {
                int okay = JOptionPane.showConfirmDialog(null, "Terima Kasih",
                        "Konfirmasi Tutup", JOptionPane.OK_CANCEL_OPTION);
                if (okay == JOptionPane.OK_OPTION) {

                    DateFormat dfm = new SimpleDateFormat("yyyy-MM-dd");
                    dfm.setTimeZone(TimeZone.getTimeZone("GMT+7:00"));

                    //Akan Mengeset Tanggal Tertentu
                    Date b=new Date();
                    dfm = new SimpleDateFormat("yyyy-MM-dd / HH:mm:ss");


                }
                }
           }
         });

         quit.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
                int ok = JOptionPane.showConfirmDialog(null, "Apakah Anda Yakin Ingin Menutup Jendela?",
                        "Konfirmasi Tutup", JOptionPane.OK_CANCEL_OPTION);
                if (ok == JOptionPane.OK_OPTION) {
                    System.exit(0);
                }
            }
        });

        bersihkan.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
                dataEntry1.setText("");
                dataEntry2.setText("");
                dataEntry3.setText("");
                dataEntry4.setText("");
                dataEntry5.setText("");
                dataEntry6.setText("");
            }
        });

        this.setVisible(true);

    }

    public void actionPerformed(ActionEvent event) {
//      
       
    }

}

0 komentar:

Posting Komentar