Results 1 to 13 of 13
  1. #1
    becky is offline Member
    Join Date
    Jan 2009
    Posts
    13
    Rep Power
    0

    Default loop when there is no user-input

    hi all

    i've got a question:
    i program graphic applications e.g. where a user can press a button and then a joptionpane pops up and says "you have pressed a button".
    but there has to be an idle-loop in the source code anywhere, where the compiler waits for a user-input (e.g. press a button).
    i know that listeners "listen" if a button is pressed. but the compiler has to check anywhere IF this button is pressed....so can you please tell where i can find this loop in my source code?

    would be glad if you can help!!

    tom

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Is your program a Swing or AWT program? If so, you don't have to worry about this loop as the GUI takes care of this for you. You just have to respond to events, that's it.

  3. #3
    becky is offline Member
    Join Date
    Jan 2009
    Posts
    13
    Rep Power
    0

    Default

    it's a swing program. yes, i know it works that way but i want to know where i can find this loop because i want to understand how this works. so can you please tell me where i can find this loop in my source code?

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Seems to me this is not a thing to worry about. And also I've no idea that what you are trying to learn from there. You are trying looking into the Java API may be.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by becky View Post
    it's a swing program. yes, i know it works that way but i want to know where i can find this loop because i want to understand how this works. so can you please tell me where i can find this loop in my source code?
    It's not in your source code as it's buried deep within the Swing library. Rather than chase this zebra, I recommend that you go through the Sun Swing tutorial. If you want to learn more about Swing's underpinnings, then look at the book: Filthy Rich Clients.

  6. #6
    sakura030808 is offline Member
    Join Date
    Jan 2009
    Posts
    2
    Rep Power
    0

    Default

    you can add some codes below your button source
    you may use a condition
    while loop
    Last edited by sakura030808; 01-29-2009 at 07:57 PM.

  7. #7
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    i'm not too familiar with action listeners and gui's, but it seems like the topic creator is curious with multi-threading and how a program can have a continuous loop while other actions are able to take place. just my guess though.

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by emceenugget View Post
    ...but it seems like the topic creator is curious with multi-threading and how a program can have a continuous loop while other actions are able to take place. just my guess though.
    You're probably right. Still the best place to learn about the mechanisms of Swing as well as the nuts and bolts of how to use Swing are the Sun Swing tutorials. If the OP hasn't gone through these, that's the best place to start.

    Here are a few of the tutorials below. I recommend that you avoid using NetBeans to generate your Swing code (and I recommend that you avoid the NetBeans and Swing portion of the tutorials) until you get a solid foundation in Swing coding itself:

    Lesson: A Brief Introduction to the Swing Package (The Java™ Tutorials > Graphical User Interfaces)
    Lesson: Getting Started with Swing (The Java™ Tutorials > Creating a GUI with JFC/Swing)
    Lesson: Using Swing Components (The Java™ Tutorials > Creating a GUI with JFC/Swing)

    Good luck!

  9. #9
    becky is offline Member
    Join Date
    Jan 2009
    Posts
    13
    Rep Power
    0

    Default

    It's not in your source code as it's buried deep within the Swing library
    k, i see.
    i thought it would be just like in C/C++ where you always see the whole code of your program and where YOU have to tell the compiler what he has to do in idle-mode when there's no user input.
    anyway...THX A LOT for your answers!
    you've helped me a lot!

  10. #10
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quite interesting. Even in C/C++ how can you see whole code, if you are use library files(header files actually)?

  11. #11
    becky is offline Member
    Join Date
    Jan 2009
    Posts
    13
    Rep Power
    0

    Default

    Quite interesting. Even in C/C++ how can you see whole code, if you are use library files(header files actually)?
    Yes, of course...you're right :-)
    but what i wanted to say is that YOU have to tell the compiler where you want a loop so that the compiler waits for a user input (except from commands like scanf and so on, but if you're working with interrupts YOU have to write a loop for the compiler where he waits until an interrupt occurs).

  12. #12
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    becky, I can't get the way of your question. You mean JOptionPane.showInputDialog()
    Or maybe the JTextArea component?

  13. #13
    becky is offline Member
    Join Date
    Jan 2009
    Posts
    13
    Rep Power
    0

    Default

    becky, I can't get the way of your question. You mean JOptionPane.showInputDialog()
    Or maybe the JTextArea component?
    yes, for example. but it doesn't matter which components i am using. i just wanted to say that i am writing Swing programs.
    and i wanted to know where i can find the idle-loop in my java code where the compiler waits for a user input.
    but my question is already answered (thanks to "fubarable"):
    It's not in your source code as it's buried deep within the Swing library

Similar Threads

  1. how to get input from User
    By Alvaro in forum New To Java
    Replies: 7
    Last Post: 01-16-2010, 12:02 AM
  2. Multiple line user input
    By jointhelabel in forum New To Java
    Replies: 3
    Last Post: 10-26-2008, 03:41 AM
  3. who to take user input ,not by console...
    By Shyam Singh in forum New To Java
    Replies: 3
    Last Post: 06-13-2008, 11:09 PM
  4. Prompting user input of a string.
    By apfroggy0408 in forum New To Java
    Replies: 3
    Last Post: 03-09-2008, 07:23 PM
  5. cant take input from user
    By new_1 in forum New To Java
    Replies: 6
    Last Post: 12-25-2007, 08:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •