Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

java problem

  • 23-11-2003 04:06PM
    #1
    Closed Accounts Posts: 1,325 ✭✭✭


    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.


Comments

  • Closed Accounts Posts: 358 ✭✭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]


  • Closed Accounts Posts: 1,325 ✭✭✭b3t4


    no joy CH

    Thanks,
    A.


  • Closed Accounts Posts: 1,325 ✭✭✭b3t4


    fixed the problem,

    A.


Advertisement