I can't come up with logic for certain actionListeners for my program, mainly the ones that will run the game.

I want to go through my actionListeners one by one.

First actionListener I want to work with is the one that will be setting the order of pictures that the user has to guess to win.

In my interface class I have a menuBar. I want to use the New action to start the random order.

private class NewListener implements ActionListener {
		public void actionPerformed(ActionEvent arg0) {


Should i do something like

int v = 0;
     for (int i = 0; i < 4; i++)
       v = v * 10 + (int)(Math.random() * 6 + 1);
     return v;

I'm truly confused.. I'm not asking for handouts I just need to see some sort of logic on this.

I also have problems with the other actionListners.

If you would like to see all of my code let me know.

My project is due this Tuesday so I want to get the actionListeners done tonight if possible.

Yes I've seen others sources code on the internet but it's not quite matching what I want and I can't understand it.

Any help please, Thank you.

Doesn't seem like anyone wants to help, but I'm just going to put this out there.

These methods handle the random images that will be selected by A.I that the user has to guess

public void randomChoices() {

		programChoice = new int[NUM_NEEDED];
		rand = new Random();
		for (int i = 0; i < NUM_NEEDED; i++) {
			programChoice[i] = rand.nextInt(4);


	 * Maps programChoice to an programImage depending on what number
	 * programChoice ==
	public void mapImage() {

		programImage = new ImageIcon[NUM_NEEDED];
		for (int i = 0; i < NUM_NEEDED; i++) {
			programImage[i] = new ImageIcon();
			if (programChoice[i] == 0) {
				programImage[i] = snoopy;
			} else if (programChoice[i] == 1) {
				programImage[i] = charlie;
			} else if (programChoice[i] == 2) {
				programImage[i] = woodstock;
			} else {
				programImage[i] = linus;

This listener simply takes the user input and sets the button to a Icon of users choice

private class ButtonListener extends Image implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			 * Added a for loop so I can address which array button was pressed.
			for (int i = 0; i < NUM_NEEDED; i++) {
				if (selection.equals("Snoopy")
						&& choiceButton[i].equals(e.getSource())) {
				}  if (selection.equals("Charlie Brown")
						&& choiceButton[i].equals(e.getSource())) {

				} if (selection.equals("Woodstock")
						&& choiceButton[i].equals(e.getSource())) {

				}  if (selection.equals("Linus")
						&& choiceButton[i].equals(e.getSource())) {

				 if (selection.equals("Pick a Character")
							&& choiceButton[i].equals(e.getSource())) {


My Problem is comparing the choices the person set on the buttons to what the A.I has chosen.

The A.I random choices take place in my Management class.

The listener takes place in another

I have a solve button for when the user sets his images down on the four buttons and is ready to click solve, the solve button is suppose to compare what he put into the buttons and compare it to the programChoices which are int type.

This is the solve listener, I tried a couple of things. The one I want to see if it works is sending choiceButton as an argument to the ColorManagement Class but doesn't work. Not sure what I'm doing wrong the suggestions come up as make a method that accepts a JButton[] in the Panels class.. Which I don't want to do because I have a Constructor and method that accepts JButton[] as an argument in the ColorManagement class.

private class SolveListener extends ColorManagement implements ActionListener{
		public void actionPerformed(ActionEvent e) {
			ColorManagement cm = new ColorManagement();
			for(int i=0; i<NUM_NEEDED; i++){


Greatly appreciated to anyone that helps. Projects due tmw and still struggling with logistics.

This article has been dead for over six months. Start a new discussion instead.