Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: Text file to text area and Radiobuttons?

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb solved.

    I have some java questions. I made a game that has two balls. One that you control and one that moves around the screen. You have to avoid getting hit by the moving ball.
    So far, I just have a ball moving around and the one that you control. When you get hit by the moving ball, I made it so that the game redirects to JPanel. This jpanel contains questions (education purposes).
    My question is: how do I load a text file with questions in this format:
    the text file:

    What is bob + 2?
    A) x5
    B) c8
    C) 1337
    D) 15555

    What is new+bie?
    A) Newbie
    B) noob
    C) loser
    D) donaldmax

    and so on. i have around 35 questions.

    So far the panel i made has 4 radiobuttons on a gridlayout of 5,1. the 4 radio buttons do this right now:

    A)
    B)
    C)
    D)

    I am trying to put a text area containing a question from the question.txt file and the four answer choices in the corresponding radio buttons(a,b,c,d). how would i be able to do this?
    Also how do i make the ball move faster? (the moving one) every 20 seconds. im using a thread currently. im a newbie at java :/



    thank you! any comments and tips are appreciated. if you need more information please post and say so !

    solved!
    Last edited by donaldmax; May 27th, 2011 at 10:48 PM. Reason: solved


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Text file to text area and Radiobuttons?

    I get 11 errors when I compile this code. Is that what I should expect?

  3. #3
    Junior Member
    Join Date
    May 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Text file to text area and Radiobuttons?

    this should compile. i just commented out the text reader stuff. i have images but you dont really need that. should be able to run D:
    Last edited by donaldmax; May 28th, 2011 at 12:49 PM.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Text file to text area and Radiobuttons?

    commented out the text reader stuff
    You should write a small testing program that does just the text reader stuff to get the techniques and classes to work like you want it to. Then move the code into the larger program.

  5. #5
    Junior Member
    Join Date
    May 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Text file to text area and Radiobuttons?

    how would you get the contents of each line of the text file?

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Text file to text area and Radiobuttons?

    The Scanner class would be an easy way for a simple file.
    The other file reading classes get more complicated.

  7. #7
    Junior Member
    Join Date
    May 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Text file to text area and Radiobuttons?

    i will look into the scanner class. does anyone know how to make a ball (uses thread) to move a bit faster every 20 seconds?

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Text file to text area and Radiobuttons?

    I made a game that has two balls.
    How are you controlling the ball movement now?

  9. #9
    Junior Member
    Join Date
    May 2011
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Text file to text area and Radiobuttons?

    one is being controlled with arrow keys. other one is controlled, look at mainpanel. my game is my mainpanel.

  10. #10
    Forum old-timer
    Join Date
    Nov 2008
    Location
    Faversham, Kent, UK
    Posts
    472
    My Mood
    Mellow
    Thanks
    4
    Thanked 58 Times in 54 Posts

    Default Re: Text file to text area and Radiobuttons?

    Quote Originally Posted by donaldmax View Post
    i will look into the scanner class. does anyone know how to make a ball (uses thread) to move a bit faster every 20 seconds?
    If you're using a timer in the thread, reduce the timer delay; if you're just sleeping the thread in a loop, reduce the sleep time.

    Incidentally, when posting code, please use the Java Naming Conventions - class names begin with an uppercase letter, method and variable names begin with a lowercase letter. If you don't follow the convention, people will be confused reading your code, and people like me won't read it at all.

Similar Threads

  1. Replies: 8
    Last Post: March 25th, 2011, 02:34 PM
  2. Display in a text area
    By susieferrari in forum Java Theory & Questions
    Replies: 21
    Last Post: March 22nd, 2011, 09:56 AM
  3. java program to copy a text file to onother text file
    By francoc in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: April 23rd, 2010, 03:10 PM
  4. Jigloo help to produce a text area which only scrolls down
    By rtumatt in forum AWT / Java Swing
    Replies: 0
    Last Post: February 2nd, 2010, 06:09 PM
  5. Problem in implementing mortgage calculator
    By American Raptor in forum AWT / Java Swing
    Replies: 1
    Last Post: April 1st, 2009, 02:09 PM

Tags for this Thread