Instantiating objects from within listener methods!
Hi Everyone,
I have just finished writing a nice GUI for an application that I am developing. On the GUI there are several JButtons and several JComboBoxes. I have written listener methods for all the afore mentioned, except for one JButton.
The offending JButtons listener method needs to create an object from another entirely different class and I am having trouble doing this.
e.g.:
class GUI(){
.....
JButton buttonCalc = new JButton("Calculate);
.....
GUI()
{
.....
.....
Frame.add(buttonCalc)
.....
.....
.....
.....
buttonCalc.addActionListener(this);
.....
public void actionPerfromed(ActionEvent e)
{
if(e.getActionCommand().equals("Calculate"))
{
//Create an Object from a totally differnet class.
//e.g.:
//CalculateX CalcX = new CalculateX();
}
if(e.get.....
{
....
.....
}
}
class CalculateX{
.....
....
CalculateX{
......
......
}
}
I have tried code like the above but have so far found no success. The above code results in an error message similar to "Class CaclculateX not found in Class GUI".
I get the feeling that this is an issue of scope, however I have no idea how to resolve this.
Any help in creating an object of a different class from within the Listener method of another class (as indicated above) will be greatly appreciated.
Thanks
A-S

