Sockets and JFrames problem
Hi, I'm new here and I have a problem about Java SE. The thing is that I'm coding a multiplayer chessgame through internet, before the game starts, there are some other JFrames (to choose ip, port, white or black pieces,..) until it reaches the Frame with the board and it's pieces.
So the DatainputStream i read has to be in a loop becuase i don't know when the other user might make a move.
Code:
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Intro i = new Intro();
}
}
For example that's theMain class that gets an instance of the intro Frame. Then this intro Class when a button is pressed gets an instance of another Class called Menu which is used to fill out the port, ip, etc. Then with a button i calls the Game class that contains all of the code.
Code:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here
dispose(); // To dispose the last Frame
Game j;
JFrame frame = new JFrame("Game - Server");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
j = new GameServer (frame);
j.createAndShowGUI();
j.connect();
}
The connect method is simple:
Code:
server= new ServerSocket(5000);
s=servidor.accept();
os=s.getOutputStream();
is=s.getInputStream();
dis=new DataInputStream(is);
dos=new DataOutputStream(os);
connection = true;
while(connection){
// All the dis.reads...
}
But th problem is that when the Game class frame opens i doesn't show anything, but if I declare the variable 'j' inside the static void main in Main class it seems to word perfectly.