Agen 11650012

Pages

Senin, 03 Juni 2013

APLIKASI DATA BUKU

APLIKASI DATA BUKU








Source code :
// membuat class data 

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

/**
 *
 * @author acer
 */
import java.util.ArrayList;
import javax.swing.JOptionPane;

class data {

    private String Judul_Buku;
    private String Nomor_ISBN;
    private String Nama_pengarang;
    private String Edisi_buku;
    private String Nama_penerbit;
    private int Tahun_terbit;

    public void setData(String Judul_Buku, String Nomor_ISBN, String Nama_pengarang, String Edisi_buku, String Nama_penerbit, int Tahun_terbit) {
        this.Judul_Buku = Judul_Buku;
        this.Nomor_ISBN = Nomor_ISBN;
        this.Nama_pengarang = Nama_pengarang;
        this.Edisi_buku = Edisi_buku;
        this.Nama_penerbit = Nama_penerbit;
        this.Tahun_terbit = Tahun_terbit;

    }

    public String getEdisi_buku() {
        return Edisi_buku;
    }

    public String getJudul_Buku() {
        return Judul_Buku;
    }

    public String getNama_penerbit() {
        return Nama_penerbit;
    }

    public String getNama_pengarang() {
        return Nama_pengarang;
    }

    public String getNomor_ISBN() {
        return Nomor_ISBN;
    }

    public int getTahun_terbit() {
        return Tahun_terbit;
    }
}

Source code :

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

/**
 *
 * @author acer
 */
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.border.Border;

/**
 *
 * @author jie
 */
public class form_startup extends JFrame {

    ImageIcon pic = new ImageIcon("src/gambar/Untitled-1.jpg");
    int a = 0;
    JProgressBar progressBar = new JProgressBar(0, 100);
    Border border = BorderFactory.createTitledBorder("Waiting…");
    JLabel gambar = new JLabel();

    public form_startup() {
        setTitle("Hudan Dardiri / 11650012");
        setIconImage(Toolkit.getDefaultToolkit().getImage(form_startup.class.getResource("images (1).gif")));
        progressBar.setStringPainted(true);
        progressBar.setBorder(border);
        JPanel content = (JPanel) getContentPane();
        content.setBackground(Color.blue);
        setContentPane(gambar);
        gambar.setIcon(pic);
        Color warnaBorder = Color.BLACK;
        content.setBorder(BorderFactory.createLineBorder(warnaBorder, 5));
        setLayout(null);
        Component add = add(progressBar);
        progressBar.setBounds(120, 300, 353, 40);
        pack();
        setSize(550, 550);
        setVisible(true);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(3);
        while (a <= 100) {
            progressBar.setValue(a);
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
            }
            a += 1;

        }
        this.dispose();
       


    }


    public static void main(String args[]) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            new form_startup();
        } catch (Exception ex) {
        }

    }
}



Source code :
// Membuat kelas frame buku :


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

/**
 *
 * @author acer
 */
import java.applet.AudioClip;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.*;
import java.util.ArrayList;
import java.util.Collections;
import javax.swing.*;
import pbo.buku;
import sun.applet.AppletAudioClip;

public class form_buku extends JFrame {

    int idx;
    String pil, tempo;
    data banyak = new data();
    ArrayList judul = new ArrayList();
    ArrayList isbn = new ArrayList();
    ArrayList pengarang = new ArrayList();
    ArrayList edisi = new ArrayList();
    ArrayList penerbit = new ArrayList();
    ArrayList tahun = new ArrayList();
    String input, keluar;
    int i = 0;
    ImageIcon pic = new ImageIcon("src/gambar/Untitled-2.jpg");
    JLabel l2 = new JLabel("Judul Buku");
    JLabel l3 = new JLabel("No ISBN");
    JLabel l4 = new JLabel("Pengarang");
    JLabel l5 = new JLabel("Edisi");
    JLabel l6 = new JLabel("Penerbit");
    JLabel l7 = new JLabel("Terbit");
    JTextField t1 = new JTextField();
    JTextField t2 = new JTextField();
    JTextField t3 = new JTextField();
    JTextField t4 = new JTextField();
    JTextField t5 = new JTextField();
    JTextField t6 = new JTextField();
    JButton b1 = new JButton("Add");
    JButton b2 = new JButton("Edit");
    JButton b3 = new JButton("Delete");
    JButton b4 = new JButton("Search");
    JButton b5 = new JButton("View");
    JButton b6 = new JButton("Sort");
    JLabel gambar = new JLabel();

    form_buku() {
        setTitle("Hudan Dardiri / 11650012");
        setSize(550, 550);
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
        setResizable(false);
        setIconImage(Toolkit.getDefaultToolkit().getImage(form_buku.class.getResource("images (1).gif")));
    }

    void tampil() {
        setContentPane(gambar);
        gambar.setIcon(pic);

        getContentPane().setLayout(null);
        getContentPane().add(l2);
        getContentPane().add(l3);
        getContentPane().add(l4);
        getContentPane().add(l5);
        getContentPane().add(l6);
        getContentPane().add(l7);

        getContentPane().add(t1);
        getContentPane().add(t2);
        getContentPane().add(t3);
        getContentPane().add(t4);
        getContentPane().add(t5);
        getContentPane().add(t6);

        getContentPane().add(b1);
        getContentPane().add(b2);
        getContentPane().add(b3);
        getContentPane().add(b4);
        getContentPane().add(b5);
        getContentPane().add(b6);

        l2.setBounds(130, 50, 110, 50);
        l2.setFont(new java.awt.Font("Impact", 0, 20));
        l2.setForeground(Color.BLACK);
        l3.setBounds(130, 90, 110, 50);
        l3.setFont(new java.awt.Font("Impact", 0, 20));
        l3.setForeground(Color.BLACK);
        l4.setBounds(130, 130, 110, 50);
        l4.setFont(new java.awt.Font("Impact", 0, 20));
        l4.setForeground(Color.BLACK);
        l5.setBounds(130, 170, 110, 50);
        l5.setFont(new java.awt.Font("Impact", 0, 20));
        l5.setForeground(Color.BLACK);
        l6.setBounds(130, 210, 110, 50);
        l6.setFont(new java.awt.Font("Impact", 0, 20));
        l6.setForeground(Color.BLACK);
        l7.setBounds(130, 250, 110, 50);
        l7.setFont(new java.awt.Font("Impact", 0, 20));
        l7.setForeground(Color.BLACK);


        t1.setBounds(250, 60, 190, 25);
        t1.setFont(new java.awt.Font("Impact", 0, 14));
        t1.setBackground(new java.awt.Color(204, 204, 204));
        t2.setBounds(250, 100, 190, 25);
        t2.setFont(new java.awt.Font("Impact", 0, 14));
        t2.setBackground(new java.awt.Color(204, 204, 204));
        t3.setBounds(250, 140, 190, 25);
        t3.setFont(new java.awt.Font("Impact", 0, 14));
        t3.setBackground(new java.awt.Color(204, 204, 204));
        t4.setBounds(250, 180, 190, 25);
        t4.setFont(new java.awt.Font("Impact", 0, 14));
        t4.setBackground(new java.awt.Color(204, 204, 204));
        t5.setBounds(250, 220, 190, 25);
        t5.setFont(new java.awt.Font("Impact", 0, 14));
        t5.setBackground(new java.awt.Color(204, 204, 204));
        t6.setBounds(250, 260, 190, 25);
        t6.setFont(new java.awt.Font("Impact", 0, 14));
        t6.setBackground(new java.awt.Color(204, 204, 204));

        b1.setBounds(132, 305, 75, 25);
        b1.setFont(new java.awt.Font("Impact", 0, 14));
        b1.setBackground(Color.red);
        b2.setBounds(210, 305, 75, 25);
        b2.setFont(new java.awt.Font("Impact", 0, 14));
        b2.setBackground(Color.GREEN);
        b3.setBounds(288, 305, 75, 25);
        b3.setFont(new java.awt.Font("Impact", 0, 14));
        b3.setBackground(Color.red);
        b5.setBounds(365, 305, 75, 25);
        b5.setFont(new java.awt.Font("Impact", 0, 14));
        b5.setBackground(Color.GREEN);
        b4.setBounds(452, 60, 75, 25);
        b4.setFont(new java.awt.Font("Impact", 0, 14));
        b4.setBackground(Color.RED);
        b6.setBounds(452, 100, 75, 25);
        b6.setFont(new java.awt.Font("Impact", 0, 14));
        b6.setBackground(Color.GREEN);


        b1.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ef) {
                data mytv = new data();
                mytv.setData(t1.getText(), t2.getText(), t3.getText(), t4.getText(), t5.getText(), Integer.parseInt(t6.getText()));
                judul.add(i, mytv.getJudul_Buku());
                isbn.add(i, mytv.getNomor_ISBN());
                pengarang.add(i, mytv.getNama_pengarang());
                edisi.add(i, mytv.getEdisi_buku());
                penerbit.add(i, mytv.getNama_penerbit());
                tahun.add(i, mytv.getTahun_terbit());
                i++;
                reset();
                JOptionPane.showMessageDialog(null, "Sukses Di Tambahkan");
            }
        });
        b2.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ef) {
                data mytv = new data();
                mytv.setData(t1.getText(), t2.getText(), t3.getText(), t4.getText(), t5.getText(), Integer.parseInt(t6.getText()));
                judul.set(idx, mytv.getJudul_Buku());
                isbn.set(idx, mytv.getNomor_ISBN());
                pengarang.set(idx, mytv.getNama_pengarang());
                edisi.set(idx, mytv.getEdisi_buku());
                penerbit.set(idx, mytv.getNama_penerbit());
                tahun.set(idx, mytv.getTahun_terbit());
                reset();
                JOptionPane.showMessageDialog(null, "Sukses Di Edit");
            }
        });
        b3.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ef) {
                int x = 0;
                pil = t1.getText();
                for (int j = 0; j < judul.size(); j++) {
                    if (pil.equals(judul.get(j))) {
                        x = j;
                        break;
                    }
                }
                judul.remove(x);
                isbn.remove(x);
                pengarang.remove(x);
                edisi.remove(x);
                penerbit.remove(x);
                tahun.remove(x);

                i--;
                reset();
                JOptionPane.showMessageDialog(null, "Sukses Di Hapus");

            }
        });
        b4.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ef) {
                System.out.println("\n" + "Data yang dicari : ");
                int x = 0;
                pil = t1.getText();
                for (int j = 0; j < judul.size(); j++) {
                    if (pil.equals(judul.get(j))) {
                        System.out.println(judul.get(j) + " " + isbn.get(j) + " " + pengarang.get(j) + edisi.get(j) + " " + penerbit.get(j) + " " + tahun.get(j));
                        x = 1;
                    }
                }
                if (x == 0) {
                    System.out.println("Data Tidak Ada");
                }
                reset();
            }
        });


        b5.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ef) {
                System.out.println("\n" + "Data yang ditampilkan : ");
                for (int j = 0; j < judul.size(); j++) {
                    System.out.println(j + 1 + " " + judul.get(j) + " " + isbn.get(j) + " " + pengarang.get(j) + " " + edisi.get(j) + " " + penerbit.get(j) + " " + tahun.get(j));
                }

            }
        });

        b6.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent ef) {
                System.out.println("\n" + "Data setelah diurutkan : ");
                for (int j = 1; j < judul.size(); j++) {
                    for (int k = 0; k < judul.size() - j; k++) {
                        if (((String) judul.get(k)).compareTo((String) judul.get(k + 1)) > 0) {
                            banyak.setData((String) judul.get(k), (String) isbn.get(k), (String) pengarang.get(k), (String) edisi.get(k), (String) penerbit.get(k), (int) tahun.get(k));
                            judul.set(k, (String) judul.get(k + 1));
                            isbn.set(k, (String) isbn.get(k + 1));

                            pengarang.set(k, (String) pengarang.get(k + 1));
                            edisi.set(k, (String) edisi.get(k + 1));
                            penerbit.set(k, (String) penerbit.get(k + 1));
                            tahun.set(k, (int) tahun.get(k + 1));
                            judul.set(k + 1, banyak.getJudul_Buku());
                            isbn.set(k + 1, banyak.getNomor_ISBN());
                            pengarang.set(k + 1, banyak.getNama_pengarang());
                            edisi.set(k + 1, banyak.getEdisi_buku());
                            penerbit.set(k + 1, banyak.getNama_penerbit());
                            tahun.set(k + 1, banyak.getTahun_terbit());


                        }
                    }
                }
                for (int j = 0; j < judul.size(); j++) {
                    Collections.sort(judul);
                    if (judul.get(j).equals("Cinta")) {
                        Collections.sort(tahun);
                    }
                    System.out.println(j + 1 + " " + judul.get(j) + " " + isbn.get(j) + " " + pengarang.get(j) + " " + edisi.get(j) + " " + penerbit.get(j) + " " + tahun.get(j));
                }
            }
        });
    }

    public void reset() {
        t1.setText("");
        t2.setText("");
        t3.setText("");
        t4.setText("");
        t5.setText("");
        t6.setText("");
    }

    public static void main(String[] args) {
        form_buku gui = new form_buku();
        gui.tampil();
    }
}


Download Button

Tidak ada komentar:

Posting Komentar

Diberdayakan oleh Blogger.
 

Peliharaanku

Peliharaanku

Peliharaanku