473,382 Members | 1,396 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

JButton

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
6 2118
r035198x
13,262 8TB
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
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
r035198x
13,262 8TB
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
JosAH
11,448 Expert 8TB
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
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
heat84
118 100+
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

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

Similar topics

0
by: Jeff T. | last post by:
Hi, I have a JMenuBar object that contains a JToolBar object which contains some JButton objects. After I let my applet sit for > 20 minutes, the graphics on those buttons would disappear. ...
3
by: Konrad Den Ende | last post by:
Is it possible to do at all? The software will be used on computers with western operative systems (so i guess, JVM will be english) but i'm asured that japanese will be enabled through IME so that...
4
by: porky008 | last post by:
I put in a next and previous button but it crashes when I run it. I also need it to loop around to the first or last if at the ends. Can some one help me with this? import java.awt.*; import...
0
by: Oswald Otte | last post by:
Hello How can I change the look of a disabled JButton? I have made a boardgame with a brown background and brown buttons. I have also put an imageicon on the buttons that has a colored image on...
9
by: SimonHeffer | last post by:
I've been asked to give my .NET app the same look and feel to another app written using Java/Swing. My main issue is to do with button/icons. The JButton used by the other app has an icon with a...
2
by: sokeefe | last post by:
I am trying to edit the GUI of a project in Netbeans. In particular, I am trying to add new JButtons. I get a NullPointerException when I try to add an Event to any given JButton (even ones that...
1
by: sokeefe | last post by:
I am trying to edit the GUI of a project in Netbeans. In particular, I am trying to add new JButtons. I get a NullPointerException when I try to add an Event to any given JButton (even ones that...
12
by: yeshello54 | last post by:
So I want to set the background color of a Jbutton. I know that the normal way to do such a thing is down the following way: JButton button = new JButton("xxxx"); button.setBackground(Color.RED);...
1
by: mlibot | last post by:
My JButton will be disabled when running my program... my JButton will be enabled if the value or parameter are equal to 3... for example: 1 value is path of the file i selected. 2 vaue is path of...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.