Kamis, 22 Desember 2011

Class TestSoal3

public class TesSoal3 {

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

Class Soal3

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

public class Soal3 extends JFrame implements ActionListener {

    private static final int lebar = 700;
    private static final int tinggi = 400;
    private static final int x = 0;
    private static final int y = 0;
    Container contentPane;
    private JMenu file;

    public Soal3() {
        setSize(lebar, tinggi);
        setTitle("Password");
        setLocation(x, y);
        setResizable(true);
        setBackground(Color.GRAY);

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

        createfile();

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

        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    public void actionPerformed(ActionEvent e) {
        String menuName;
        menuName = e.getActionCommand();

        if (menuName.equals("Exit")) {
            System.exit(0);
        }

        if (menuName.equals("Home Password")) {
            Panel j1 = new Panel();
            contentPane.add(j1);
            j1.revalidate();
            j1.setVisible(true);
        }
    }

    private void createfile() {
        JMenuItem item;

        file = new JMenu("File");

        item = new JMenuItem("Home Password");
        item.addActionListener(this);
        file.add(item);

        item = new JMenuItem("Exit");
        item.addActionListener(this);
        file.add(item);
    }
}

Class Panel

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

public class Panel extends JPanel implements ActionListener {

    private JLabel name, paswd;
    private JTextField nm, pw;
    private JButton ok;

    public Panel() {

        this.setLayout(new GridLayout(2, 1));

        JPanel p1 = new JPanel();
        p1.setLayout(new GridLayout(2, 2));

        name = new JLabel();
        name.setText("Input your User Name :");

        paswd = new JLabel();
        paswd.setText("Input your Password :");

        nm = new JTextField();
        nm.setColumns(22);
        nm.addActionListener(this);

        pw = new JTextField();
        pw.setColumns(22);
        pw.addActionListener(this);

        p1.add(name);
        p1.add(nm);
        p1.add(paswd);
        p1.add(pw);

        JPanel p2 = new JPanel();
        p2.setLayout(new FlowLayout());
        ok = new JButton("OK");
        ok.addActionListener(this);
        p2.add(ok);

        this.add(p1);
        this.add(p2);
    }

    public void actionPerformed(ActionEvent e) {
        String button;
        button = e.getActionCommand();

        if (button.equals("OK")) {
            if ((nm.getText().equals("root")) && (pw.getText().equals("123456"))) {
                JOptionPane.showMessageDialog(this, "ok");
            } else {
                JOptionPane.showMessageDialog(this, "Salah");
            }
        }
    }
}

Class TestKaryawan

import java.util.InputMismatchException;
import java.util.Scanner;

public class TesKaryawan {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int tgl, bln, thn;
        String nm;

        try {
            Karyawan k = new Karyawan();

            System.out.print("Masukkan Nama : ");
            nm = input.next();
            k.setNama(nm);
            System.out.print("Masukkan Tanggal : ");
            tgl = input.nextInt();
            k.setTglLahir(tgl);
            System.out.print("Masukkan Bulan : ");
            bln = input.nextInt();
            k.setBlnLahir(bln);
            System.out.print("Masukkan Tahun : ");
            thn = input.nextInt();
            k.setThnLahir(thn);

        } catch (InputMismatchException  f) {
            System.out.println("Salah Format");
        }
        catch (Exception e) {
            System.out.println(e.getMessage());
        }
    }
}

Class Karyawan

public class Karyawan {

    private String nama;
    private int tglLahir;
    private int blnLahir;
    private int thnLahir;

    public Karyawan() {
    }

    public void setNama(String nama) {
        this.nama = nama;
    }

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

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

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

Class TestUtsSoal1

public class TesUtsSoal1 {

    public static void main(String[] args) {

        UtsSoal1 frame = new UtsSoal1();
        frame.setVisible(true);
    }

}

Class UtsSoal1

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

public class UtsSoal1 extends JFrame implements ActionListener {

    private static final int lebar = 700;
    private static final int tinggi = 400;
    private static final int x = 0;
    private static final int y = 0;
    Container contentPane;
    private JMenu utama_1;
    private JMenu utama_2;
    private JLabel input;
    private JTextField isiinput;
    private JButton ok;

    public UtsSoal1() {
        setSize(lebar, tinggi);
        setTitle("UTS Satu");
        setLocation(x, y);
        setResizable(true);
        setBackground(Color.GRAY);

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

        createUtama_1();
        createUtama_2();

        JMenuBar menuBar = new JMenuBar();
        this.setJMenuBar(menuBar);
        menuBar.add(utama_1);
        menuBar.add(utama_2);

        input = new JLabel();
        input.setText("Input Password");
        contentPane.add(input);

        isiinput = new JTextField();
        isiinput.setColumns(15);
        contentPane.add(isiinput);

        ok = new JButton("OK");
        contentPane.add(ok);

        setDefaultCloseOperation(EXIT_ON_CLOSE);
    }

    public void actionPerformed(ActionEvent e) {
       
    }

    private void createUtama_1() {
        JMenuItem item;

        utama_1 = new JMenu("Utama 1");

        item = new JMenuItem("Utama 1A");
        item.addActionListener(this);
        utama_1.add(item);

        utama_1.addSeparator();

        item = new JMenuItem("Utama 1B");
        item.addActionListener(this);
        utama_1.add(item);

        utama_1.addSeparator();

        item = new JMenuItem("Utama 1C");
        item.addActionListener(this);
        utama_1.add(item);
    }

    private void createUtama_2() {
        JMenuItem item;

        utama_2 = new JMenu("Utama 2");

        item = new JMenuItem("Utama 2A");
        item.addActionListener(this);
        utama_2.add(item);
    }
}

Class TestPegawai

import java.util.Scanner;
import javax.swing.JOptionPane;
public class TestPegawai {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        Pegawai p = new Pegawai();

        String a=JOptionPane.showInputDialog("Masukkan Nama:");
            p.setName(a);
        String b=JOptionPane.showInputDialog("Masukan NIP:");
            p.setNIP(b);
         try {
        String c= JOptionPane.showInputDialog(null,"Masukkan Golongan :");
            p.setGolongan(c);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, e.getMessage());
        }
    }
}

Class Pegawai

public class Pegawai {
    private String NIP;
    private String Name;
    private String golongan;

public Pegawai(){}

    public String getNIP() {
        return NIP;
    }

    public void setNIP(String NIP) {
        this.NIP = NIP;
    }

    public String getName() {
        return Name;
    }

    public void setName(String Name) {
        this.Name = Name;
    }

    public String getGolongan() {
        return golongan;
    }

    public void setGolongan(String golongan)throws Exception {
      if(golongan == "(I|II|III|IV)"){
        this.golongan = golongan;
      }else
          throw  new Exception("Maaf Golongan yang ada masukkan salah");
    }
    }

Class Main

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

public class Main extends Thread {
        private static Kotak shapes2JPanel;
    public static void main(String[] args) {
        JFrame frame = new JFrame( "Drawing 2D Shapes" );
      frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

      shapes2JPanel = new Kotak();
      frame.add( shapes2JPanel );
      frame.setBackground( Color.WHITE );
      frame.setSize( 400, 400 );
      frame.setVisible( true );
      Main m=new Main();
      m.start();
   }

    @Override
    public void run(){
        while (true){
            try{
                Main.sleep(100);
            }
            catch(InterruptedException ie){break;}
            shapes2JPanel.repaint();
        }
    }
}

Class Kotak

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;

public class Kotak extends JPanel {
    private static GeneralPath gp;
    int jum=1;

    public void paintComponent( Graphics g )
   {
      super.paintComponent( g );
      Random random = new Random();
      Graphics2D g2d = ( Graphics2D ) g;
      g2d.translate( 200, 200 );

      if (jum==25)
          jum=0;

      for ( int count = 1; count <= jum; count++ )
      {
         g2d.rotate( Math.PI / 5.0 );
         g2d.setColor( new Color( random.nextInt( 256 ),
            random.nextInt( 256 ), random.nextInt( 256 ) ) );

         g2d.fillRect(0,0,90,90);
      }
      jum++;
   }
    public GeneralPath kotakImage()
    {
      int xPoints[] = { 90, 0, 180};
      int yPoints[] = { 90, 0, 180};
      GeneralPath kotak = new GeneralPath();
      kotak.moveTo( xPoints[ 0 ], yPoints[ 0 ] );

      for ( int count = 1; count < xPoints.length; count++ )
         kotak.lineTo( xPoints[ count ], yPoints[ count ] );

      kotak.closePath();
      return kotak;
    }
}

Selasa, 06 Desember 2011

Basis Data Modul 12 (Query)

1.
SELECT department_id
FROM employees
MINUS
SELECT department_id
FROM job_history
WHERE job_id LIKE 'ST_CLERK';

2.
SELECT country_id, country_name
FROM countries
minus
SELECT c.country_id, c.country_name
FROM countries c JOIN locations l ON c.country_id = l.country_id
JOIN departments d ON l.location_id = d.location_id;

3.
SELECT job_id, department_id
FROM employees
WHERE department_id IN (10, 50, 20)
UNION
SELECT job_id, department_id
FROM job_history
WHERE department_id IN (10, 50, 20);

4.
SELECT employee_id, job_id
from employees
INTERSECT
SELECT employee_id, job_id
from job_history