Changing function of a buttom.

Consider the following:-

ID [_______]
Name [_______]
Marks [_______]

NEW EDIT CLOSE

This is a form which I have made. What i need is When I click on NEW button, if textboxes should be cleared and the text on the NEW button should change to SAVE. the EDIT button should be disabled and CLOSE should change to CANCEL.

I am able to change the text of the buttons using settext command but their function should is not changing ie, even though now it displays to be a save button but functions as new button. can anybody tell me how to implement this functionality.

Questions by vrijesh28

Showing Answers 1 - 3 of 3 Answers

Hi Dude..

It's a a very simple problem what u need to do is ..

Let,
 JButton n1=new JButton("New");
 n1.setActionCommand("New");
 
JButton n1=new JButton("Save");
 n1.setActionCommand("Save");

..
.
.
public void actionPerformed(ActionEvent e)
 {
  if(e.getActionCommand()=="New")
     {
       //Write your code here
     }
 if(e.getActionCommand()=="Save")
     {
       //Write your code here
     }

}
     
This way check the actionCommand string instead of checking from JButton's name
i.e.  if(e.getSource()==n1)

This will help your to come to a Solution..
u can change the  functionality accordingly....

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions