The Artima Developer Community
Sponsored Link

Java Answers Forum
Question about button action in a gui

1 reply on 1 page. Most recent reply: Jun 16, 2005 4:14 AM by Matthias Neumair

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
krijn

Posts: 1
Nickname: krijn
Registered: Jun, 2005

Question about button action in a gui Posted: Jun 16, 2005 3:44 AM
Reply to this message Reply
Advertisement
private void jTextField1_actionPerformed(ActionEvent e)
{
System.out.println("\njTextField1_actionPerformed(ActionEvent e) called.");


}

I made a gui were i have 9 buttons with the values 1 til 9.
I want that the values come to set after eachother like 234 in a texfield.
Can som1 give me an example of how i can do this.

Thnx for helping


Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: Question about button action in a gui Posted: Jun 16, 2005 4:14 AM
Reply to this message Reply
No examples for homework, hust hints.

1. set the value to insert as actionCommand for each button (or as text if you want).

2. create one actionlistener.
2.1 add this actionlistener to all Buttons
2.2 (AbstractButton)event.getSource() is the buttonmodel of the pressed button.
2.3 getText() gives you the displayed Text, getActionCommand() the action command of the ButtonModel from 2.2
2.4 get The current Text from the textfield with getText()
2.5 set the new text using a concatenator (s = s1 + s2).

Flat View: This topic has 1 reply on 1 page
Topic: Recursion Code I'm having issues with... Previous Topic   Next Topic Topic: Why iterator() method is required to explicitly synchronize.

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use