Discussions
Categories
Groups
Advertisement
Child Item
Home
Topics
Technology & Internet
Software & Web Development
Development
java problem
b3t4
Hey people,
Really hope you can help me out.
I've a JMenu and an actionPerformed method listening for the ActionEvent. In the actionPerformed method I have different if statements relating to the different getActionCommand.
//simplified look at things
if(g.getActionCommand == "Generate File")
{
//create a file
}
if(g.getActionCommand == "Read File")
{
Election newElection = new Election();
//add stuff from the file to the newElection object
}
//another menu option
if(g.getActionCommand == "Something else")
{
//try to use the altered newElection object
}
My problem is that in the thrid if statement I can't do anything with the altered class as I had hoped. newElection as far as it is concerned is empty of any data added in the Read File if statement. However, I want the scope of the newElection class to be extended to the next if statement but I am really unsure on how to do this. I tried placing the Election newElection = newElection() outside the if statements but no luck. I have looked into the idea of clones but I'm at a bigger loss as to what to do. I'm not even sure if what I want is possible.
Any help would be really appreciated,
Thanks,
A.
Find more posts tagged with
Quick Links
All Categories
Recent Posts
Activity
Unanswered
Groups
Best Of
Advertisement
Advertisement
Comments
CH
how about...
[php]
public void actionPerformed()
{
Election newElection = null;
//simplified look at things
if(g.getActionCommand == "Generate File")
{
//create a file
}
if(g.getActionCommand == "Read File")
{
newElection = new Election();
//add stuff from the file to the newElection object
}
//another menu option
if(g.getActionCommand == "Something else")
{
if(newElection != null)
//try to use the altered newElection object
else
//"Read File" has not been called
}
}
[/php]
b3t4
no joy CH
Thanks,
A.
b3t4
fixed the problem,
A.