• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Swing validation

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I finished this program and when I tested the first code group at the bottom validating the combobox entries it worked fine. Now this program freezes when I touch the radio buttons or comboboxes. The last block of code is supposed to immediatley revert back to the first selection in the array when the same position is picked in another combobox. I have looked it over and have no idea why it just freezes. The problem has to be in the lat bit performing the validation because it was fine before.

 
Marshal
Posts: 27367
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In your action listener you are changing a combo box, which causes the action listener to be called, which then changes a combo box, which causes the action listener to be called, which then changes... you get the picture I hope.

It's a pity you wrote 500 lines of code before testing anything; try not to do that in future.
 
Dale Herring
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
MMM okay. Well I've figured out that it only breaks around the fifth box check but not sure why it's affecting the radio buttons and why it works until that point. Also refer to earlier post, I had checked the first block and just like now it did work, it just does not work all teh way through.
 
Marshal
Posts: 76408
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried your code and it hung on the first radio button click.

Your post sounds like you tying yourself in knots. I suspect you are going to have to delete a lot of that code (> 95%) and see what happens.
I do not like the multiple ifs. You are throwing an inappropriate Exception because none of those Strings is null. You should not be catching unchecked Exceptions. You need to alter your design and to check the contents of the fields when you push any of the buttons.
You should also not make a display class implement action listener. Apply different listeners to the different components. Or implement a Component, maybe a menu item, maybe a button, which checks that the fields contain text and then compiles the team.

Can you add some sort of listener to the combo boxes which removes the selected position from all the other boxes?
 
Paul Clapham
Marshal
Posts: 27367
88
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would suggest you would have a lot less code if you used an array rather than nine variables. And also, don't call setSelectedIndex(0) if index 0 is already selected -- that may be causing the infinite loop.

You should also avoid using == to compare String values, although you are somehow getting away with it here. Use the equals() method instead.

 
Campbell Ritchie
Marshal
Posts: 76408
364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:. . . avoid using == to compare String values, although you are somehow getting away with it here. . . .

A long time ago when I was working for the MSc, we had one chap on the course who had written a lot of C#, where (I think) == is overloaded on Strings. So he used == throughout and it worked nicely, because all the Strings were literals which were automatically interned, or assigned from those literals. “It works all right until I serialise it, Campbell, but it won't work afterwards.”

Even at that tender age I realised there was a problem because the deserialised Strings were being compared to the original literals with == and that wouldn't work; they were now new objects. Changing every occurrence of == to equals sorted out the problem.
 
Eliminate 95% of the weeds in your lawn by mowing 3 inches or higher. Then plant tiny ads:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic