fuction callinghow to call 2 function onclick. i want to know. when i click on button
Page 1 of 1
11 Replies - 826 Views - Last Post: 26 July 2008 - 12:14 PM
#1
fuction calling
Posted 20 July 2008 - 10:07 PM
Replies To: fuction calling
#2
Re: fuction calling
Posted 20 July 2008 - 10:46 PM
public void actionPerformed(ActionEvent e)
{
// call your functions here.
}
If you don't have an ActionListener set up...
jButton1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
// do stuff on the button click (AKA the action performed)
// of course, you replace "jButton1" with the name of your button object.
}
});
Hope this helps!
This post has been edited by Locke37: 20 July 2008 - 10:47 PM
#3
Re: fuction calling
Posted 21 July 2008 - 04:35 AM
bt.addMouseListener(new MouseListener(){
public void mouseClicked(MouseEvent arg0) {
// method1();
// method2();
}
public void mouseEntered(MouseEvent arg0) {
}
public void mouseExited(MouseEvent arg0) {
}
public void mousePressed(MouseEvent arg0) {
}
public void mouseReleased(MouseEvent arg0) {
}
});
#4
Re: fuction calling
Posted 21 July 2008 - 02:53 PM
#5
Re: fuction calling
Posted 21 July 2008 - 03:29 PM
Locke37, on 21 Jul, 2008 - 02:53 PM, said:
Right, but it will happen when mouse is over, mouse pressed, mouse released, key pressed when button is active, or any other thing not just on click as wanted.
#6
Re: fuction calling
Posted 21 July 2008 - 03:53 PM
lordms12, on 21 Jul, 2008 - 03:29 PM, said:
Locke37, on 21 Jul, 2008 - 02:53 PM, said:
Right, but it will happen when mouse is over, mouse pressed, mouse released, key pressed when button is active, or any other thing not just on click as wanted.
Locke37 solution will also work when <CR> is entererd and the JButton has the focus so it is better a better implementation especially if you want (later) disable the JButton in that case the ActionListener will not be call while your MouseListener will
#7
Re: fuction calling
Posted 23 July 2008 - 08:49 AM
lordms12, on 21 Jul, 2008 - 03:29 PM, said:
Locke37, on 21 Jul, 2008 - 02:53 PM, said:
Right, but it will happen when mouse is over, mouse pressed, mouse released, key pressed when button is active, or any other thing not just on click as wanted.
No...it won't. I use this on every button when making my own GUIs. It only happens when you click the button or when it has the focus and you press 'Enter' or 'Spacebar'.
This post has been edited by Locke37: 23 July 2008 - 08:53 AM
#8
Re: fuction calling
Posted 23 July 2008 - 09:03 PM
#9
Re: fuction calling
Posted 24 July 2008 - 03:43 AM
tjd195, on 23 Jul, 2008 - 09:03 PM, said:
To add my 0.02€, using ActionListener is less work because it only has 1 method to implement (and yes I do know my IDE can generate it for me, but that means clicking more checkboxes in case of MouseListener)
#10
Re: fuction calling
Posted 24 July 2008 - 01:53 PM
JeroenFM, on 24 Jul, 2008 - 03:43 AM, said:
tjd195, on 23 Jul, 2008 - 09:03 PM, said:
To add my 0.02€, using ActionListener is less work because it only has 1 method to implement (and yes I do know my IDE can generate it for me, but that means clicking more checkboxes in case of MouseListener)
Correct, using an ActionListener is less work, but should only be used on buttons in my opinion. I don't use it for anything else. Course, I don't make too advanced GUIs...
#11
Re: fuction calling
Posted 25 July 2008 - 01:13 AM
#12
Re: fuction calling
Posted 26 July 2008 - 12:14 PM
This post has been edited by Locke37: 26 July 2008 - 12:14 PM
|
|

New Topic/Question
Reply




MultiQuote





|