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

Thread: Help with Java buttons

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

    Default Help with Java buttons

    Hi all,
    I am very new to Java and to keep it short I have to write a program to calculate mortgage amounts. I got all the buttons, textfields and all that good stuff for the GUI. Now, I am stuck trying to figure out how I go about adding actions to my buttons. LIke for example, push the close button to close. The way I added my buttons and such was like this:

    add(new JButton("Enter"));
    add(newJButton("Close"));


    and so on...all my textfields and labels were done the same.

    any help on how I can add the actions will be greatly appreciated.


  2. #2

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,579
    Thanks
    49
    Thanked 2,233 Times in 2,205 Posts

    Default Re: Help with Java buttons

    You need to create variables for the GUI objects that can be used to add the listeners.
    Comp comp = new Comp();
    vs
    add(new Comp());

Similar Threads

  1. Java App - Add, Delete, Reorder elements of the buttons
    By alibm in forum AWT / Java Swing
    Replies: 5
    Last Post: March 7th, 2011, 07:46 AM
  2. Java swing buttons are flickering in windows 7 environment
    By javasam in forum Member Introductions
    Replies: 1
    Last Post: February 17th, 2011, 08:51 AM
  3. Java swing buttons are flickering in windows 7 environment
    By javasam in forum AWT / Java Swing
    Replies: 1
    Last Post: February 14th, 2011, 11:13 AM
  4. [SOLVED] Buttons not working..
    By khms in forum What's Wrong With My Code?
    Replies: 14
    Last Post: September 2nd, 2010, 06:01 PM
  5. Need more buttons!
    By GotWankel? in forum AWT / Java Swing
    Replies: 0
    Last Post: October 5th, 2009, 01:08 AM