Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- //package esahabat;
- /**
- *
- * @author aisyah
- */
- import java.sql.*;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- import java.io.*;
- import java.util.Locale;
- public class Sahabat extends JFrame implements ActionListener
- {
- private PreparedStatement pstmt;
- JTabbedPane jtpTAB = new JTabbedPane();
- JLabel jlbNama = new JLabel("Name");
- JLabel jlbTLahir = new JLabel("Date of Birth");
- JLabel jlbTel = new JLabel("Telephone");
- JLabel jlbAlamat = new JLabel("Address");
- JLabel jlbCari = new JLabel("Search");
- JLabel jlbPaparKeyIn = new JLabel ("DATA YANG TELAH DIMASUKKAN");
- JTextField jtfNama = new JTextField(10);
- JTextField jtfTLahir = new JTextField(10);
- JTextField jtfTel = new JTextField(10);
- JTextField jtfCari = new JTextField(10);
- JTextArea jtaAlamat = new JTextArea(10,1);
- JTextArea jtaPapar = new JTextArea(1,1);
- JTextArea jtaPaparKeyIn = new JTextArea(1,1);
- JButton jbtSimpan = new JButton("Save");
- JButton jbtPapar = new JButton("Show All Records");
- JButton jbtCari = new JButton("Search");
- Sahabat()
- {
- Container bekas = getContentPane();
- bekas.setLayout (new BorderLayout(5,10));
- bekas.setBackground(Color.pink);
- JPanel jplButtonPapar = new JPanel();
- jplButtonPapar.setLayout(new FlowLayout());
- jplButtonPapar.add(jbtPapar);
- JPanel jplCari = new JPanel();
- jplCari.setLayout (new GridLayout(1,4,10,10));
- jplCari.add(jlbCari);
- jplCari.add(jtfCari);
- jplCari.add(jbtCari);
- JPanel jplCombine = new JPanel();
- jplCombine.setLayout (new BorderLayout());
- jplCombine.add(jplCari, BorderLayout.NORTH);
- jplCombine.add(jplButtonPapar, BorderLayout.SOUTH);
- JPanel jplRekod = new JPanel();
- jplRekod.setLayout(new GridLayout(5,2,10,10));
- jplRekod.add(jlbNama);
- jplRekod.add(jtfNama);
- jplRekod.add(jlbTLahir);
- jplRekod.add(jtfTLahir);
- jplRekod.add(jlbAlamat);
- jplRekod.add(new JScrollPane(jtaAlamat));
- jplRekod.add(jlbTel);
- jplRekod.add(jtfTel);
- JPanel jplCombine2 = new JPanel();
- jplCombine2.setLayout(new BorderLayout());
- jplCombine2.add(jplRekod, BorderLayout.CENTER);
- jplCombine2.add(new JScrollPane(jtaPaparKeyIn), BorderLayout.SOUTH);
- JPanel jplTabRekod = new JPanel();
- jplTabRekod.setLayout(new BorderLayout());
- jplTabRekod.add(jplCombine2, BorderLayout.CENTER);
- jplTabRekod.add(jbtSimpan,BorderLayout.SOUTH);
- JPanel jplTabPapar = new JPanel();
- jplTabPapar.setLayout(new BorderLayout());
- jplTabPapar.add(jplCombine, BorderLayout.NORTH);
- jplTabPapar.add(new JScrollPane(jtaPapar), BorderLayout.CENTER);
- jtpTAB.add(jplTabRekod, "Friend's Records");
- jtpTAB.add(jplTabPapar, "Friend's Info");
- bekas.add(jtpTAB, BorderLayout.CENTER);
- jtfNama.addActionListener(this);
- jtfTLahir.addActionListener(this);
- jtfTel.addActionListener(this);
- jbtSimpan.addActionListener(this);
- jbtPapar.addActionListener(this);
- jbtCari.addActionListener(this);
- }
- public void actionPerformed(ActionEvent e)
- {
- //define operation if button simpan had been clicked
- if(e.getSource() == jbtPapar){
- // Create a statement
- }
- if(e.getSource() == jbtCari) {
- pstmt = connection.prepareStatement(queryString);
- }
- }
- public static void main (String args[])throws SQLException, ClassNotFoundException
- {
- Sahabat bingkai = new Sahabat();
- bingkai.setTitle("eSahabat.Pro Versi 1.0");
- bingkai.setSize(500,400);
- bingkai.setVisible(true);
- bingkai.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- //dapatkan saiz piksel skrin monitor semasa
- Dimension saizSkrin = Toolkit.getDefaultToolkit().getScreenSize();
- int lebarSkrin = saizSkrin.width;
- int panjangSkrin = saizSkrin.height;
- //dapatkan saiz frame semasa
- Dimension saizBingkai = bingkai.getSize();
- //kira dan set kedudukan frame pada skrin.
- int x = (lebarSkrin - saizBingkai.width)/2;
- int y = (panjangSkrin - saizBingkai.height)/2;
- //plotkan koordinat x,y yang dah dikira pada arahan setLocation
- bingkai.setLocation(x,y);
- Class.forName("org.apache.derby.jdbc.ClientDriver");
- System.out.println("Driver loaded");
- // Establish a connection
- Connection connection = DriverManager.getConnection
- ("jdbc:derby://localhost:1527/student_database;user=derby; password=derby;");
- System.out.println("Database connected");
- Statement statement = connection.createStatement();
- ResultSet resultSet = statement.executeQuery
- ("select * from DERBY.SAHABAT");
- /*if (resultSet.next()){
- String nama = resultSet.getString(1);
- JOptionPane.showMessageDialog(null, nama);*/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement