having issues getting my action listener to listen to my combo boxes

So, i have my final project for my programming class and I'm making pong. This is ten times harder than i thought it would be, especially since our teacher left us on do loops and then dropped this project on us. Anyway, i need my ComboListener to update the variables and send them back to the interface so it can display a play button. unfortunately it isn't updating the variables and my friends having the same issue, some guidance on this would be nice because our teacher isn't much help. here's what i have so far.

I was getting null pointer exception before, but i was able to get past that so it displays everything. Still, it wont change the variable for speed and int in the JFrame class (ponginterfaceviewer). Some tips would be nice or somewhere on the web that i can read would be really helpful thanks (by the way, i put a print statement in to check the variable, but i want the button to go there in the end).

You have a bit of code to go through, and I can't state that I've gone through it all, and also I'm at work and without a useable Java compiler, but let me see if I can tease anything out for you.

In your PongInterfaceViewer

First off, I like how you are trying to separate your view and your control.

You're getting your player and your speed from pong4 at program creation and by polling, but not in an event-driven way, though this can work, except,...

You've got a while (true) game loop ( in your main method at while (speed !=5 && player != 2)) which usually doesn't play nice with Swing's EDT. Better to use a Swing Timer for a game loop, however,...

I'm not even sure why you're polling the comboboxes as you do and would probably use a different approach entirely. Wouldn't you only display the comboboxes and get user input prior to each new game? If so, then there's no need to poll them and you certainly wouldn't want to extract the speed and player from them on program creation as you do or even giving them a listener. Rather you might consider not adding listeners to the combo boxes at all but displaying them as you're doing or in a dialog window, and then give the gui a "Start Game" button and an ActionListener for the button, and only get the selected information from the combo boxes when the player presses this button. Then get after you've gotten this information get rid of the this introductory portion of your GUI and start your game proper.

wow thanks for the speedy response and you shone a light i hadn't even thought of, thank you. Your right ill try what you said and as far as extending the class goes, I took an example from our classes text books and tried to morph it around my pong program. The end result gave me this and ill post back when i try it out.

well i know the actionlistener is running, because i put in a run statement at the end of the listener to print the variables and its printing, but now it wont change the variables to what i want them for each. I'm going to post my current listener.

well i know the actionlistener is running, because i put in a run statement at the end of the listener to print the variables and its printing, but now it wont change the variables to what i want them for each. I'm going to post my current listener.

Maybe I didn't stress highly enough, but my most important point in my post above was point 4, that your design is off, that you shouldn't even be adding ActionListeners to your combo boxes, but that instead you should simply extract the data from the combo boxes when the user presses a button indicating that he's done setting them.

I think I would create a class that held both JComboBoxes and had two public methods, getSpeed() and getPlayer() that returned the selected item from the speed and player combo boxes respectively. I wouldn't have the loop or polling as you do. I'd possibly display this class in a JOptionPane or other modal JDialog and when the dialog was complete, extract the player count and speed via the two public methods.

Again, i copied this model from our java book, but i tried skewing the design when i really had no idea what i was doing. Now, i feel like im getting close. Thanks for working through this with me. Plus, my last resort is just using JOptionPane.showInputDialog("enter player here");. Which I might have to move on soon, but this sounds pretty close to being ironed out, ill post back soon when i remodel my program.

So, I fiddled around with the combo box thing and came to the conclusion that it is ten times harder than I wanted this to be. My program came to this (right now it just echo prints the variables, but it will pass them on to my actual Pong class).

You can still use JComboBoxes and use a JOptionPane to simply get user information. For instance you could create a class that holds two JComboBoxes along with two getter methods to extract the selected items from the combo boxes:

Ok, I see what you were trying to tell me before and thank you for helping along with this process. I have one final question though, How can I run my actual game after the user interface is done? In the run class you posted it only called on the interface to compile all of these components together. Should I put a run statement at the end of the GUI method or should I create a second actionListener to track a play button instead of the "show combo" button?