Advertisement
Guest User

Untitled

a guest
Jun 18th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.18 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5.  
  6. //package esahabat;
  7.  
  8. /**
  9. *
  10. * @author aisyah
  11. */
  12. import java.sql.*;
  13. import javax.swing.*;
  14. import java.awt.*;
  15. import java.awt.event.*;
  16. import java.io.*;
  17. import java.util.Locale;
  18.  
  19. public class Sahabat extends JFrame implements ActionListener
  20. {
  21. private PreparedStatement pstmt;
  22.  
  23. JTabbedPane jtpTAB = new JTabbedPane();
  24. JLabel jlbNama = new JLabel("Name");
  25. JLabel jlbTLahir = new JLabel("Date of Birth");
  26. JLabel jlbTel = new JLabel("Telephone");
  27. JLabel jlbAlamat = new JLabel("Address");
  28. JLabel jlbCari = new JLabel("Search");
  29. JLabel jlbPaparKeyIn = new JLabel ("DATA YANG TELAH DIMASUKKAN");
  30.  
  31. JTextField jtfNama = new JTextField(10);
  32. JTextField jtfTLahir = new JTextField(10);
  33. JTextField jtfTel = new JTextField(10);
  34. JTextField jtfCari = new JTextField(10);
  35.  
  36. JTextArea jtaAlamat = new JTextArea(10,1);
  37. JTextArea jtaPapar = new JTextArea(1,1);
  38. JTextArea jtaPaparKeyIn = new JTextArea(1,1);
  39.  
  40. JButton jbtSimpan = new JButton("Save");
  41. JButton jbtPapar = new JButton("Show All Records");
  42. JButton jbtCari = new JButton("Search");
  43.  
  44. Sahabat()
  45. {
  46. Container bekas = getContentPane();
  47. bekas.setLayout (new BorderLayout(5,10));
  48. bekas.setBackground(Color.pink);
  49.  
  50. JPanel jplButtonPapar = new JPanel();
  51. jplButtonPapar.setLayout(new FlowLayout());
  52. jplButtonPapar.add(jbtPapar);
  53.  
  54. JPanel jplCari = new JPanel();
  55. jplCari.setLayout (new GridLayout(1,4,10,10));
  56. jplCari.add(jlbCari);
  57. jplCari.add(jtfCari);
  58. jplCari.add(jbtCari);
  59.  
  60. JPanel jplCombine = new JPanel();
  61. jplCombine.setLayout (new BorderLayout());
  62. jplCombine.add(jplCari, BorderLayout.NORTH);
  63. jplCombine.add(jplButtonPapar, BorderLayout.SOUTH);
  64.  
  65. JPanel jplRekod = new JPanel();
  66. jplRekod.setLayout(new GridLayout(5,2,10,10));
  67. jplRekod.add(jlbNama);
  68. jplRekod.add(jtfNama);
  69. jplRekod.add(jlbTLahir);
  70. jplRekod.add(jtfTLahir);
  71. jplRekod.add(jlbAlamat);
  72. jplRekod.add(new JScrollPane(jtaAlamat));
  73. jplRekod.add(jlbTel);
  74. jplRekod.add(jtfTel);
  75.  
  76. JPanel jplCombine2 = new JPanel();
  77. jplCombine2.setLayout(new BorderLayout());
  78. jplCombine2.add(jplRekod, BorderLayout.CENTER);
  79. jplCombine2.add(new JScrollPane(jtaPaparKeyIn), BorderLayout.SOUTH);
  80.  
  81. JPanel jplTabRekod = new JPanel();
  82. jplTabRekod.setLayout(new BorderLayout());
  83. jplTabRekod.add(jplCombine2, BorderLayout.CENTER);
  84. jplTabRekod.add(jbtSimpan,BorderLayout.SOUTH);
  85.  
  86. JPanel jplTabPapar = new JPanel();
  87. jplTabPapar.setLayout(new BorderLayout());
  88. jplTabPapar.add(jplCombine, BorderLayout.NORTH);
  89. jplTabPapar.add(new JScrollPane(jtaPapar), BorderLayout.CENTER);
  90.  
  91. jtpTAB.add(jplTabRekod, "Friend's Records");
  92. jtpTAB.add(jplTabPapar, "Friend's Info");
  93.  
  94. bekas.add(jtpTAB, BorderLayout.CENTER);
  95.  
  96. jtfNama.addActionListener(this);
  97. jtfTLahir.addActionListener(this);
  98. jtfTel.addActionListener(this);
  99. jbtSimpan.addActionListener(this);
  100. jbtPapar.addActionListener(this);
  101. jbtCari.addActionListener(this);
  102. }
  103. public void actionPerformed(ActionEvent e)
  104. {
  105. //define operation if button simpan had been clicked
  106. if(e.getSource() == jbtPapar){
  107. // Create a statement
  108.  
  109.  
  110. }
  111. if(e.getSource() == jbtCari) {
  112.  
  113. pstmt = connection.prepareStatement(queryString);
  114.  
  115. }
  116. }
  117. public static void main (String args[])throws SQLException, ClassNotFoundException
  118. {
  119. Sahabat bingkai = new Sahabat();
  120. bingkai.setTitle("eSahabat.Pro Versi 1.0");
  121. bingkai.setSize(500,400);
  122. bingkai.setVisible(true);
  123. bingkai.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  124. //dapatkan saiz piksel skrin monitor semasa
  125. Dimension saizSkrin = Toolkit.getDefaultToolkit().getScreenSize();
  126. int lebarSkrin = saizSkrin.width;
  127. int panjangSkrin = saizSkrin.height;
  128.  
  129. //dapatkan saiz frame semasa
  130. Dimension saizBingkai = bingkai.getSize();
  131. //kira dan set kedudukan frame pada skrin.
  132. int x = (lebarSkrin - saizBingkai.width)/2;
  133. int y = (panjangSkrin - saizBingkai.height)/2;
  134.  
  135. //plotkan koordinat x,y yang dah dikira pada arahan setLocation
  136. bingkai.setLocation(x,y);
  137.  
  138. Class.forName("org.apache.derby.jdbc.ClientDriver");
  139. System.out.println("Driver loaded");
  140.  
  141. // Establish a connection
  142. Connection connection = DriverManager.getConnection
  143. ("jdbc:derby://localhost:1527/student_database;user=derby; password=derby;");
  144. System.out.println("Database connected");
  145.  
  146. Statement statement = connection.createStatement();
  147.  
  148. ResultSet resultSet = statement.executeQuery
  149. ("select * from DERBY.SAHABAT");
  150. /*if (resultSet.next()){
  151. String nama = resultSet.getString(1);
  152.  
  153. JOptionPane.showMessageDialog(null, nama);*/
  154. }
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement