• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

loop in a JFrame

 
Greenhorn
Posts: 28
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is it possible to implement for loop in JFrame
 
Saloon Keeper
Posts: 15727
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can not implement a for loop. 'for' is a keyword.

You need to be more specific what you want to achieve.
 
Marshal
Posts: 79943
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can write a for statement almost anywhere. But writing it in a display class looks like possibly poor design to me.
 
james kinyua
Greenhorn
Posts: 28
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i want to convert this loop into a jframe and am not sure how to go about it








 
Campbell Ritchie
Marshal
Posts: 79943
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can in theory run such code anywhere. But why? A frame is intended for displaying things, not for running loops. If you simply run that loop, you will be asking for information much faster than you can write in the fields.
What you might do is add listeners to text fields, or to buttons. I think you can add action listeners which are fired when you push the enter key on a text component. You can have a label where you set the text something like

Enter In Time No 123

adjacent to a text field where you can enter the time. You can use the enter key on the text fields or a button to fire an action.

Have you got the logic for that loop working correctly? Why have you got an empty catch statement? That is dangerous because Exceptions can occur and you would never know. Don't even think about a GUI until you have that loop working correctly.
 
james kinyua
Greenhorn
Posts: 28
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, i had the idea but i never thought it would be possible in a button.
i have another problem when i try to add a button in the GroupLayout.



Also how do i center the button?
 
Campbell Ritchie
Marshal
Posts: 79943
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't know. Surely the GUI Builder in NetBeans will do any centring for you?
 
What do you have in that there bucket? It wouldn't be a tiny ad by any chance ...
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic