Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.net.*;
- import java.io.*;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- class PalClient implements ActionListener {
- static Socket sock;
- static PrintWriter socketWriter;
- static BufferedReader socketReader;
- static String inputString;
- static String auth_string;
- static JPanel panel;
- static JButton submitAuth, submitInput;
- static JTextField username, password, input;
- static JTextArea status;
- static void createPanel() {
- panel = new JPanel();
- submitAuth = new JButton("Authenticate");
- submitInput = new JButton("Check");
- username = new JTextField("joseph", 30);
- password = new JTextField("pass123", 30);
- input = new JTextField(30);
- status = new JTextArea(30, 30);
- submitAuth.addActionListener(new PalClient());
- submitInput.addActionListener(new PalClient());
- panel.add(username);
- panel.add(password);
- panel.add(submitAuth);
- panel.add(input);
- panel.add(submitInput);
- panel.add(status);
- }
- public void actionPerformed(ActionEvent ae) {
- String actionString = ae.getActionCommand();
- String str;
- System.out.println(actionString);
- if (actionString == "Authenticate") {
- auth_string = username.getText() + ";" + password.getText();
- socketWriter.println(auth_string);
- System.out.println(auth_string);
- try {
- str = socketReader.readLine();
- System.out.print(str);
- if (str == "true")
- status.append("Login successul\n");
- } catch (Exception e) {
- System.out.println(e);
- }
- }
- if (actionString == "Check") {
- try {
- socketWriter.print(input.getText());
- status.setText(socketReader.readLine());
- }
- catch (Exception e){}
- }
- }
- public static void main(String[] args) {
- JFrame f = new JFrame();
- boolean accountExists = false;
- // Initialize sockets
- try {
- sock = new Socket("127.0.0.1", 5003);
- // Set up IO streams
- socketWriter = new PrintWriter(sock.getOutputStream(), true);
- socketReader = new BufferedReader(new InputStreamReader(sock.getInputStream()));
- createPanel();
- f.add(panel);
- f.setBounds(0, 0, 400, 400);
- f.setVisible(true);
- f.setDefaultCloseOperation(3);
- } catch (Exception e) {
- System.out.println(e);
- }
- }
- }
Add Comment
Please, Sign In to add comment