scruffles.net subscribe
Friday, January 12, 2007

You're creating a button that toggles back and forth between two states. You want the button's text to change depending on the state it's in. Ignoring the obvious usability issues involved, how would you go about implementing that? It's a simple problem, so it should have a simple answer:

button.setText(isInWhateverState ? "text 1" : "text 2");

I just ran into some code that works a little different than one might expect. It uses two buttons, each with different text. Each button has a complicated set of lazy initializers and it's own listeners. The two buttons are on a panel with a CardLayout. Pressing either button switches the card layout making the other visible.

Sometimes writing really bad code takes a bit of creativity.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]



<< Home

Bryan