0

Why when I press the button it doesn't do anything?. It won't go to the next frame I want on a certain condition I put

if(e.getSource()==btn2)
    {
        if (txt5.getText=="20")
        {
           Accept a = new Accept();
           a.setAccept();
           dispose();
        //}
        if (txt5.getText=="5")
        {
           Reject a = new Reject();
           a.setReject();
           dispose();
        }
        if(txt.getText=="10")
        {
           Reserve a = new Reserve();
           a.setReserve();
           dispose();
        }

    }
Gabriel's Messanger
  • 3,213
  • 17
  • 31
  • Have you put comment `//}` on purpose? If so, the code won't even compile. – Gabriel's Messanger Oct 06 '15 at 17:23
  • Other than the obvious syntax error (`//}`) there's no way to answer this question currently. How are you setting the text? What's the source of the event? If you put a breakpoint in this method does it get hit? – Mike G Oct 06 '15 at 17:23
  • paste the whole code with the ActionListener ... – chenchuk Oct 06 '15 at 17:24
  • 2
    Even though this doesn't compile, I'm guessing it is a duplicate of http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java . – VGR Oct 06 '15 at 17:26
  • i already remove the // and paste it at actionPerformed but it still wont work – Zoey Oct 06 '15 at 17:31
  • The code you show does nothing - each 'if' block creates a new object called 'a', then calls a setXxx() method on it, then discards 'a'. Also, what is txt5 ? Do you mean txt5.getText or txt5.getText() ? And comparing it to a string literal probably does not do what you expect. – FredK Oct 06 '15 at 17:40
  • `why when i press the button it doesn't do anything` - add debug code to see if the listener code is being executed. Don't use `==` for String comparisons. Use the `equals(...)` method. – camickr Oct 06 '15 at 18:20

0 Answers0