Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

java problem

Options
  • 23-11-2003 4: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