Results 1 to 2 of 2
  1. #1
    ChrisS145 is offline Member
    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    Unhappy Trying to change text of Jlabel multiple times using button

    Hi, I'm new to Java. I know a few things, but I don't know enough to even create a valid program that doesn't have an error.

    Now, I'm trying to find out how to create a button game, where I use Action listener to count the amount of times that a J button in the center of the screen, and change the text of the J label based on that number. I'm taking a Java class, but I've only had my first day. The teacher demonstrated some scripts, and I requested for him to show a certain script. I took notes, and this is what i currently have/understand a little:

    public void action performed(action event arg0) (
    clicks += 1;
    1.settext("")

    and

    button=new J button ("")
    button.setbounds("")
    button.addactionlistener(new actionlistener() (

    and also

    J label l=new J label();
    l.settext("");
    l.setbounds("");

    and something to do with J panel.

    I need a script that uses something similar to these, where I can add more changes in the J label's text based on the clicks. Like adding a 2.settext() after 1.settext(), and 3.settext() after 2.settext(), and so on.

    So, I would be very grateful if someone were to create a script that has these requirements, and uses "Button Game" as the Project, "gamepack" as the pack, and "game" as the class.

    (And just to note, don't critisize me about how I could ask my teacher, beacuse I take the class once I week and I don't know him.)

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

    Default Re: Trying to change text of Jlabel multiple times using button

    Starting to learn programming is a daunting task, but you'll not be able to guess at this and succeed. If you don't have a decent textbook to refer to (or even if you do), I strongly suggest that you check out the Java tutorials here: The Java Tutorials.

Similar Threads

  1. Replies: 1
    Last Post: 02-11-2012, 03:07 AM
  2. write line multiple times
    By relith in forum New To Java
    Replies: 3
    Last Post: 10-27-2010, 08:38 AM
  3. Issue with saving multiple times to a variable
    By sidd0123 in forum New To Java
    Replies: 3
    Last Post: 06-06-2010, 02:02 AM
  4. Playing an AudioInputStream multiple times
    By pmgallardo in forum Advanced Java
    Replies: 6
    Last Post: 03-09-2009, 04:29 PM
  5. How can I change text for paginate button?
    By robot in forum NetBeans
    Replies: 0
    Last Post: 11-20-2008, 06:04 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
  •