Rabu, 21 Desember 2011

region

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

package conectsql;

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

/**
 *
 * @author Eka
 */
public class Region {

    private Integer regionId;
    private String regionName;
    private static Connection conn;

    public Region() throws SQLException {
        DataHandler dataHandler = new DataHandler();
        dataHandler.getDBConnection();
        conn = dataHandler.conn;
    }
    public Region(Integer regionId, String regionName) {
        this.regionId = regionId;
        this.regionName = regionName;
    }
    public Integer getRegionId() {
        return regionId;
    }
    public void setRegionId(Integer regionId) {
        this.regionId = regionId;
    }
    public String getRegionName() {
        return regionName;
    }
    public void setRegionName(String regionName) {
        this.regionName = regionName;
    }  
    public static ArrayList TampilRegion() throws SQLException {
        ArrayList result = null;
        DataHandler dataHandler = new DataHandler();
        dataHandler.getDBConnection();
        Connection conn = dataHandler.conn;
        Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                ResultSet.CONCUR_UPDATABLE);
        String query2 = "Select * from regions";
        result = new ArrayList();
        ResultSet rset = stmt.executeQuery(query2);
        while (rset.next()) {
            Region temp = new Region(rset.getInt(1),
                    rset.getString(2));
            result.add(temp);
        }
        conn.close();
        return result;
    }
    public static ArrayList addRegion(int id, String name) throws SQLException {
        ArrayList result = null;
        DataHandler dataHandler = new DataHandler();
        dataHandler.getDBConnection();
        Connection conn = dataHandler.conn;
        Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                ResultSet.CONCUR_UPDATABLE);

        String query = "INSERT INTO regions VALUES (" + id + ",'" + name + "')";

        result = new ArrayList();
        try {
            result.add(stmt.executeUpdate(query));
        } catch (SQLException ex) {
            System.out.println("error : " + ex.getMessage());
        }
        conn.close();
        return result;
    }
//    public static void addRegion(int id, String name) throws SQLException
//    {   PreparedStatement pstmt=null;
//        String sisip ="insert into regions values("+id+","+name+")";
//        pstmt=conn.prepareStatement(sisip);
////int hasil=pstmt.executeUpdate(sisip);
//        pstmt.setObject(1, id);
//        pstmt.setObject(2, name);
//        int cek=pstmt.executeUpdate();
//        if (cek >0)
//            System.out.println("Satu data sudah berhasil dimasukkan");
//        else
//            System.out.println("Data belum berhasil ditambah");
//        //alternatif
////        Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
////        String sisip2 ="insert into regions (region_id,region_name) values(id,name)";
////        int hasil=stmt.executeUpdate(sisip2);
//    }

//    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 = " + keyword ;
//
//        String query="select * from regions where region_name like '%"+keyword+"%'";
//        System.out.println(query);
//        ResultSet rset = stmt.executeQuery(query);
//        result = new ArrayList();
//        while (rset.next()) {
//          Region temp = new Region(rset.getInt(1),rset.getString(2));
//            result.add(temp);
////            result.add(temp.getRegionId());
////            result.add(temp.getRegionName());
//        }
//        conn.close();
//        return result;
//    }
     

//    public static void main(String[] args) throws SQLException {
//        Region r=new Region();
////        System.out.println("isRegionExist " + r.isRegionExist(1));
////        r.addRegion(8,"Asia Timur");
//        ArrayList ar=Region.searchRegions("Asia");
//        Region or;
//        for (int i=0;i<ar.size();i++)
//        {
//            or=(Region)ar.get(i);
//
//            System.out.println(or.getRegionId()+" "+or.getRegionName());
//        }
//        conn.close();
//    }
}
//package Region;
//
//import java.sql.Connection;
//import java.sql.ResultSet;
//import java.sql.SQLException;
//import java.sql.Statement;
//import java.util.ArrayList;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Queen AZT
 */
//public class Region {
//
//    private int region_id;
//    private String region_name;
//
//    public Region() {
//    }
//
//    public Region(int region_id, String region_name) {
//        this.region_id = region_id;
//        this.region_name = region_name;
//    }
//
//    public int getRegion_id() {
//        return region_id;
//    }
//
//    public void setRegion_id(int region_id) {
//        this.region_id = region_id;
//    }
//
//    public String getRegion_name() {
//        return region_name;
//    }
//
//    public void setRegion_name(String region_name) {
//        this.region_name = region_name;
//    }

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

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

/**
 *
 * @author admin
 */
public class JIFEmp 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;
    JTextField text1;
    JTable jtabel1;

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

    public void addPanel() {
        pa = new JPanel();
        pa.setBorder(BorderFactory.createTitledBorder(
                BorderFactory.createLineBorder(Color.red), "Employee"));
        jtabel1 = new JTable();
        jtabel1.setPreferredScrollableViewportSize(new Dimension(700, 350));
        JScrollPane scrollPane = new JScrollPane(jtabel1);

        pa.add(scrollPane);
        pb = new JPanel();
        pb.setLayout(new GridLayout(2, 1));
        p1 = new JPanel();
        p1.setLayout(new GridLayout(2, 1));
        p2 = new JPanel();
        p2.setLayout(new FlowLayout());
        label1 = new JLabel("Masukkan nama : ");
        p1.add(label1);
        text1 = new JTextField();
        p1.add(text1);
        but1 = new JButton("Tampil");
        but1.addActionListener(this);
        p2.add(but1);
        pb.add(p1);
        pb.add(p2);
        this.setLayout(new GridLayout(2, 1));
        this.add(pa);
        this.add(pb);
    }

    public void actionPerformed(ActionEvent event) {
//        throw new UnsupportedOperationException("Not supported yet.");
        JButton clickedButton = (JButton) event.getSource();
        if ((clickedButton.getText()).compareTo("Tampil") == 0) {
            EmployeesTableModel e;
            try {
                System.out.println(text1.getText());
                e = new EmployeesTableModel(text1.getText());
                jtabel1.setModel(e);
                jtabel1.revalidate();
            } catch (SQLException ex) {
                Logger.getLogger(JIFEmp.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}



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

package conectsql;

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

/**
 *
 * @author Tatik
 */
public class RegionTableModel extends AbstractTableModel {

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

    public RegionTableModel(int id,String keyword) throws SQLException {
        Region r=new Region();
         data1 = Region.addRegion(id, keyword);
         data = Region.TampilRegion();
    }
    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) {
        Region temp = (Region) 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 {
//        RegionTableModel test = new RegionTableModel("Asia");
//        System.out.println("nama :" + test.getValueAt(1, 1));
//    }


//package Region;

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

/**
 *
 * @author Queen AZT
 */
//
//import java.sql.SQLException;
//import java.util.ArrayList;
//import javax.swing.table.AbstractTableModel;

//public class RegionTableModel extends AbstractTableModel {
//    //region_id, region_name
//
//    String columNames[] = {"Region Id", "Region Name"};
//    ArrayList data, data1;
//
//
//    @SuppressWarnings("static-access")
//    public RegionTableModel(int id, String name) throws SQLException  {
//        Region r = new Region();
//  
//
//    }
//
//    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) {
//      
//
//    @Override
//    public Class getColumnClass(int c) {
//        return getValueAt(0, c).getClass();
//    }
//}

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

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

/**
 *
 * @author admin
 */
public class DataHandler {

    // string „localhost‟ anda ganti dengan IP server yang digunakan
    String jdbcUrl = "jdbc:oracle:thin:local host:orcl";
    String userid = "System";
    String password = "veraeka";
    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 terkoneksi");

}
}
public void close() {
    try {
        conn.close();

} catch (SQLException ex) {
    System.out.println("Tidak bisa tutup koneksi");
    }
}

}





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

package uts1;

/**
 *
 * @author Acer 4745g
 */
public class Student {
    private String name;
    private String email;
    private String nim;
    private double ipk;
    public Student(){
       
    }
    public Student (String name, String email, String nim,double ipk){
        this.name=name;
        this.email= email;
        this.name=nim;
        this.ipk=ipk;
    }
    public String getName(){
        return name;
    }
    public void setName(String name){
        this.name=name;
    }
    public String getEmail(){
        return email;
    }
    public void setEmail(String email){
        this.email=email;
    }
    public String getNim(){
        return nim;
    }
    public void setNim(String nim){
        this.nim=nim;
    }
    public double getIpk(){
        return ipk;
    }
    public void setIpk(double ipk) throws Exception{
        if(ipk >= 0.0 && ipk <=4.0){
            this.ipk=ipk;
            System.out.println("input berupa angka :"+ipk);
        }
        else{
            System.out.println("nilai tidak sesuai");
        }
    }
    public void setIpk(String ipk){
         try {
            setIpk(Double.parseDouble(ipk));
            System.out.println("input berupa String :"+ipk);
        }catch (Exception ex){
            System.out.println("error:"+ex.getMessage());
        }
    }/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package uts1;

/**
 *
 * @author Acer 4745g
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Student test= new Student();
        test.setIpk("3.00");
//        test.setIpk("3.0");
        test.setIpk("5.00");
//        test.setIpk("6.0");
//        test.setIpk("tiga");
       
    }
   

}

}

kelas main

surat

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

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.io.*;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

/**
 *
 * @author Rency
 */
public class Surat {

    private String noSurat,  perihal,  pengirim,  penerima;
    private int tglSrt,  blnSrt,  thnSrt;
    private int tglDiterima,  blnDiterima,  thnDiterima;

    public Surat() {
    }

    public Surat(String noSurat, String perihal, int tglSrt, int blnSrt, int thnSrt,
            int tglDiterima, int blnDiterima, int thnDiterima,
            String pengirim, String penerima) {
        this.noSurat = noSurat;
        this.perihal = perihal;
        this.tglSrt = tglSrt;
        this.blnSrt = blnSrt;
        this.thnSrt = thnSrt;
        this.tglDiterima = tglDiterima;
        this.blnDiterima = blnDiterima;
        this.thnDiterima = thnDiterima;
        this.pengirim = pengirim;
        this.penerima = penerima;
    }

    public void save() throws IOException {
        JFileChooser chooser = new JFileChooser();
        int option = chooser.showSaveDialog(chooser);

        if (option == JFileChooser.APPROVE_OPTION) {
            String file = chooser.getSelectedFile().getPath();
            File outFile = new File(file);
            FileOutputStream outFileStream = new FileOutputStream(outFile, true);
            PrintWriter outStream = new PrintWriter(outFileStream);
         
           
            String surat = null;

            surat = this.getNoSurat() + ":" + this.getPerihal() + ":" + this.getTglSrt() + "/" + this.getBlnSrt() + "/" +
                    this.getThnSrt() + ":" + this.getTglDiterima() + "/" + this.getBlnDiterima() + "/" + this.getThnDiterima() + ":" +
                    this.getPengirim() + ":" + this.getPenerima()+"\n";

            outStream.println(surat);
            outStream.close();
           
        } else {
            JOptionPane.showMessageDialog(null, "ERROR");
        }

    }

    public String getNoSurat() {
        return noSurat;
    }

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

    public String getPerihal() {
        return perihal;
    }

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

    public String getPengirim() {
        return pengirim;
    }

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

    public String getPenerima() {
        return penerima;
    }

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

    public static ArrayList addData(String no, String perihal, int tgl1, int bln1, int thn1,
            int tgl2, int bln2, int thn2,
            String pengirim, String penerima) throws SQLException, ClassNotFoundException {

        ArrayList result = null;
        DataHandler1 dataHandler = new DataHandler1();
        dataHandler.getDBConnection();
        Connection conn = dataHandler.conn;
        Statement stmt = (Statement) conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                ResultSet.CONCUR_UPDATABLE);

        String query = "INSERT INTO surat VALUES ('" + no + "', '" + perihal + "', " + tgl1 + "," + bln1 + "," + thn1 + "," + tgl2 + "," + bln2 + "," + thn2 + ", '" + pengirim + "', '" + penerima + "')";

        result = new ArrayList();
        try {
            result.add(stmt.executeUpdate(query));
        } catch (SQLException ex) {
            System.out.println("error : " + ex.getMessage());
        }
        conn.close();
        return result;

    }

    public static ArrayList displaySuratMasuk() throws SQLException, ClassNotFoundException {
        ArrayList result = null;
        DataHandler1 dataHandler = new DataHandler1();
        dataHandler.getDBConnection();
        Connection conn = dataHandler.conn;
        Statement stmt = (Statement) conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
                ResultSet.CONCUR_UPDATABLE);

        String query2 = "Select * from surat";
        result = new ArrayList();

        ResultSet rset = stmt.executeQuery(query2);
        while (rset.next()) {
            Surat temp = new Surat(rset.getString(1),
                    rset.getString(2),
                    rset.getInt(3),
                    rset.getInt(4),
                    rset.getInt(5),
                    rset.getInt(6),
                    rset.getInt(7),
                    rset.getInt(8),
                    rset.getString(9),
                    rset.getString(10));

            result.add(temp);
        }

        conn.close();
        return result;
    }

    public static ArrayList searchPengirim(String keyword) throws SQLException, ClassNotFoundException {
        ArrayList result = null;
        DataHandler1 dataHandler = new DataHandler1();
        dataHandler.getDBConnection();
        Connection conn = dataHandler.conn;
        Statement stmt = (Statement) conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                ResultSet.CONCUR_READ_ONLY);

        String query = "SELECT * from surat " + "where pengirim like '%" + keyword + "%'";
        ResultSet rset = stmt.executeQuery(query);
        result = new ArrayList();
        while (rset.next()) {
            Surat temp = new Surat(rset.getString(1),
                    rset.getString(2),
                    rset.getInt(3),
                    rset.getInt(4),
                    rset.getInt(5),
                    rset.getInt(6),
                    rset.getInt(7),
                    rset.getInt(8),
                    rset.getString(9),
                    rset.getString(10));
            result.add(temp);

        }
        conn.close();
        return result;
    }

    public static ArrayList searchPenerima(String keyword) throws SQLException, ClassNotFoundException {
        ArrayList result = null;
        DataHandler1 dataHandler = new DataHandler1();
        dataHandler.getDBConnection();
        Connection conn = dataHandler.conn;
        Statement stmt = (Statement) conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                ResultSet.CONCUR_READ_ONLY);


        String query = "SELECT * FROM surat where penerima like '%" + keyword + "%'";

        ResultSet rset = stmt.executeQuery(query);
        result = new ArrayList();
        while (rset.next()) {
            Surat temp = new Surat(rset.getString(1),
                    rset.getString(2),
                    rset.getInt(3),
                    rset.getInt(4),
                    rset.getInt(5),
                    rset.getInt(6),
                    rset.getInt(7),
                    rset.getInt(8),
                    rset.getString(9),
                    rset.getString(10));
            result.add(temp);
        }
        conn.close();
        return result;
    }

    public static ArrayList searchPerihal(String keyword) throws SQLException, ClassNotFoundException {
        ArrayList result = null;
        DataHandler1 dataHandler = new DataHandler1();
        dataHandler.getDBConnection();
        Connection conn = dataHandler.conn;
        Statement stmt = (Statement) conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                ResultSet.CONCUR_READ_ONLY);
        String query = "SELECT * FROM surat where perihal like '%" + keyword + "%'";

        ResultSet rset = stmt.executeQuery(query);
        result = new ArrayList();
        while (rset.next()) {
            Surat temp = new Surat(rset.getString(1),
                    rset.getString(2),
                    rset.getInt(3),
                    rset.getInt(4),
                    rset.getInt(5),
                    rset.getInt(6),
                    rset.getInt(7),
                    rset.getInt(8),
                    rset.getString(9),
                    rset.getString(10));
            result.add(temp);

        }
        conn.close();
        return result;
    }

    public static ArrayList searchBlnThn(int bln, int thn) throws SQLException, ClassNotFoundException {
        ArrayList result = null;
        DataHandler1 dataHandler = new DataHandler1();
        dataHandler.getDBConnection();
        Connection conn = dataHandler.conn;
        Statement stmt = (Statement) conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                ResultSet.CONCUR_READ_ONLY);
        String query = "SELECT * FROM surat where bln_diterima = " + bln + " AND thn_diterima = " + thn;


        ResultSet rset = stmt.executeQuery(query);
        result = new ArrayList();
        while (rset.next()) {
            Surat temp = new Surat(rset.getString(1),
                    rset.getString(2),
                    rset.getInt(3),
                    rset.getInt(4),
                    rset.getInt(5),
                    rset.getInt(6),
                    rset.getInt(7),
                    rset.getInt(8),
                    rset.getString(9),
                    rset.getString(10));
            result.add(temp);

        }
        conn.close();
        return result;
    }

    public static ArrayList searchBln(int bln) throws SQLException, ClassNotFoundException {
        ArrayList result = null;
        DataHandler1 dataHandler = new DataHandler1();
        dataHandler.getDBConnection();
        Connection conn = dataHandler.conn;
        Statement stmt = (Statement) conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
                ResultSet.CONCUR_READ_ONLY);
        String query = "SELECT * FROM surat where bln_diterima = " + bln;
//        ResultSet rset = stmt.execute(query);
        ResultSet rset = stmt.executeQuery(query);
        result = new ArrayList();
        while (rset.next()) {

            Surat temp = new Surat(rset.getString(1),
                    rset.getString(2),
                    rset.getInt(3),
                    rset.getInt(4),
                    rset.getInt(5),
                    rset.getInt(6),
                    rset.getInt(7),
                    rset.getInt(8),
                    rset.getString(9),
                    rset.getString(10));
            result.add(temp);
        }
        conn.close();
        return result;
    }

    public int getTglSrt() {
        return tglSrt;
    }

    public void setTglSrt(int tglSrt) throws Exception {
        this.tglSrt = tglSrt;
    }

    public int getBlnSrt() {
        return blnSrt;
    }

    public void setBlnSrt(int blnSrt) throws Exception {
        this.blnSrt = blnSrt;
    }

    public int getThnSrt() {
        return thnSrt;
    }

    public void setThnSrt(int thnSrt) throws Exception {
        this.thnSrt = thnSrt;
    }

    public int getTglDiterima() {
        return tglDiterima;
    }

    public void setTglDiterima(int tglDiterima) throws Exception {
        this.tglDiterima = tglDiterima;
    }

    public int getBlnDiterima() {
        return blnDiterima;
    }

    public void setBlnDiterima(int blnDiterima) throws Exception {
        this.blnDiterima = blnDiterima;
    }

    public int getThnDiterima() {
        return thnDiterima;
    }

    public void setThnDiterima(int thnDiterima) throws Exception {
        this.thnDiterima = thnDiterima;
    }
}

uts08

import java.io.File;
/*
 * EmployeeList.java
 *
 * Created on December 4, 2008, 7:31 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

/**
 *
 * @author Puspaningtyas
 */
public class EmployerList {
    private Employer[] list = new Employer[100];
    private int numberOfEmployer=0;
    private File file;
   
    /** Creates a new instance of EmployeeList
     * Konstruktor EmployerList merupakan konstruktor yang berfungsi:
     * 1. membuat obyek EmployerList
     * 2. membaca tabel employee (field firstname dan lastname)
     * 3. memasukkan hasil pembacaan ke obyek list
     * Poin : 20
     */
    public EmployerList() {
    }
   
    /**
     * Fungsi save() merupakan fungsi untuk menyimpan obyek list ke file.
     * Poin: 10
     */
    public void save(){
       
    }
    /**
     * Fungsi addEmployer() merupakan fungsi untuk menambah list.
     * Poin: 10
     */
    public void addEmployer(Employer employer){
       
    }
   
    public int getNumberOfEmployer() {
        return numberOfEmployer;
    }
   
    public void setNumberOfEmployer(int numberOfEmployer) {
        this.numberOfEmployer = numberOfEmployer;
    }
   
    public File getFile() {
        return file;
    }
   
    public void setFile(File file) {
        this.file = file;
    }
   
   
   
}

/*
 * Employee.java
 *
 * Created on December 4, 2008, 7:32 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

/**
 *
 * @author Puspaningtyas
 * Poin: 20
 */
public class Employer {
    /** Creates a new instance of Employee */
    public Employer() {
    }
    
}

sopWatch

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class StopWatchFrame extends javax.swing.JFrame
        implements Runnable{
   
    /** Creates new form NewJFrame */
    public StopWatchFrame() {
        super("Stop Watch");
        initComponents();
    }
   
   
    private void initComponents() {
        numberLabel = new javax.swing.JLabel();
        numberText = new javax.swing.JTextField();
        startButton = new javax.swing.JButton();
        stopButton = new javax.swing.JButton();
       
        this.setLayout(new java.awt.GridLayout(0, 2));
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
       
        numberLabel.setText("timer");
        this.add(numberLabel);
       
        numberText.setText("0");
        this.add(numberText);
       
        startButton.setText("Start");
        this.add(startButton);
       
       
        stopButton.setText("Stop");
        this.add(stopButton);
       
    }
   
    public void startButtonAction(){

    }
   
    public void stopButtonAction(){

    }
    public static void main(String args[]) {
        StopWatchFrame test = new StopWatchFrame();
        test.setSize(300,100);
        test.setVisible(true);
    }
   
   
    // Variables declaration - do not modify
    private javax.swing.JLabel numberLabel;
    private javax.swing.JTextField numberText;
    private javax.swing.JButton startButton;
    private javax.swing.JButton stopButton;
    private Thread thread;
    private int time;
    private boolean start=false;
    // End of variables declaration
   
    public boolean isStart() {
        return start;
    }
   
    public void setStart(boolean start) {
        this.start = start;
    }
   
    public int getTime() {
        return time;
    }
   
    public void setTime(int time) {
        this.time = time;
    }
   
    public void run() {
        try {
            while(isStart()){
                Thread.sleep(100);

            }
        } catch (InterruptedException ex) {
            ex.printStackTrace();
        }
    }
   
}

soal3_uts1

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

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

/**
 *
 * @author admin
 */
public class Soal3 extends JInternalFrame implements ActionListener {

    JPanel p1, p2, p3;
    JLabel l1, l2, l3;
    JTextField t1, t2;
    JButton but1;

    public Soal3() {
        JPanel P = new JPanel();
        setSize(400, 400);
        P.setLayout(new GridLayout(2, 1));
        setContentPane(P);
        p1 = new JPanel();
        p1.setBackground(Color.WHITE);
        p1.setLayout(new GridLayout(2, 2));
        l1 = new JLabel("input your user name");
        p1.add(l1);
        t1 = new JTextField();
        t1.setColumns(10);
        p1.add(t1);

        l2 = new JLabel("input your password");
        p1.add(l2);
        t2 = new JTextField();
        t2.setColumns(10);
        l3 = new JLabel();
        p1.add(t2);
        P.add(p1);

        p2 = new JPanel();
        p2.setBackground(Color.WHITE);
        but1 = new JButton("Ok");
        p2.add(but1);
        P.add(p2);
        but1.addActionListener(this);

    }

    public void actionPerformed(ActionEvent e){
        String s = e.getActionCommand();
        if (s.equals("Ok")) {
            String nama = t1.getText();
            String pass = t2.getText();
            if (nama.equals("root") && pass.equals("admin")) {
                JOptionPane.showMessageDialog(null, "password ok");
            } else {
                JOptionPane.showMessageDialog(null, "salah");
//                throw new Exception("salah");
            }
        }
    }
}


kelas lain

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

import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;

/**
 *
 * @author admin
 */
public class Soal_3 extends JFrame {

    JMenuBar menuBar;
    JMenu file, utama2;
    JMenuItem a1, a2, a3;
    JLabel l1;
    JTextField t1;
    JButton but1;

    public Soal_3() {
        super("Password");
        menuBar = new JMenuBar();

        file = new JMenu("FILE");
        menuBar.add(file);

        a1 = new JMenuItem("Menu Password");
        file.add(a1);

        a2 = new JMenuItem("Exit");
        file.add(a2);

        setDefaultCloseOperation(EXIT_ON_CLOSE);
//
        this.setJMenuBar(menuBar);
//         JPanel P = new JPanel();
//        setSize(400, 400);
//        P.setLayout(new GridLayout(2, 1));
//        setContentPane(P);
//        JPanel p1 = new JPanel();
//        p1.setBackground(Color.WHITE);
//        p1.setLayout(new GridLayout(2, 2));
//        l1 = new JLabel("input your user name");
//        p1.add(l1);
//        t1 = new JTextField();
//        t1.setColumns(10);
//        p1.add(t1);
//        JLabel l2 = new JLabel("input your password");
//        p1.add(l2);
//        t1 = new JTextField();
//        t1.setColumns(10);
//        p1.add(t1);
//        P.add(p1);
//        JPanel p2 = new JPanel();
//        p2.setBackground(Color.WHITE);
//        but1 = new JButton("Ok");
//        p2.add(but1);
//        P.add(p2);

        a1.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
//                throw new UnsupportedOperationException("Not supported yet.");
                a1Action();
            }
                    });
    }
    private void a1Action (){
       Soal3 frames = new Soal3();
        frames.setVisible(true);
        this.add(frames);
    }


}

kelas main

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

package testsoal_3;

import java.awt.*;
import javax.swing.*;

/**
 *
 * @author admin
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Soal_3 a= new Soal_3();
        a.setSize(600, 300);
        a.setVisible(true);
    }

}

http://www.ziddu.com/download/17897490/NetBeansProjects.zip.html

soal_2_uts1

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

package soal_2;

/**
 *
 * @author admin
 */
public class Soal2 {

     public String nama;
    public int tglLahir;
    public int blnLahir;
    public int thnLahir;

    public Soal2(){

    }
    public void setTglLahir(int tgl) throws Exception{
        if(tgl>0 && tgl <=31)
            this.tglLahir=tgl;
        else
            throw new Exception ("tanggal harus sesuai");
    }

     public void setBlnahir(int bulan) throws Exception{
        if(bulan>0 && bulan <=12)
            this.blnLahir=bulan;
        else
            throw new Exception ("bulan harus sesuai");
    }

      public void setThnahir(int tahun) throws Exception{
        if(tahun>0 && tahun >1900)
            this.thnLahir=tahun;
        else
            throw new Exception ("tahun harus sesuai");
    }

    /**
     * @return the nama
     */
    public String getNama() {
        return nama;
    }

    /**
     * @return the tglLahir
     */
    public int getTglLahir() {
        return tglLahir;
    }

    /**
     * @return the blnLahir
     */
    public int getBlnLahir() {
        return blnLahir;
    }

    /**
     * @return the thnLahir
     */
    public int getThnLahir() {
        return thnLahir;
    }


}

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

import java.lang.Exception;
import javax.swing.JOptionPane;

/**
 *
 * @author admin
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Soal2 s = new Soal2();
        int tgl;
        int bln;
        int thn;
//        tanggal=Integer.parseInt(tgl);
        try {
            tgl = Integer.parseInt(JOptionPane.showInputDialog(null, " masukan tgl lahir anda:"));
            s.setTglLahir(tgl);
            
            bln=Integer.parseInt(JOptionPane.showInputDialog(null, "masukan bulan lahir anda:"));
            s.setBlnahir(bln);

            thn=Integer.parseInt(JOptionPane.showInputDialog(null, "Masukan tahun lahir anda:"));
            s.setThnahir(thn);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Error  " + ex.getMessage()+"\n silahkan masukan yang benar");
        }

    }
}

Soal1_uts1

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

package testSoal_1;

import javax.swing.*;

/**
 *
 * @author admin
 */
public class Soal_1 extends JFrame{
JMenuBar menuBar;
JMenu utama1,utama2;
JMenuItem a1,a2,a3,a4,a5;
JLabel l1;
JTextField t1;
JButton but1;
    public Soal_1(){
        super("UTS Soal");
        menuBar = new JMenuBar();

        utama1 = new JMenu("Utama 1");
        menuBar.add(utama1);

        utama2 = new JMenu("Utama 2");
        menuBar.add(utama2);

        a1 = new JMenuItem("Menu 1A");
        utama1.add(a1);

        a2 = new JMenuItem("Menu 1B");
        utama1.add(a2);
        utama1.addSeparator();

        a3= new JMenuItem("Menu 1C");
        utama1.add(a3);
        setDefaultCloseOperation(EXIT_ON_CLOSE);

        a4=new JMenuItem("Menu 2A");
        utama2.add(a4);

        a5=new JMenuItem("Menu 2B");
        utama2.add(a5);

        this.setJMenuBar(menuBar);

    }

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

package testSoal_1;

import javax.swing.*;

/**
 *
 * @author admin
 */
public class Soal_1 extends JFrame{
JMenuBar menuBar;
JMenu utama1,utama2;
JMenuItem a1,a2,a3,a4,a5;
JLabel l1;
JTextField t1;
JButton but1;
    public Soal_1(){
        super("UTS Soal");
        menuBar = new JMenuBar();

        utama1 = new JMenu("Utama 1");
        menuBar.add(utama1);

        utama2 = new JMenu("Utama 2");
        menuBar.add(utama2);

        a1 = new JMenuItem("Menu 1A");
        utama1.add(a1);

        a2 = new JMenuItem("Menu 1B");
        utama1.add(a2);
        utama1.addSeparator();

        a3= new JMenuItem("Menu 1C");
        utama1.add(a3);
        setDefaultCloseOperation(EXIT_ON_CLOSE);

        a4=new JMenuItem("Menu 2A");
        utama2.add(a4);

        a5=new JMenuItem("Menu 2B");
        utama2.add(a5);

        this.setJMenuBar(menuBar);

    }

}

soal_2_uts2

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

/**
 *
 * @author admin
 */
public class S0al_2 {

    private String nama;
    private String nip;
    private String golongan;

    /**
     * @return the nama
     */
    public String getNama() {
        return nama;
    }

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

    /**
     * @return the nip
     */
    public String getNip() {
        return nip;
    }

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

    /**
     * @return the golongan
     */
    public String getGolongan() {
        return golongan;
    }

    /**
     * @param golongan the golongan to set
     */
    public void setGolongan(String golongan) throws Exception {
//        String a=";
        if (golongan.equals("Ia")) {
        }
         else if (golongan.equals("Ib")) {
         }  else if (golongan.equals("Ic")) {
         } else if (golongan.equals("Id")) {
         }
         else if(golongan.equals("IIa")){
         }
         else if(golongan.equals("IIb")){
         }
         else if(golongan.equals("IIc")){
         }
         else if(golongan.equals("IId")){
         }
         else if(golongan.equals("IIIa")){
         }
         else if(golongan.equals("IIIb")){
         }
         else if(golongan.equals("IIIc")){
         }
         else if(golongan.equals("IIId")){
         }
        else if(golongan.equals("IVa")){
         }else if(golongan.equals("IVb")){
         }else if(golongan.equals("IVc")){
         }else if(golongan.equals("IVd")){

         this.golongan = golongan;
         }
    else
        throw new Exception ("golongan harus sesuai");
    }
}



kelas mian

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

package uts_105314069;

import java.util.Scanner;
import javax.swing.JOptionPane;

/**
 *
 * @author admin
 */
public class TesPegawai {
 public static void main(String[] args) {
     S0al_2 s= new S0al_2();
     String gol;
     String nama;
     String nip;
     
//      System.out.println("masukan golongan :");
//      gol=in.next();

        try {
            nama=(JOptionPane.showInputDialog(null, " masukn nama pegawai:"));
            s.setNama(nama);
            nip=(JOptionPane.showInputDialog(null, " masukn nip:"));
            s.setNip(nip);
            gol = (JOptionPane.showInputDialog(null, " masukn golongan pegawai:"));
            s.setGolongan(gol);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Error  " + ex.getMessage()+"\n silahkan masukan yang benar");
        }

 }

}

soal_1 uts2

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

package uts_105314069;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.GeneralPath;
import java.util.Random;
import javax.swing.JPanel;

/**
 *
 * @author admin
 */
public class Soal_1 extends JPanel {
   // draw general paths
    @Override
   public void paintComponent( Graphics g )
   {
      super.paintComponent( g ); // call superclass's paintComponent
      Random random = new Random(); // get random number generator
     
      int xPoints[] = { 0,60,60,0 };
      int yPoints[] = { 0,0,60,60};
      Graphics2D g2d = ( Graphics2D ) g;
      GeneralPath star = new GeneralPath(); // create GeneralPath object
     
      star.moveTo( xPoints[ 0 ], yPoints[ 0 ] );

      // create the star--this does not draw the star
      for ( int count = 1; count < xPoints.length; count++ )
         star.lineTo( xPoints[ count ], yPoints[ count ] );

      star.closePath(); // close the shape

      g2d.translate( 200, 200 ); // translate the origin to (200, 200)

      // rotate around origin and draw stars in random colors
      for ( int count = 1; count <= 18; count++ )
      {
         g2d.rotate( Math.PI / 4.0 ); // rotate coordinate system

         // set random drawing color
         g2d.setColor( new Color( random.nextInt( 256 ),
            random.nextInt( 256 ), random.nextInt( 256 ) ) );

         g2d.fill( star ); // draw filled star
      } // end for
   } // end method paintComponent
} // end class Shapes2JPanel

kelas Main

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

package uts_105314069;

import java.awt.Color;
import javax.swing.JFrame;

/**
 *
 * @author admin
 */
public class Tes_Soal_1 extends Thread {
    // execute application

    private static Soal_1 shapes2JPanel;

    public static void main(String args[]) {
        // create frame for Shapes2JPanel
        JFrame frame = new JFrame("Drawing 2D");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        shapes2JPanel = new Soal_1();
        frame.add(shapes2JPanel); // add shapes2JPanel to frame
        frame.setBackground(Color.WHITE); // set frame background color
        frame.setSize(400, 400); // set frame size
        frame.setVisible(true); // display frame
        Tes_Soal_1 sh = new Tes_Soal_1();
        sh.start();
    } // end main

    @Override
    public void run() {
        while (true) {
            try {
                Tes_Soal_1.sleep(500);
            } catch (InterruptedException ie) {
                break;
            }
            shapes2JPanel.repaint();
        }
    }
} // end class Shapes2