开发者

java gui and logic

it s 3 hours i m tring to understand a thing but no success...

the problem is:

i have a class Gui( a client) with a main for a cardgame. the Gui has a main that has in an invokelater a Runnable where the logic ( a separate class managing the gamesession) runs and some methods to manipulate the order of the cards.

public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                PokerClientGui gui = new PokerClientGui();
                gui.setVisible(true);
                PokerClient pokerClient = new PokerClient(gui);

                pokerClient.gameSession();
            }
        });
}

The lo开发者_运维技巧gic is created in the main of the Gui passing the Gui itself to the logic. As far as i am proceding in the program there are no problems since all the objects/strings sent from the server to the client logic are received and for example the Hand is passed to the gui and displayed correctly. The problem comes now: i want to pass from the gui to the logic, the manipulated hand to send it to the sever via method of the logic class.

Since this function is called by the event mouse on the Gui (and not in the main of the Gui) i have no handle to the logic object so i can t use its sending objects method. I tried changing to static the method of the logic that sends and i made statics also the member involved in sending things on the socket.....

it doesn t send anything ..... it s not a problem of something wrong and i try to catch the exceptions (and nothing comes from them)

where m i wrong? what i am missing ? how should i bind the gui and the logic?


Perhaps you could create an event queue in your Runnable() class, and pass it to both your gui and your client constructors.

The client would add events for the GUI to display, and the GUI would add events for the client to process. It might be easier with two queues, one for each direction, rather than re-using a single channel for both directions.

Then your GUI and your client would add the event queue from this object into the list of things to 'check' when waiting in their event loops. When an event comes from the other object, it wakes the current object to do processing, same as events from the server or the user.


In place of creating the object of PokerClientGui in main class u better create its object directly in the PokerClient object and access its object gameSession() .

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜