Writing own GUI for the game.

I want to write simply 2D multiplayer game, but not here is my problem. Problem is with GUI;/.

I want to buttons with my Icons, so I create them in this way:

start =new JButton();

start.setFocusable(false);

start.setBorder(null);

start.setContentAreaFilled(false);

start.setIgnoreRepaint(true);

start.setIcon(new ImageIcon("c:\\images\\start.png"));

start.setRolloverIcon(new ImageIcon("c:\\images\\start_mouse.png"));

start.addActionListener(this);

More, I create own RepaintManger, which doesnt repaint my components (I do it menuLoop with method:

frame.getLayeredPane().paintComponents(g);

Where frame is reference to JFrame FullWIndow Screen and g Graphics2D.

It's works fine. But when I "change" my menu with:

screen.getFullScreenWindow().getLayeredPane().removeAll();

menu = loginMenu.getMenu();

menu.setLocation((screen.getWidth() - menu.getWidth()) / 2,

(screen.getHeight() - menu.getHeight()) / 2);

screen.getFullScreenWindow().getLayeredPane().add(menu,

javax.swing.JLayeredPane.MODAL_LAYER);

// menuLoop(); app returns to gameLoop and draw there menu all the time

setGameState(GameStates.GAME_MENU);

menu is JPanel, and method loginMenu.getMenu(); returns JPanel with created buttons and text fields (maybe this is not good method to swich menus - which will be better? - but it works). Here is the problem. With TextFields, when i type in them fast my application freezes.

I even set setIgnoreRapaint(true) in this fields, but this doesnt help.

Is the problem in Threads? I think so, but I don't know how to eliminate it.

Thanks for any help.

[2063 byte] By [akakusa] at [2007-10-2 0:13:00]
# 1
Sorry for my errors :/. I've just noticed them and can't edit my post. But I hope, You understand my english ;)
akakusa at 2007-7-15 16:14:29 > top of Java-index,Other Topics,Java Game Development...
# 2
If your app freezes when you type input into a text box, I'd expect the problem is when the event handlers for that box.How fast are you typing? If this is an action game, Swing may not be the best choice. GUI widgets in general may not be the best choice.
paulcwa at 2007-7-15 16:14:29 > top of Java-index,Other Topics,Java Game Development...
# 3
Thanks for reply ;)It freezes when I type above 2 - 3 chars per second. It will be simple multiplayer turn strategy game. I want to use buttons for orders and text field for simple chat. When swing is bad choice, what should I use?
akakusa at 2007-7-15 16:14:29 > top of Java-index,Other Topics,Java Game Development...
# 4
If it's turn-based, and there isn't a lot of interaction of individual parts, I'd think that Swing is fne, although others may disagree with me.What are in your event handlers?
paulcwa at 2007-7-15 16:14:29 > top of Java-index,Other Topics,Java Game Development...
# 5

For TextFields I haven't implemented any event handler. I use own only in Buttons (they works I call methods with arguments from text fields). For example: public void actionPerformed(ActionEvent e) {

if (e.getSource() == reset) {

login.setText("");

pass.setText("");

//host.setText("");

}

else if (e.getSource() ==logIn) {

server.tryLogIn(new String(login.getText()), new String(login.getText()));

}

}

akakusa at 2007-7-15 16:14:30 > top of Java-index,Other Topics,Java Game Development...
# 6

Can you create a simple Swing app with a text box and nothing else, and type so fast that it freezes?

If so perhaps it's a problem with Swing (though I doubt it) or maybe you're typing control characters?

If not, then again I suspect event handlers. You must have an event handler that deals with the input you're typing in. The only ones you've shown are for clearing and logging in; what do you use for normal game play when it freezes?

paulcwa at 2007-7-15 16:14:30 > top of Java-index,Other Topics,Java Game Development...
# 7

I've just found error :). I tried do repaint together with reading the event dispatched queue.

I had:

frame.getLayeredPane().paintComponents(g);

I have now:

Runnable doRepaint = new Runnable() {

public void run() { frame.getLayeredPane().paintComponents(g); }

};

try {

SwingUtilities.invokeAndWait(doRepaint);

} catch(InterruptedException ex) { }

catch(InvocationTargetException ex) { }

Thanks for help Paul :)

akakusa at 2007-7-15 16:14:30 > top of Java-index,Other Topics,Java Game Development...