Created
October 15, 2018 13:35
-
-
Save drelagreen/c6e5dd6fd46f8c3550470deff7ddc2f6 to your computer and use it in GitHub Desktop.
2,0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package v0_2b; | |
import javax.swing.*; | |
import java.awt.*; | |
import java.awt.event.ActionEvent; | |
import java.awt.event.ActionListener; | |
import java.awt.event.KeyEvent; | |
import java.awt.event.KeyListener; | |
public class Graph extends JFrame { | |
JTextField jj; | |
Graph(){ | |
setResizable(false); | |
setTitle("SAMBEKChat v.0.2b"); | |
setSize(500,500); | |
setVisible(true); | |
setDefaultCloseOperation(EXIT_ON_CLOSE); | |
JLabel label = new JLabel("Welcome to SAMBEKChat webEd(0.2b)"); | |
label.setFont(new Font("Monaco", Font.PLAIN, 27)); | |
JTextField login = new JTextField(10); | |
JPasswordField password = new JPasswordField(10); | |
JButton ok = new JButton("OK"); | |
// ok.setSize(50,50); | |
JButton cancel = new JButton("CANCEL"); | |
// cancel.setSize(50,50); | |
setLocationRelativeTo(password); | |
JPanel panel1 = new JPanel();panel1.setLayout(new GridLayout(12,1)); | |
panel1.setSize(500,500); | |
panel1.add(new JLabel("Разметка немножко в говно, я с ней разберусь...позже")); | |
panel1.add(label); | |
panel1.add(new JLabel(" Login:")); | |
panel1.add(login); | |
panel1.add(new JLabel(" Password:")); | |
panel1.add(password); | |
panel1.add(new JLabel(" IP:")); | |
JTextField ipField = new JTextField(10); | |
panel1.add(ipField); | |
panel1.add(ok); | |
panel1.add(cancel); | |
ipField.setFont(new Font("Monaco", Font.PLAIN, 20)); | |
login.setFont(new Font("Monaco", Font.PLAIN, 20)); | |
password.setFont(new Font("Monaco", Font.PLAIN, 20)); | |
jj = new JTextField(10); | |
panel1.add(jj); | |
jj.setEditable(false); | |
setContentPane(panel1); | |
ok.addActionListener(new ActionListener() { | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
Kek.login(login.getText(),password.getPassword(),ipField.getText()); | |
if (Kek.isConnected) {jj.setText(":) Загрузка..."); Kek.turn2(); } else { | |
jj.setText(":( Подключение не удалось "); | |
} | |
ok.setEnabled(true); | |
cancel.setEnabled(true); | |
} | |
}); | |
KeyListener kl = new KeyListener() { | |
@Override | |
public void keyTyped(KeyEvent e) { | |
} | |
@Override | |
public void keyPressed(KeyEvent e) { | |
if (e.getKeyCode()==KeyEvent.VK_ENTER){ | |
ok.doClick(); | |
} | |
} | |
@Override | |
public void keyReleased(KeyEvent e) { | |
} | |
}; | |
ipField.addKeyListener(kl); | |
password.addKeyListener(kl); | |
login.addKeyListener(kl); | |
cancel.addActionListener(new ActionListener() { | |
@Override | |
public void actionPerformed(ActionEvent e) { | |
System.exit(0); | |
} | |
}); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package v0_2b; | |
import javax.swing.*; | |
public class Graph2 extends JFrame { | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package v0_2b; | |
import java.io.DataInputStream; | |
import java.io.DataOutputStream; | |
import java.io.IOException; | |
import java.net.Socket; | |
import java.util.Arrays; | |
public class Kek { | |
static Socket socket; | |
static DataInputStream dataInputStream; | |
static DataOutputStream dataOutputStream; | |
static boolean isConnected = false; | |
static Graph g = new Graph(); | |
public static void main(String[] args) { | |
} | |
public static void login(String log, char[] pas, String ip){ | |
System.out.println(log); | |
for (char c : pas) { | |
System.out.println(c); | |
} | |
int hash = Arrays.hashCode(pas); | |
System.out.println(hash); | |
try { | |
socket = new Socket(ip,7788); | |
dataInputStream = new DataInputStream(socket.getInputStream()); | |
dataOutputStream = new DataOutputStream(socket.getOutputStream()); | |
dataOutputStream.writeUTF(log+":"+hash); | |
isConnected = dataInputStream.readBoolean(); | |
if(!isConnected){socket = null; dataInputStream = null; dataOutputStream = null;}; | |
} catch (IOException e) { | |
isConnected = false; | |
} | |
} | |
public static void turn2(){ | |
System.out.println("OK"); | |
g.setVisible(false); | |
g = null; | |
Graph2 g2 = new Graph2(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment