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 2 of 2

Thread: Help Me with this program please?

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help Me with this program please?

    So I have this program here, and it's a simple java AWT program that creates a button. as of right now, it works just fine, but I want to make it so that it counts the number of times the button is clicked, and then displays that number on the button itself, but I don't know how to do that
    here's my program:
    import java.awt.*;
    import java.awt.event.*;
    public class ButtonClicks extends Frame
    {
    ButtonClicks()
    {
    setTitle("Click the button");
    setSize(200, 200);
    }
    public static void main(String args[])
    {
    Frame x;
    Button b;
    Label l;
    x = new ButtonClicks();
    b = new Button("Button");
    l = new Label("Click the button");
    l.setBounds(30, 50, 100, 30);
    b.setBounds(80, 50, 50, 30);
    x.add(b);
    x.add(l);
    }
    }


  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default Re: Help Me with this program please?

    Is there a reason why you aren't using Swing? (JFrame, JButton, etc)

    Basically you should write an action handler that sets the button text. And add that handler to the button so that it does its thing in response to button clicks.

Similar Threads

  1. Invoke a Java program with windows program
    By jackhard in forum Object Oriented Programming
    Replies: 1
    Last Post: February 21st, 2013, 07:16 AM
  2. Program goes into infinite compilation. University project - Library Program.
    By clarky2006 in forum What's Wrong With My Code?
    Replies: 35
    Last Post: November 10th, 2012, 03:56 PM
  3. Replies: 1
    Last Post: July 8th, 2012, 10:23 AM
  4. how to run a java program..when the program using jar
    By miriyalasrihari in forum Java Theory & Questions
    Replies: 2
    Last Post: May 17th, 2012, 10:04 AM
  5. Program to launch and mirror another program
    By hayate in forum Java Theory & Questions
    Replies: 13
    Last Post: March 9th, 2012, 12:47 AM

Tags for this Thread