Advertisement
Guest User

Client Side

a guest
Dec 5th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.22 KB | None | 0 0
  1. import javax.naming.Context;
  2. import javax.naming.InitialContext;
  3. import javax.sql.DataSource;
  4. import javax.swing.*;
  5. import java.awt.*;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8. import java.io.*;
  9. import java.net.Socket;
  10. import java.sql.*;
  11.  
  12.  
  13. public class Login {
  14. private Socket socket = null;
  15. private DataInputStream input = null;
  16. private DataOutputStream out = null;
  17.  
  18. public Login(String address,int port) throws ClassNotFoundException, SQLException, IOException {
  19. final Connection conn;
  20. Class.forName("com.mysql.jdbc.Driver");
  21. conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/pulsaapp","root","");
  22.  
  23. socket = new Socket(address,port);
  24. System.out.println("Berhasil Konke");
  25. Color biru = new Color(52,152,219);
  26.  
  27. final JFrame layout = new JFrame("Pulsa App");
  28. layout.setSize(500,250);
  29. layout.setLocation(450,250);
  30. layout.setResizable(false);
  31. JPanel form = new JPanel();
  32. form.setLocation(20,100);
  33. form.setBackground(biru);
  34. JPanel formContent = new JPanel();
  35. formContent.setLayout(new GridLayout(6,1,2,10));
  36. formContent.setBackground(biru);
  37.  
  38. JLabel idLabel = new JLabel("Masukkan Id :");
  39. idLabel.setFont(new Font("Segoe UI", Font.PLAIN,14));
  40. idLabel.setForeground(Color.white);
  41.  
  42. final JTextField idText = new JTextField(15);
  43. idText.setBorder(BorderFactory.createEmptyBorder());
  44.  
  45. final JLabel passLabel = new JLabel("Masukkan Password :");
  46. passLabel.setFont(new Font("Segoe UI", Font.PLAIN,14));
  47. passLabel.setForeground(Color.white);
  48.  
  49. final JPasswordField passText = new JPasswordField(15);
  50. passText.setBorder(BorderFactory.createEmptyBorder());
  51.  
  52. final JButton btn = new JButton("Login");
  53. btn.setBackground(Color.white);
  54. btn.setFont(new Font("Calibri",Font.PLAIN,14));
  55. btn.addActionListener(new ActionListener() {
  56. public void actionPerformed(ActionEvent e) {
  57. if(e.getSource() == btn) {
  58.  
  59. try {
  60. Integer getId = Integer.valueOf(idText.getText());
  61. String getPass = String.valueOf(passText.getPassword());
  62.  
  63. Server server = new Server();
  64. server.Login(getId,getPass);
  65. layout.setVisible(false);
  66. } catch (ClassNotFoundException e1) {
  67. e1.printStackTrace();
  68. } catch (SQLException e1) {
  69. e1.printStackTrace();
  70. }
  71. /*
  72. Integer id = Integer.valueOf(idText.getText());
  73. String password = String.valueOf(passText.getPassword());
  74. String sql = "SELECT id,password FROM karyawan WHERE id = ? AND password = ?";
  75. try {
  76. PreparedStatement stmt = conn.prepareStatement(sql);
  77. stmt.setInt(1,id);
  78. stmt.setString(2,password);
  79. ResultSet rs = stmt.executeQuery();
  80. if (rs.next()) {
  81. new Dashboard();
  82. layout.setVisible(false);
  83. } else {
  84. JOptionPane.showMessageDialog(null,"ID atau Password Salah");
  85. }
  86.  
  87. } catch (SQLException e1) {
  88. e1.printStackTrace();
  89. } catch (ClassNotFoundException e1) {
  90. e1.printStackTrace();
  91. }
  92. */
  93. }
  94. }
  95. });
  96.  
  97. formContent.add(idLabel);
  98. formContent.add(idText);
  99. formContent.add(passLabel);
  100. formContent.add(passText);
  101. formContent.add(btn);
  102.  
  103. form.add(formContent);
  104.  
  105. layout.add(form);
  106. layout.setVisible(true);
  107. }
  108.  
  109. //SOCKET
  110.  
  111.  
  112. public static void main(String[] args) throws SQLException, ClassNotFoundException, IOException {
  113. new Login("127.0.0.1",5000);
  114. }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement