public class War extends JFrame{
String serverAddress;
int width;
int height;
int tileWidth;
int tileHeight;
WarPanel panel;
JPanel jpanel;
Launch lPanel;
ServerSelect sPanel;
public War(){
showLaunch();
}
public static void main(String args[]){
new War();
}
public void init(String ip){
jpanel.removeAll();
serverAddress = ip;
panel = new WarPanel(serverAddress);
jpanel = (JPanel)getContentPane();
jpanel.add(panel, BorderLayout.CENTER);
BufferedImage cur = new BufferedImage(1, 1, BufferedImage.TYPE_4BYTE_ABGR);
Cursor customCursor = Toolkit.getDefaultToolkit().createCustomCursor(cur,new Point(0,0),"");
setCursor(customCursor);
setFocusable(true);
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
setSize(800,800);
setVisible(true);
System.out.println(hasFocus());
panel.init();
panel.game();
}
public void showLaunch(){
lPanel = new Launch(this);
jpanel = (JPanel)getContentPane();
jpanel.add(lPanel, BorderLayout.CENTER);
System.out.println(hasFocus());
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
setSize(800,800);
setVisible(true);
}
public void showServerSelect(){
jpanel.removeAll();
sPanel = new ServerSelect(this);
jpanel = (JPanel)getContentPane();
jpanel.add(sPanel, BorderLayout.CENTER);
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
setSize(800,800);
setVisible(true);
}
public void showGame(String address){
lPanel = null;
sPanel = null;
init(address);
}
}
🔒 Locked
JPanel Focus
Advertisement
Original Post
Yeah this is a rare thing for me 2. I never really get along with the Java GUI features lol anyway thx, ill check my code again :) One more thing, if u were tying to do wat im doing, would u go about it the same way? Have 3 JPanels, show one, then remove that from frame and show the next, then remove that from the frame and show the next?? Or is there a more appropriate way?
Haha its funny actually, this weekend i felt lyk having a little brake from the actual game programming and have an easy programming weekend, just make the mode selection screen (Multiplayer single player) and then make a Server Selection Screen, lol all in all the networking and everything took 20 mins, but ive been trying to fix this for lyk 12 hours lol
Haha its funny actually, this weekend i felt lyk having a little brake from the actual game programming and have an easy programming weekend, just make the mode selection screen (Multiplayer single player) and then make a Server Selection Screen, lol all in all the networking and everything took 20 mins, but ive been trying to fix this for lyk 12 hours lol
Ok it works perfectly if i dont call the showLaunch and showServerSelect. It straight away calls show game, it shows the game, the game handles all the events etc etc works perfectly. So i still think they problem is that i call showGame from a method in the ServerSelect panel, so is the game running from the ServerSelect panel?
Im soo confused lol
Im soo confused lol
public void showServerSelect(){ //jpanel.removeAll();//WE'LL DO THIS LATER sPanel = new ServerSelect(this); //jpanel = (JPanel)getContentPane();//jpanel IS ALREADY REFERENCING THE CONTENT PANE jpanel.removeAll(); jpanel.add(sPanel, BorderLayout.CENTER); //setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );//ALREADY SET IN init() //setSize(800,800);//ALREADY SET IN init() //setVisible(true);//ALREADY SET IN init() sPanel.requestFocus();//THIS IS WHAT YOU NEED }Hope this helps... and just for reference, please try and spell out your words. It makes you sound more intelligent. Especially when you are trying to misspell on purpose. 'lyk' != 'like'
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement