Rabu, 21 Desember 2011

Thread_Kelas ThreadGraphic

package Graphics;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class ThreadGraphic extends JPanel implements Runnable{

//    Counter counter ;
    int counter=5;
    Thread thread;
    private boolean start=true;
    private int value;

    public ThreadGraphic() {
//        counter= new Counter();
        setBackground(Color.white);
        thread = new Thread(this);
        thread.start();
    }

    public void paintComponent(Graphics g) {
        super.paintComponent(g);

        if (counter % 2 == 0) {
            g.setColor(Color.magenta);           
            g.fillOval(100, 50, 100, 100);
            counter-=1;
        }else{
            g.setColor(Color.black);
            g.fillOval(100, 50, 100, 100);
            counter+=1;
        }
    }

    public void run() {
        while(true){
//            outputLabel.setText("Counter: "+getValue());
            try {
                thread.sleep(200);
                this.repaint();
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
        }
    }

    private boolean isStart() {
        return start;
    }

    private int getValue() {
        return value;
    }

    private void setValue(int i) {
        this.value=value;
    }

    public static void main(String args[]){
        JFrame frame = new JFrame( "Grafik 2 Dimensi" );
        frame.addWindowListener( new WindowAdapter(){
            public void windowClosing( WindowEvent e ){
                System.exit( 0 );
            }
        });

        frame.setLayout(new BorderLayout());
        ThreadGraphic graph = new ThreadGraphic();
        frame.add(graph,BorderLayout.CENTER);

        frame.setSize( 450, 250 );
        frame.setVisible(true);

        AnotherCounter counter = new AnotherCounter();
       
    }
}

Thread_Kelas SimpleThread

package Graphics;

/* SimpleThread.java */
public class SimpleThread extends Thread {
    public SimpleThread(String str) {
        super(str);
    }
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println(i + " " + getName());
            try {
                sleep((long)(Math.random() * 1000));
            } catch (InterruptedException e) {}
        }
        System.out.println("DONE! " + getName());
    }
}

/* TwoThreadsTest.java */

Thread_Kelas ShapePanel

package Graphics;

import java.awt.*;
import java.awt.event.*;
import java.awt.font.*;
import java.awt.geom.*;
import javax.swing.*;


public class ShapePanel extends JPanel {

    public ShapePanel(){


        setBackground(Color.white);
    }

    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setColor(Color.BLUE);
        g.drawLine(0,10,50,60);

        g.setColor(Color.red);
        g.drawRect(50,10,50,50);

        g.setColor(new Color(255,0,0));
        g.fillOval(100,10,50,50);

        g.setColor(new Color(0,255,0));
        g.fillArc(150,10,50,50,0,180);

        Graphics2D g2 =(Graphics2D)g;
        // fill RoundRectangle2D.Double
        GradientPaint redtowhite = new GradientPaint(200,10,Color.red,250, 10,Color.black);
        g2.setPaint(redtowhite);
        g2.fill(new RoundRectangle2D.Double(200, 10, 50,50, 10, 10));
        //g2.setPaint();
        g2.drawString("Filled RoundRectangle2D", 200, 80);

    }

    public static void main(String args[]){
        JFrame frame = new JFrame( "Grafik 2 Dimensi" );
        frame.addWindowListener( new WindowAdapter(){
            public void windowClosing( WindowEvent e ){
                System.exit( 0 );
            }
        });

        frame.setLayout(new BorderLayout());
        ShapePanel shapePanel = new ShapePanel();
        frame.add(shapePanel,BorderLayout.CENTER);

        frame.setSize( 450, 250 );
        frame.setVisible(true);
    }
}

Thread_Kelas RandomCounter

package Graphics;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;


public class RandomCounter implements Runnable {

    JTextField outputLabel;
    private int value;
    Thread thread;
    private boolean start = true;

    /** Creates a new instance of Counter */
    public RandomCounter() {
        setValue(0);
    }

    /** Creates a new instance of Counter */
    public RandomCounter(JTextField output) {
        outputLabel = output;
        setValue(0);
        thread = new Thread(this);
        thread.start();
    }

    public void run() {
        while(isStart()){
            outputLabel.setText("Counter: "+getValue());
            try {
               
                thread.sleep(200);
                setValue(getValue()+(int)(Math.random()*1000));
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
        }
    }

    public boolean isStart() {
        return start;
    }

    public void setStart(boolean start) {
        this.start = start;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;

    }
}


class SimpleGUI extends JFrame{
    private JButton clickButton,stopButton;
    private JTextField counterLabel;
    private RandomCounter counter;

    /** Creates a new instance of SimpleGUI */
    public SimpleGUI() {
        clickButton = new JButton("Start");
        stopButton = new JButton("Stop");

        counterLabel = new JTextField("Counter: ",20);

        this.setLayout(new FlowLayout());
        this.add(clickButton);
        this.add(stopButton);
        this.add(counterLabel);
       

        this.setTitle("Random Counter");
        this.setSize(300,200);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        clickButton.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                clickAction();
            }
        });

        stopButton.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                stopAction();
            }
        });
    }

    public void clickAction(){
        counter = new RandomCounter(counterLabel);
    }

    public void stopAction(){
        counter.setStart(false);
    }
}

class SimpleGUITester {

    /** Creates a new instance of SimpleGUITester */
    public SimpleGUITester() {
    }

    public static void main(String[] args) {
        SimpleGUI test = new SimpleGUI();
    }
}

Thread_Kelas ImagePanel

package Graphics;

import java.awt.*;
import java.awt.image.*;
import java.io.*;
import javax.imageio.*;
import javax.imageio.stream.*;
import javax.swing.*;


public class ImagePanel extends JPanel{
    private BufferedImage logo;
    /** Creates a new instance of ImagePanel */
    public ImagePanel() {
        try {
            // buka file. Cari file gambar lain di computer anda
            File img = new File("C:\\Documents and Settings\\All Users\\Documents\\My Pictures\\Sample Pictures\\winter.jpg");
            // baca image
            logo = ImageIO.read(img);
            //img.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    public void paintComponent(Graphics g) {
        g.drawImage(logo,
                0, 0, 400, 300,
                0, 0, logo.getWidth(null), logo.getHeight(null),
                null);

    }

    public static void main(String args[]){
        JFrame frame = new JFrame("Using Java2D");
        frame.setLayout(new BorderLayout());
       
        ImagePanel gc = new ImagePanel();

        frame.add(gc,BorderLayout.CENTER);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(600,250);
        frame.setVisible(true);
    }
}

Thread_Kelas Counter

package Graphics;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;


public class Counter implements Runnable{
    JLabel outputLabel;
    private int value;
    Thread thread;
    private boolean start = true;

    /** Creates a new instance of Counter */
    public Counter() {
        setValue(0);
    }

    /** Creates a new instance of Counter */
    public Counter(JLabel output) {
        outputLabel = output;
        setValue(0);
        thread = new Thread(this);
        thread.start();
    }

    public void run() {
        while(isStart()){
            outputLabel.setText("Counter: "+getValue());
            try {
                thread.sleep(200);
                setValue(getValue() + 1);
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
        }
    }

    public boolean isStart() {
        return start;
    }

    public void setStart(boolean start) {
        this.start = start;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

}

class SimpleGUI extends JFrame{
    private JButton clickButton,stopButton;
    private JLabel counterLabel;
    private Counter counter;

    /** Creates a new instance of SimpleGUI */
    public SimpleGUI() {
        clickButton = new JButton("Start");
        stopButton = new JButton("Stop");

        counterLabel = new JLabel("Counter: ");

        this.setLayout(new FlowLayout());
        this.add(clickButton);
        this.add(counterLabel);
        this.add(stopButton);

        this.setTitle("Thread application");
        this.setSize(300,200);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        clickButton.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                clickAction();
            }
        });

        stopButton.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                stopAction();
            }
        });
    }

    public void clickAction(){
        counter = new Counter(counterLabel);
    }

    public void stopAction(){
        counter.setStart(false);
    }
}

class SimpleGUITester {

    /** Creates a new instance of SimpleGUITester */
    public SimpleGUITester() {
    }

    public static void main(String[] args) {
        SimpleGUI test = new SimpleGUI();
    }
}

Thread_Kelas AnotherSimpleCounter

package Graphics;
/* AnotherSimpleThread.java */

public class AnotherSimpleThread implements Runnable{
    Thread thread;
    /** Creates a new instance of AnotherSimpleThread */
    public AnotherSimpleThread() {
    }

    public AnotherSimpleThread(String name) {
        thread = new Thread(this,name);
        thread.start();
    }

    public void run(){
        for (int i = 0; i < 10; i++) {
            System.out.println(i + " " + thread.getName());
            try {
                thread.sleep((long)(Math.random() * 1000));
            } catch (InterruptedException e) {}
        }
        System.out.println("DONE! " + thread.getName());
    }
}

/* AnotherTwoThreadsTest.java */

Thread_Kelas AnotherCounter

package Graphics;

public class AnotherCounter implements Runnable {

    Thread thread;
    private boolean start=true;
    private int value;

    public AnotherCounter(){
        setValue(0);
        thread = new Thread(this);
        thread.start();
    }

    public void run() {
        while(isStart()){
            System.out.println(getValue());
            try {   
                thread.sleep(200);
                setValue(getValue() + 1);
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
        }
    }

    private boolean isStart() {
        return start;
    }

    private void setValue(int value) {
        this.value=value;
    }

    private int getValue() {
        return value;
    }
    public static void main(String[] args) {
        AnotherCounter c= new AnotherCounter();
    }

}

JDBC_Kelas RegionTableModel

package JDBC;

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


public class RegionsTableModel extends AbstractTableModel {

    String columNames[] = {"Nomor", "Regions"};
    ArrayList data;

    public RegionsTableModel(String keyword) throws SQLException {
        data = Regions.searchRegions(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) {
        Regions temp = (Regions) data.get(rowIndex);
        if (columnIndex == 0) {
            return temp.getRegionId();
        } else {
            return temp.getRegionName();
        }
    }

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

    public static void main(String[] args) throws SQLException {
        RegionsTableModel test = new RegionsTableModel("Asia");
        System.out.println("nama :" + test.getValueAt(0, 1));
    }

}

JDBC_Kelas Region

package JDBC;

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

public class Regions {

    private Integer regionId;
    private String regionName;

    public Regions() {
    }

    public Regions(Integer regionId, String regionName) {
        this.regionId = regionId;
        this.regionName = regionName;
    }

    public static boolean isRegionExist(Integer regionID) throws SQLException {
        boolean result = false;

        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 regions where region_id = " + regionID;

        ResultSet rset = stmt.executeQuery(query);

        rset.next();
        if (rset.isLast()) {
            result = true;
        } else {
            result = false;
        }

        conn.close();
        return result;
    }

    /**
     * @return the regionId
     */
    public Integer getRegionId() {
        return regionId;
    }

    /**
     * @param regionId the regionId to set
     */
    public void setRegionId(Integer regionId) {
        this.regionId = regionId;
    }

    public static  ResultSet getAllRegion() throws SQLException{
        DataHandler dataHandler = new DataHandler();
        dataHandler.getDBConnection();
        Connection conn = dataHandler.conn;
        Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
//        query = "SELECT * FROM Employees ORDER BY employee_id";
        String query = "SELECT * FROM Regions ORDER BY region_id";
        System.out.println("\nExecuting query: " + query);
        ResultSet rset = stmt.executeQuery(query);
        return rset;
    }

    public static void addRegion(Regions region) throws SQLException{
        DataHandler dataHandler = new DataHandler();
        dataHandler.getDBConnection();
        Connection conn = dataHandler.conn;
        Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
//        query = "SELECT * FROM Employees ORDER BY employee_id";
        String query = "INSERT INTO Regions (region_id, region_name) VALUES ("+region.getRegionId()+",'"+region.getRegionName()+"'";
//        System.out.println("\nExecuting query: " + query);
//        stmt.executeUpdate(query);
        stmt.executeUpdate(query);
//        return rset;

        conn.close();
    }

    public static ArrayList searchRegions(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 regions where region_name like '%" + keyword + "%'";

        ResultSet rset = stmt.executeQuery(query);
        result = new ArrayList();
        while (rset.next()) {
          Regions temp = new Regions(rset.getInt(1),rset.getString(2));
            result.add(temp);
        }
        conn.close();
        return result;
    }


    /**
     * @return the regionName
     */
    public String getRegionName() {
        return regionName;
    }

    /**
     * @param regionName the regionName to set
     */
    public void setRegionName(String regionName) {
        this.regionName = regionName;
    }

    public static void main(String[] args) throws SQLException {
        System.out.println("isRegionExist " + Regions.isRegionExist(1));
        Regions.addRegion(new Regions(6, "Kalimantan"));
        ResultSet rset = Regions.getAllRegion();
        while (rset.next()) {
//            System.out.println(rset.getInt(1) + " " + rset.getString(2) + " " + rset.getString(3) + " " + rset.getString(4));
            System.out.println(rset.getString(1)+" "+rset.getString(2));
        }
        System.out.println("");
        ArrayList test=Regions.searchRegions("J");
        for (int i = 0; i < test.size(); i++) {
            Regions temp = (Regions) test.get(i);
            System.out.println(temp.regionName);

        }

    }

}

JDBC_Kelas DataHandler

package JDBC;

import java.sql.Statement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import oracle.jdbc.pool.OracleDataSource;


public class DataHandler {

    String jdbcUrl = "jdbc:oracle:thin:@172.23.9.185:1521:orcl";
    String userid = "mhs105314098";
    String password = "mhs105314098";

    Connection conn;
    Statement stmt;
    ResultSet rset;
    String query;
    String sqlString;

    public DataHandler() {
    }

    public void getDBConnection() throws SQLException {
        OracleDataSource ds;
        ds = new OracleDataSource();
        ds.setURL(jdbcUrl);
        conn = ds.getConnection(userid, password);
    }

    public ResultSet getAllEmployees() throws SQLException {
        getDBConnection();
        stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
//        query = "SELECT * FROM Employees ORDER BY employee_id";
        query = "SELECT first_name FROM Employees ORDER BY employee_id";
        System.out.println("\nExecuting query: " + query);
        rset = stmt.executeQuery(query);
        return rset;
    }


    public static void main(String[] args) throws SQLException {
        DataHandler datahandler = new DataHandler();
        ResultSet rset = datahandler.getAllEmployees();
        while (rset.next()) {
//            System.out.println(rset.getInt(1) + " " + rset.getString(2) + " " + rset.getString(3) + " " + rset.getString(4));
            System.out.println(rset.getString(1));
        }
        datahandler.conn.close();
    }
}

JDBC_Kelas SearchPanel

package JDBC;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.sql.SQLException;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

public class SearchPanel extends JPanel{

    public SearchPanel(String keyWord) throws SQLException {
        super(new GridLayout(1,0));

        JTable table = new JTable(new RegionsTableModel(keyWord));
        table.setPreferredScrollableViewportSize(new Dimension(500, 70));

        //Create the scroll pane and add the table to it.
        JScrollPane scrollPane = new JScrollPane(table);

        //Add the scroll pane to this panel.
        add(scrollPane);
    }

    public static void main(String args[]) throws SQLException{
        JDialog dialog= new JDialog( new JFrame(),true );
        dialog.addWindowListener( new WindowAdapter(){
            @Override
            public void windowClosing( WindowEvent e ){
                System.exit( 0 );
            }
        });

        SearchPanel searchPanel = new SearchPanel("Asia");
        dialog.add(searchPanel);

        dialog.setSize( 450, 250 );
        dialog.setVisible(true);
    }

}

Stream_Kelas MainDocument

package stream;

import java.io.IOException;

public class testDocument {

    public static void main(String[] args) throws IOException {
        Document test = new Document("test.txt");
        test.setTeks("Hallo Dunia");
        test.Simpan();

        Document testbaca = new Document("test.txt");
        testbaca.Baca();
        System.out.println(testbaca.getTeks());
    }
}

Stream_Kelas WriteDataDemo

package stream;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class WriteDataDemo {

    /** Creates a new instance of WriteDataDemo */
    public WriteDataDemo() {
    }

    public static void main(String[] args) throws IOException {
        // write the data out with FileOutputStream
        // buat file
        File outputFile = new File("latihan.txt");
        // buka stream
        FileOutputStream out = new FileOutputStream(outputFile);

        String NIM = "105314007";
        String Nama = "James";
        String IdKoleksi = "001";
        String Judul = "laskar Pelangi";

         // sediakan data string
        String txt = NIM + "\t" + Nama + "\n" + IdKoleksi + "\t" + Judul + "\n";
        // menulis data ke stream
        out.write(txt.getBytes());

        System.out.println(outputFile.getAbsolutePath());
        System.out.println(outputFile.isDirectory());
        System.out.println(outputFile.isFile());
   
        out.close();
    }
}

Stream_Kelas ReadDataDemo

package stream;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;


public class ReadDataDemo {
/** Creates a new instance of ReadDataDemo */
    public ReadDataDemo() {
    }
     public static void main(String[] args) {
        // write the data out with FileOutputStream
        // buat file
        File inputFile = new File("latihan.txt");
        try{
        // buka stream
        FileInputStream in = new FileInputStream(inputFile);


        // buat buffer pembacaan data
        String testInput = new String();
        // variabel integer untuk membaca data dari file yang dibuka
        int c;
        // cek akhir dari file apakah bernilai -1
        while((c=in.read())!=-1){
            // tambahkan data pembacaan ke buffer
            testInput += (char)c;
        }
        // tutup stream
        in.close();
        System.out.println(testInput);
        } catch (IOException ex){
            System.out.println(ex.getMessage());
        }
    }

}

Stream_Kelas Document

package stream;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class Document {

    private File file;
    private String teks="";

    public Document() {
    }

    public Document(File File) {
        setFile(file);
    }

    public Document(String FileName) {
        File tempFile = new File(FileName);
        setFile(tempFile);
    }

    public void Baca( ) throws IOException {
      FileInputStream  stream = new FileInputStream(getFile());
        int result;
        while ((result = stream.read()) != -1) {
            setTeks(getTeks() + (char) result);
        }
        stream.close();

    }

    public void Simpan() throws IOException {
        FileOutputStream stream = new FileOutputStream(getFile());
        stream.write(getTeks().getBytes());
        stream.close();

    }

    /**
     * @return the file
     */
    public File getFile() {
        return file;
    }

    /**
     * @param file the file to set
     */
    public void setFile(File file) {
        this.file = file;
    }

    /**
     * @return the teks
     */
    public String getTeks() {
        return teks;
    }

    /**
     * @param teks the teks to set
     */
    public void setTeks(String teks) {
        this.teks = teks;
    }
}

Proyek PBO_Kelas Main

package uts_pbo_2;

public class UTS2 {


    public static void main(String[] args) {
        KotakMasuk km = new KotakMasuk();
        km.setVisible(true);
    }
}

Proyek PBO_Kelas Surat

package uts_pbo_2;

public class Surat {
    private String noSurat;
    private String perihal;
    private String TglSurat;
    private String TglTerima;
    private String pengirim;
    private String penerima;
    private String search;

    public Surat(){

    }

    public Surat(String noSurat, String perihal, String TglSurat, String TglTerima, String pengirim, String penerima) {
        this.noSurat = noSurat;
        this.perihal = perihal;
        this.TglSurat = TglSurat;
        this.TglTerima = TglTerima;
        this.pengirim = pengirim;
        this.penerima = penerima;
    }


    /**
     * @return the noSurat
     */
    public String getNoSurat() {
        return noSurat;
    }

    /**
     * @param noSurat the noSurat to set
     */
    public void setNoSurat(String noSurat) {
        this.noSurat = noSurat;
    }

    /**
     * @return the perihal
     */
    public String getPerihal() {
        return perihal;
    }

    /**
     * @param perihal the perihal to set
     */
    public void setPerihal(String perihal) {
        this.perihal = perihal;
    }

    /**
     * @return the TglSurat
     */
    public String getTglSurat() {
        return TglSurat;
    }

    /**
     * @param TglSurat the TglSurat to set
     */
    public void setTglSurat(String TglSurat) {
        this.TglSurat = TglSurat;
    }

    /**
     * @return the TglTerima
     */
    public String getTglTerima() {
        return TglTerima;
    }

    /**
     * @param TglTerima the TglTerima to set
     */
    public void setTglTerima(String TglTerima) {
        this.TglTerima = TglTerima;
    }

    /**
     * @return the pengirim
     */
    public String getPengirim() {
        return pengirim;
    }

    /**
     * @param pengirim the pengirim to set
     */
    public void setPengirim(String pengirim) {
        this.pengirim = pengirim;
    }

    /**
     * @return the penerima
     */
    public String getPenerima() {
        return penerima;
    }

    /**
     * @param penerima the penerima to set
     */
    public void setPenerima(String penerima) {
        this.penerima = penerima;
    }

    /**
     * @return the search
     */
    public String getSearch() {
        return search;
    }

    /**
     * @param search the search to set
     */
    public void setSearch(String search) {
        this.search = search;
    }
}

Proyek PBO_Kelas Read

package uts_pbo_2;

import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.SQLException;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;

public class Read extends JFrame {

    Scanner input = new Scanner(System.in);
    JCheckBox cbox[];
    DataHandler data;
    private JRadioButton[] radioButton;
    JButton ok;
    ButtonGroup bg;
    String[] btnText = {"No Surat", "Perihal", "Penerima", "Pengirim", "Tanggal Kirim", "Tanggal Terima"};
    JPanel cpanel, opanel;
    String word = null;
    Surat key;

    Read() {
    }

    public Read(Frame owner) {
        Container content = getContentPane();
        setTitle("Read Mail");
        setSize(300, 300);
        setLocation(300, 300);
        content.setLayout(new BorderLayout());

        cpanel = new JPanel(new GridLayout(0, 1));
        cpanel.setBorder(BorderFactory.createTitledBorder("Cari Berdasarkan: "));

        bg = new ButtonGroup();
        radioButton = new JRadioButton[btnText.length];

        for (int i = 0; i < radioButton.length; i++) {
            radioButton[i] = new JRadioButton(btnText[i]);
//            radioButton[i].addItemListener(this);
            bg.add(radioButton[i]);
            cpanel.add(radioButton[i]);
        }
        ok = new JButton("OK");
        opanel = new JPanel();
        opanel.add(ok);

        content.add(cpanel, BorderLayout.CENTER);
        content.add(opanel, BorderLayout.SOUTH);

        ok.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                if (radioButton[0].isSelected()) {
                    data = new DataHandler();
                    try {

                        Surat surat = new Surat();
                        word = JOptionPane.showInputDialog("Masukkan Keyword: ");
                        surat.setSearch(word);
                        ArrayList test = data.searchNo(surat.getSearch());
                        for (int i = 0; i < test.size(); i++) {
                            DataHandler temp = (DataHandler) test.get(i);
                            JOptionPane.showMessageDialog(rootPane, temp.getNo());
                        }
                    } catch (SQLException ex) {
                        Logger.getLogger(KotakMasuk.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } else if (radioButton[1].isSelected()) {
                    data = new DataHandler();
                    try {

                        Surat surat = new Surat();
                        word = JOptionPane.showInputDialog("Masukkan Keyword: ");
                        surat.setSearch(word);
                        ArrayList test = data.searchHal(surat.getSearch());
                        for (int i = 0; i < test.size(); i++) {
                            DataHandler temp = (DataHandler) test.get(i);
                            JOptionPane.showMessageDialog(rootPane, temp.getHal());
                        }
                    } catch (SQLException ex) {
                        Logger.getLogger(KotakMasuk.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } else if (radioButton[2].isSelected()) {
                    data = new DataHandler();
                    try {

                        Surat surat = new Surat();
                        word = JOptionPane.showInputDialog("Masukkan Keyword: ");
                        surat.setSearch(word);
                        ArrayList test = data.searchPenerima(surat.getSearch());
                        for (int i = 0; i < test.size(); i++) {
                            DataHandler temp = (DataHandler) test.get(i);
                            JOptionPane.showMessageDialog(rootPane, temp.getPnrm());
                        }
                    } catch (SQLException ex) {
                        Logger.getLogger(KotakMasuk.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } else if (radioButton[3].isSelected()) {
                    data = new DataHandler();
                    try {

                        Surat surat = new Surat();
                        word = JOptionPane.showInputDialog("Masukkan Keyword: ");
                        surat.setSearch(word);
                        ArrayList test = data.searchPengirim(surat.getSearch());
                        for (int i = 0; i < test.size(); i++) {
                            DataHandler temp = (DataHandler) test.get(i);
                            JOptionPane.showMessageDialog(rootPane, temp.getPkrm());
                        }
                    } catch (SQLException ex) {
                        Logger.getLogger(KotakMasuk.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } else if (radioButton[4].isSelected()) {
                    data = new DataHandler();
                    try {

                        Surat surat = new Surat();
                        word = JOptionPane.showInputDialog("Masukkan Keyword: ");
                        surat.setSearch(word);
                        ArrayList test = data.searchTglSurat(surat.getSearch());
                        for (int i = 0; i < test.size(); i++) {
                            DataHandler temp = (DataHandler) test.get(i);
                            JOptionPane.showMessageDialog(rootPane, temp.getTglSurat());
                        }
                    } catch (SQLException ex) {
                        Logger.getLogger(KotakMasuk.class.getName()).log(Level.SEVERE, null, ex);
                    }
                } else{
                    data = new DataHandler();
                    try {

                        Surat surat = new Surat();
                        word = JOptionPane.showInputDialog("Masukkan Keyword: ");
                        surat.setSearch(word);
                        ArrayList test = data.searchNo(surat.getSearch());
                        for (int i = 0; i < test.size(); i++) {
                            DataHandler temp = (DataHandler) test.get(i);
                            JOptionPane.showMessageDialog(rootPane, temp.getTglTerima());
                        }
                    } catch (SQLException ex) {
                        Logger.getLogger(KotakMasuk.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            }
        });
    }
}

Proyek PBO_Kelas MailTable

package uts_pbo_2;

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

public class MailTable extends AbstractTableModel{

    String columNames[] = {"No Surat", "Perihal", "Penerima", "Pengirim",
    "Tanggal Kirim", "Tanggal Terima"};
    ArrayList data;

    public MailTable(String keyword) throws SQLException {
        data = DataHandler.searchNo(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) {
        DataHandler temp = (DataHandler) data.get(rowIndex);
        if (columnIndex == 0) {
            return temp.getNo();
        } else if (columnIndex == 1){
            return temp.getHal();
        } else if (columnIndex == 2){
            return temp.getPnrm();
        }else if (columnIndex == 3){
            return temp.getPkrm();
        }else if (columnIndex == 4){
            return temp.getTglSurat();
        }else {
            return temp.getTglTerima();
        }
    }

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

}

Proyek PBO_Kelas KotakMasuk

package uts_pbo_2;

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

public class KotakMasuk extends JFrame {

    JMenu menuFile, menuHelp;
    JMenuItem itemPengirim, exit, baca, semua;
    JMenuBar bar;
    DataSuratMasuk surat;
    Read read;
    ImageIcon img;
    JLabel label;

    public KotakMasuk() {
        Container content = getContentPane();
        setSize(400, 300);
        setLocation(300, 300);
        setTitle("Kotak Masuk");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        img = new ImageIcon("Koala.jpg");
        label = new JLabel(img);
        content.add(label);

        menuFile = new JMenu("File");
        menuHelp = new JMenu("Help");
        bar = new JMenuBar();
        itemPengirim = new JMenuItem("New Mail");
        baca = new JMenuItem("Read Mail");
        semua = new JMenuItem("Mail Table");
        exit = new JMenuItem("Exit");

        setJMenuBar(bar);
        bar.add(menuFile);
        bar.add(menuHelp);

        menuFile.add(baca);
        menuFile.add(itemPengirim);
        menuFile.add(semua);
        menuFile.addSeparator();
        menuFile.add(exit);

        baca.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                DataHandler data = new DataHandler();
                read = new Read(new KotakMasuk());
                read.setVisible(true);
            }
        });

        itemPengirim.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                surat = new DataSuratMasuk(new KotakMasuk());
                surat.setVisible(true);
            }
        });

        semua.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                try {
                    JDialog dialog = new JDialog(new JFrame(), true);
                    AllTable searchPanel = new AllTable("");
                    dialog.add(searchPanel);
                    dialog.setSize(600, 300);
                    dialog.setVisible(true);
                } catch (SQLException ex) {
                    Logger.getLogger(KotakMasuk.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });

        exit.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                System.exit(0);
            }
        });
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

}

Proyek PBO_Kelas

package uts_pbo_2;

import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class DataSuratMasuk extends JDialog {

    JLabel labelNo, labelHal, labelTglSurat, labelTglTerima, labelPengirim, labelPenerima;
    JTextField fieldNo, fieldHal, fieldTglSurat, fieldTglTerima, fieldPengirim, fieldPenerima;
    JButton btnOK;

    public DataSuratMasuk(Frame owner) {
        super(owner);
        setTitle("Data Surat Masuk");
        setSize(500, 250);
        setLocation(300, 300);
        setResizable(false);
        setLayout(new FlowLayout());


        labelNo = new JLabel("No");
        labelHal = new JLabel("Perihal");
        labelTglSurat = new JLabel("Tanggal Surat (DD-MMM-YY)");
        labelTglTerima = new JLabel("Tanggal Terima (DD-MMM-YY)");
        labelPengirim = new JLabel("Pengirim");
        labelPenerima = new JLabel("Penerima");

        fieldNo = new JTextField(20);
        fieldHal = new JTextField(20);
        fieldPenerima = new JTextField(20);
        fieldPengirim = new JTextField(20);
        fieldTglSurat = new JTextField(20);
        fieldTglTerima = new JTextField(20);

        JPanel panel = new JPanel(new GridLayout(6, 1));
        getContentPane().add(panel);
        panel.setBorder(BorderFactory.createTitledBorder("Masukkan Identitas Surat: "));
        panel.add(labelNo);
        panel.add(fieldNo);
        panel.add(labelHal);
        panel.add(fieldHal);
        panel.add(labelPenerima);
        panel.add(fieldPenerima);
        panel.add(labelPengirim);
        panel.add(fieldPengirim);
        panel.add(labelTglSurat);
        panel.add(fieldTglSurat);
        panel.add(labelTglTerima);
        panel.add(fieldTglTerima);

        btnOK = new JButton("Simpan");
        getContentPane().add(btnOK);
        btnOK.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if (fieldNo.getText().equals("") || fieldHal.getText().equals("") || fieldPenerima.getText().equals("")
                        || fieldPengirim.getText().equals("") || fieldTglSurat.getText().equals("")
                        || fieldTglTerima.getText().equals("")) {
                    JOptionPane.showMessageDialog(null, "Ada Field yang Kosong");
                } else {
                
                        Surat surat = new Surat();
                        surat.setNoSurat(fieldNo.getText());
                        surat.setPerihal(fieldHal.getText());
                        surat.setTglSurat(fieldTglSurat.getText());
                        surat.setTglTerima(fieldTglTerima.getText());
                        surat.setPenerima(fieldPenerima.getText());
                        surat.setPengirim(fieldPengirim.getText());
                        JOptionPane.showMessageDialog(rootPane, "Surat Telah Berhasil Disimpan");

                        DataHandler datahandler = new DataHandler();
                    try {
                        datahandler.add(surat.getNoSurat(), surat.getPerihal(), surat.getPenerima(),
                                surat.getPengirim(), surat.getTglSurat(), surat.getTglTerima());
                    } catch (SQLException ex) {
                        Logger.getLogger(DataSuratMasuk.class.getName()).log(Level.SEVERE, null, ex);
                    }

                }

            }
        });

    }

}

ProyekPBO_Kelas DataHandler

package uts_pbo_2;

import java.sql.Statement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import oracle.jdbc.pool.OracleDataSource;

public class DataHandler {

    String jdbcUrl = "jdbc:oracle:thin:172.23.9.185:1521:orcl";
    String userid = "mhs105314031";
    String password = "mhs105314031";
    Connection conn;
    Statement stmt;
    ResultSet rset;
    String query;
    String sqlString;
    private String no;
    private String hal;
    private String pnrm;
    private String pkrm;
    private String TglSurat;
    private String TglTerima;

    public DataHandler() {
    }

    public DataHandler(String no, String hal, String pnrm, String pkrm, String TglSurat, String TglTerima) {
        this.no = no;
        this.hal = hal;
        this.pnrm = pnrm;
        this.pkrm = pkrm;
        this.TglSurat = TglSurat;
        this.TglTerima = TglTerima;
    }

    public void getDBConnection() throws SQLException {
        OracleDataSource ds;
        ds = new OracleDataSource();
        ds.setURL(jdbcUrl);
        conn = ds.getConnection(userid, password);
    }

    public ResultSet getAllEmployees() throws SQLException {
        getDBConnection();
        stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
//        query = "SELECT * FROM Employees ORDER BY employee_id";
        query = "SELECT first_name FROM Employees ORDER BY employee_id";
        System.out.println("\nExecuting query: " + query);
        rset = stmt.executeQuery(query);
        return rset;
    }

     public static ArrayList searchMail(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 Mail";

        ResultSet rset = stmt.executeQuery(query);
        result = new ArrayList();
        while (rset.next()) {
          DataHandler temp = new DataHandler(rset.getString(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 searchNo(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 Mail where NoSurat like '%" + keyword + "%'";

        ResultSet rset = stmt.executeQuery(query);
        result = new ArrayList();
        while (rset.next()) {
          DataHandler temp = new DataHandler(rset.getString(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 searchHal(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 Mail where LOWER (Perihal) like '%" + keyword + "%'";

        ResultSet rset = stmt.executeQuery(query);
        result = new ArrayList();
        while (rset.next()) {
          DataHandler temp = new DataHandler(rset.getString(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 searchPenerima(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 Mail where LOWER (Penerima) like '%" + keyword + "%'";

        ResultSet rset = stmt.executeQuery(query);
        result = new ArrayList();
        while (rset.next()) {
          DataHandler temp = new DataHandler(rset.getString(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 searchPengirim(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 Mail where LOWER (Pengirim) like '%" + keyword + "%'";

        ResultSet rset = stmt.executeQuery(query);
        result = new ArrayList();
        while (rset.next()) {
          DataHandler temp = new DataHandler(rset.getString(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 searchTglSurat(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 Mail where TglSurat like '%" + keyword + "%'";

        ResultSet rset = stmt.executeQuery(query);
        result = new ArrayList();
        while (rset.next()) {
          DataHandler temp = new DataHandler(rset.getString(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 searchTglTerima(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 Mail where TglTerima like '%" + keyword + "%'";

        ResultSet rset = stmt.executeQuery(query);
        result = new ArrayList();
        while (rset.next()) {
          DataHandler temp = new DataHandler(rset.getString(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 void add(String no, String hal, String pnrm, String pkrm, String TglSurat, String TglTerima) throws SQLException {
        DataHandler dataHandler = new DataHandler();
        ArrayList result = null;
        dataHandler.getDBConnection();
        Connection conn = dataHandler.conn;
        Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
        String query = "INSERT INTO Mail VALUES ('" + no + "', '" + hal + "', '"
                + pnrm + "', '" + pkrm + "', '" + TglSurat + "', '"
                + TglTerima + "')";
        result = new ArrayList();
        try {
            result.add(stmt.executeUpdate(query));
        } catch (SQLException ex) {
            System.out.println("error : " + ex.getMessage());
        }
        conn.close();
    }


    /**
     * @return the no
     */
    public String getNo() {
        return no;
    }

    /**
     * @param no the no to set
     */
    public void setNo(String no) {
        this.no = no;
    }

    /**
     * @return the hal
     */
    public String getHal() {
        return hal;
    }

    /**
     * @param hal the hal to set
     */
    public void setHal(String hal) {
        this.hal = hal;
    }

    /**
     * @return the pnrm
     */
    public String getPnrm() {
        return pnrm;
    }

    /**
     * @param pnrm the pnrm to set
     */
    public void setPnrm(String pnrm) {
        this.pnrm = pnrm;
    }

    /**
     * @return the pkrm
     */
    public String getPkrm() {
        return pkrm;
    }

    /**
     * @param pkrm the pkrm to set
     */
    public void setPkrm(String pkrm) {
        this.pkrm = pkrm;
    }

    /**
     * @return the TglSurat
     */
    public String getTglSurat() {
        return TglSurat;
    }

    /**
     * @param TglSurat the TglSurat to set
     */
    public void setTglSurat(String TglSurat) {
        this.TglSurat = TglSurat;
    }

    /**
     * @return the TglTerima
     */
    public String getTglTerima() {
        return TglTerima;
    }

    /**
     * @param TglTerima the TglTerima to set
     */
    public void setTglTerima(String TglTerima) {
        this.TglTerima = TglTerima;
    }

}