By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,929 Members | 634 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,929 IT Pros & Developers. It's quick & easy.

JButton

P: 12
Hi all

I am having a problem with JButton.

JButton b=new JButton("save");

how can i get the name of the JButton b.

Please give the anser for me
Nov 15 '07 #1
Share this Question
Share on Google+
6 Replies


10K+
P: 13,264
Hi all

I am having a problem with JButton.

JButton b=new JButton("save");

how can i get the name of the JButton b.

Please give the anser for me
The name is b.
What can I say?
Nov 15 '07 #2

P: 12
The name is b.
What can I say?
I want the name of the button as "save".

please give some idea.
Nov 15 '07 #3

10K+
P: 13,264
I want the name of the button as "save".

please give some idea.
Here "save" is usually called the text of the label. You get it using the getText() method. Read all about it in the specs for the button class.
Nov 15 '07 #4

Expert 10K+
P: 11,448
The ActionEvent can tell the source of the event which is object b (your button)
after you have pressed it.

kind regards,

Jos
Nov 15 '07 #5

P: 1
Hi Vijay


In Swing there is a facility of getActionCommand & setActionCommand.


While defining button just add below line.
JButton b=new JButton("save");
b.setActionCommand("save");

and when you are handling action performed...
public void actionPerformed(ActionEvent e) {
String nameOfButton = e.getActionCommand();

............
...........
............

}


Hi all

I am having a problem with JButton.

JButton b=new JButton("save");

how can i get the name of the JButton b.

Please give the anser for me
Nov 15 '07 #6

100+
P: 118
Hi Vijay


In Swing there is a facility of getActionCommand & setActionCommand.


While defining button just add below line.
JButton b=new JButton("save");
b.setActionCommand("save");

and when you are handling action performed...
public void actionPerformed(ActionEvent e) {
String nameOfButton = e.getActionCommand();

............
...........
............

}
I dont think this code will return the name of the button as requested.
Nov 16 '07 #7

Post your reply

Sign in to post your reply or Sign up for a free account.