Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.naming.Context;
- import javax.naming.InitialContext;
- import javax.sql.DataSource;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.io.*;
- import java.net.Socket;
- import java.sql.*;
- public class Login {
- private Socket socket = null;
- private DataInputStream input = null;
- private DataOutputStream out = null;
- public Login(String address,int port) throws ClassNotFoundException, SQLException, IOException {
- final Connection conn;
- Class.forName("com.mysql.jdbc.Driver");
- conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/pulsaapp","root","");
- socket = new Socket(address,port);
- System.out.println("Berhasil Konke");
- Color biru = new Color(52,152,219);
- final JFrame layout = new JFrame("Pulsa App");
- layout.setSize(500,250);
- layout.setLocation(450,250);
- layout.setResizable(false);
- JPanel form = new JPanel();
- form.setLocation(20,100);
- form.setBackground(biru);
- JPanel formContent = new JPanel();
- formContent.setLayout(new GridLayout(6,1,2,10));
- formContent.setBackground(biru);
- JLabel idLabel = new JLabel("Masukkan Id :");
- idLabel.setFont(new Font("Segoe UI", Font.PLAIN,14));
- idLabel.setForeground(Color.white);
- final JTextField idText = new JTextField(15);
- idText.setBorder(BorderFactory.createEmptyBorder());
- final JLabel passLabel = new JLabel("Masukkan Password :");
- passLabel.setFont(new Font("Segoe UI", Font.PLAIN,14));
- passLabel.setForeground(Color.white);
- final JPasswordField passText = new JPasswordField(15);
- passText.setBorder(BorderFactory.createEmptyBorder());
- final JButton btn = new JButton("Login");
- btn.setBackground(Color.white);
- btn.setFont(new Font("Calibri",Font.PLAIN,14));
- btn.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- if(e.getSource() == btn) {
- try {
- Integer getId = Integer.valueOf(idText.getText());
- String getPass = String.valueOf(passText.getPassword());
- Server server = new Server();
- server.Login(getId,getPass);
- layout.setVisible(false);
- } catch (ClassNotFoundException e1) {
- e1.printStackTrace();
- } catch (SQLException e1) {
- e1.printStackTrace();
- }
- /*
- Integer id = Integer.valueOf(idText.getText());
- String password = String.valueOf(passText.getPassword());
- String sql = "SELECT id,password FROM karyawan WHERE id = ? AND password = ?";
- try {
- PreparedStatement stmt = conn.prepareStatement(sql);
- stmt.setInt(1,id);
- stmt.setString(2,password);
- ResultSet rs = stmt.executeQuery();
- if (rs.next()) {
- new Dashboard();
- layout.setVisible(false);
- } else {
- JOptionPane.showMessageDialog(null,"ID atau Password Salah");
- }
- } catch (SQLException e1) {
- e1.printStackTrace();
- } catch (ClassNotFoundException e1) {
- e1.printStackTrace();
- }
- */
- }
- }
- });
- formContent.add(idLabel);
- formContent.add(idText);
- formContent.add(passLabel);
- formContent.add(passText);
- formContent.add(btn);
- form.add(formContent);
- layout.add(form);
- layout.setVisible(true);
- }
- //SOCKET
- public static void main(String[] args) throws SQLException, ClassNotFoundException, IOException {
- new Login("127.0.0.1",5000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement