Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

loop in a JFrame  RSS feed

 
james kinyua
Greenhorn
Posts: 28
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is it possible to implement for loop in JFrame
 
Stephan van Hulst
Saloon Keeper
Posts: 7712
141
  • Mark post as helpful
  • send pies
  • 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.
 
Campbell Ritchie
Sheriff
Posts: 55333
157
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Posts: 55333
157
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Posts: 55333
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't know. Surely the GUI Builder in NetBeans will do any centring for you?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!