aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/ui/MainFrame.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/ui/MainFrame.java')
-rw-r--r--src/main/java/ui/MainFrame.java92
1 files changed, 82 insertions, 10 deletions
diff --git a/src/main/java/ui/MainFrame.java b/src/main/java/ui/MainFrame.java
index 0eac906..cfef0ba 100644
--- a/src/main/java/ui/MainFrame.java
+++ b/src/main/java/ui/MainFrame.java
@@ -5,31 +5,39 @@ import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
+
+import models.CONSTS;
+
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.Color;
import javax.swing.JButton;
import javax.swing.JTextArea;
import java.awt.Font;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.nio.ByteBuffer;
+import java.nio.channels.SocketChannel;
import java.awt.BorderLayout;
public class MainFrame extends JFrame implements Runnable {
- /**
- * Launch the application.
- */
+
+
+
public static void main(String[] args) {
MainFrame frame = new MainFrame();
frame.setVisible(true);
}
-
- /**
- * Create the frame.
- */
+ public ByteBuffer readBuffer=ByteBuffer.allocate(1024);
+ public SocketChannel client;
public LoginPanel loginPanel=null;
public ChooseOpponentPanel chooseOpponentPanel=null;
GamePanel gamePanel=null;
+ public long userId=-1;
public MainFrame() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 727, 429);
@@ -39,20 +47,84 @@ public class MainFrame extends JFrame implements Runnable {
getContentPane().setLayout(new BorderLayout(0, 0));
add(loginPanel,BorderLayout.CENTER);
setVisible(true);
+ this.addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e)
+ {
+ System.out.println("EXITED");
+
+ try {
+ client.close();
+ Thread.sleep(500);
+ } catch (Exception e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ System.exit(EXIT_ON_CLOSE);
+ }
+
+ });
+
+ try {
+ client=SocketChannel.open(new InetSocketAddress(CONSTS.socketPort));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
new Thread(this).start();
}
@Override
public void run() {
while(true) {
try {
- Thread.sleep(500);
- System.out.println("testClient");
- } catch (InterruptedException e) {
+
+
+
+
+
+
+
+ } catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
+ public SocketChannel getClient() {
+ return client;
+ }
+ public void setClient(SocketChannel client) {
+ this.client = client;
+ }
+ public LoginPanel getLoginPanel() {
+ return loginPanel;
+ }
+ public void setLoginPanel(LoginPanel loginPanel) {
+ this.loginPanel = loginPanel;
+ }
+ public ChooseOpponentPanel getChooseOpponentPanel() {
+ return chooseOpponentPanel;
+ }
+ public void setChooseOpponentPanel(ChooseOpponentPanel chooseOpponentPanel) {
+ this.chooseOpponentPanel = chooseOpponentPanel;
+ }
+ public GamePanel getGamePanel() {
+ return gamePanel;
+ }
+ public void setGamePanel(GamePanel gamePanel) {
+ this.gamePanel = gamePanel;
+ }
+ public ByteBuffer getReadBuffer() {
+ return readBuffer;
+ }
+ public void setReadBuffer(ByteBuffer readBuffer) {
+ this.readBuffer = readBuffer;
+ }
+ public long getUserId() {
+ return userId;
+ }
+ public void setUserId(long userId) {
+ this.userId = userId;
+ }
}