-2

When I press the button, the text field doesn't update and every time it shows 20000.

The task is to choose from a combo box and then the text field will show you a number.

if STUDIO , Pb. show 10000
if F3 , pb shows 20000

String typoo = typo.getSelectedItem().toString();
int pbb = 0 ;
if (typoo == "Studio") {
    pbb = 10000;
} 
else if (typoo == "F3") {
    pbb = 20000;
}

JButton btnNewButton = new JButton("UPDATE");
btnNewButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        pb.setText(String.valueOf(pbb));
    }
});
andrewJames
  • 19,570
  • 8
  • 19
  • 51
MrHaouari
  • 1
  • 1
  • 4
    Don't use `==` to test for string equality, use the `equals()` method instead, for example: `if (typoo.equals("Studio")) {`. To ignore letter case you can use: `if (typoo.equalsIgnoreCase("studio")) {`. – DevilsHnd - 退職した Mar 12 '23 at 22:45

1 Answers1

-1

the if statements should be inside the actionPerformed() method and use the function String.equals() to compare Strings

Hakim
  • 11
  • 1
  • 7