K
K
Kirill Romanenko2014-07-10 13:36:44
Java
Kirill Romanenko, 2014-07-10 13:36:44

Why does this line not work, in principle, without errors?

Tell me guys. I am learning to build forms in Java: I wrote for the switch
onna.setName(onna.isEnabled()?"1000":"2000");
it seemed to me that in the On position it should be called 1000, but vice versa - 2000. But there is no name at all! Just the button and the icon remained. Everything works, no compiler errors..
------------------------------------ -------------------------------------------------- ------------------------------------------------
This option also passed without errors, but did not give a visual effect:
if (onna.isEnabled())
{
onna.setName("1000");
}
onna.setName("2000");

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
GavriKos, 2014-07-10
@GavriKos

Debugger looked - these functions are generally called? Are they written in the switch event handler?

C
Calc, 2014-07-10
@Calc

And the state of the button is changed through setEnabled?
Or are you just poking at it?
Are you using swing
After changing the name, do you call revalidate or repaint?

S
Serzhh, 2014-07-10
@Serzhh

Try:
onna.setName((onna.isEnabled()) ? "1000" : "2000");
Or what would be clearer:
String onnaName = (onna.isEnabled()) ? "1000" : "2000";
onna.setNmae(onnaName);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question