ActionPerformed problem

Hi all,

I have a GUI based roulette game with two classes a bet screen and a main menu screen i need to know how to say if a button is pressed in the bet screen to do its operations and then close and return to the main menu screen. This is a piece of the code

new ActionListener()

{

publicvoid actionPerformed( ActionEvent event )

{

BetScreen betScreen =new BetScreen();

betScreen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

betScreen.setSize(300,100);

betScreen.setVisible(true);

if(event.getSource() == BetScreen.oddButton)

{

betScreen.setVisible(false);

}//end if

}//end method actionPerformed

}//end method actionListener

);//end call to addActionListener

[1288 byte] By [Timmy_The_Turtlea] at [2007-11-27 1:00:32]
# 1

well, i don't know what is a BetScreen but if it is a class created by yourself you should add this to the constructor of the BetScreen

public BetScreen(ActionListener al)

{

for(int i=0;i<10,i++)//i'm just guessing

{

buttons.addActionListener(al);

}

}

and in the code:

new ActionListener()

{

public void actionPerformed( ActionEvent event )

{

BetScreen betScreen = new BetScreen(this); //the modyfied line

betScreen.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

betScreen.setSize(300,100);

betScreen.setVisible(true);

if(event.getSource() == BetScreen.oddButton)

{

betScreen.setVisible(false);

}//end if

if(event.getActionCommand().equals("Red 1"))//or whatever says the button of the betScreen

{

//whatever you had to do with it

}

}//end method actionPerformed

}//end method actionListener

);//end call to addActionListener

i hope this solves your problem

Cesar_Castroa at 2007-7-11 23:35:13 > top of Java-index,Java Essentials,New To Java...