I'm a newbie in here, (sorry I dont know where to post)
anyways...
our machine problem is this..
make a Jframe that has a click button "Press Me" and when you clicked it, another frame will appear and tells "You clicked x time/s" where x is the number clicked. Below that word is an "ok" button which means exit.
I only knew how to make a "Press Me button" our teacher said just explore. huhuhu Somebody HELP ME!!!
thank You for your Kind Consideration.
7 replies to this topic
#1
Posted 09 March 2011 - 07:43 PM
|
|
|
#2
Posted 09 March 2011 - 11:17 PM
I thot your teacher said you must explore now if we give you the answer you will not be exploring now will you? any way what I will jsut explain to you theoratically what i would do probably not the best approach but i think it will work.
I would create two forms, and the second form will be invoked within the "Press Me" and that is will you will keep the number of times the key has been pressed. Ill try put up the code later
I would create two forms, and the second form will be invoked within the "Press Me" and that is will you will keep the number of times the key has been pressed. Ill try put up the code later
#3
Posted 10 March 2011 - 02:52 AM
Do you know how to add an ActionListener to your JButton? You'll need to do that in order to get this to work. Adding an ActionListener is easy, just use the addActionListener method on your JButton.
ActionListener myListener = new MyActionListenerDerivitive(); myJButton.addActionListener(myListener);
Wow I changed my sig!
#4
Posted 10 March 2011 - 10:10 AM
Done. Thank You very much :) ... uhm, Is it possible to click "Press Me" without clicking the "OK" in new window [what i mean is that it will not alert saying click ok first so you can click press me] how? just asking ^^,
#5
Posted 11 March 2011 - 12:21 AM
If you want that kind of behaviour, (not being able to click Press Me again before closing the new window), then you 2nd frame should extend JDialog.
I gues your 2nd frame now extends JFrame, so just change it into JDialog. Both work similiar, but JDialogs have a different constructor:
I gues your 2nd frame now extends JFrame, so just change it into JDialog. Both work similiar, but JDialogs have a different constructor:
JDialog(Dialog owner, boolean modal)As owner you have to give the original frame, and modal = true means you can't click on the owner frame until the dialog is closed.
#6
Posted 11 March 2011 - 03:40 AM
I use the drag and drop functionality do create my gui projects so i want to know if I had implemented the solution to this problem using two JFrame forms, how would i access the int PressMeCounter on the other JFrame form.
#7
Posted 11 March 2011 - 03:57 AM
Well, somewhere in your actionListener you could do
And I'm pretty sure you can set it enabled again in the actionlistener of the 'OK'-button.
There's only 1 problem with this, and that's the fact that you can close the 2nd window without pressing 'OK' but just closing it.
Then your first button is still disabled.
You could catch the window.closing event with a windowlistener, but that seems like a lot of work for something silly.
Edit:
Alternatively, you can in the main frame class (even though it's drag & dropped, you should still be able to get the code somewhere) You can add the 2nd window as field. and you always use setVisible, so the 2nd frame always exists, but isn't always visible.
Something like this:
button.setEnabled(false);Then you can't press it anymore (obviously).
And I'm pretty sure you can set it enabled again in the actionlistener of the 'OK'-button.
There's only 1 problem with this, and that's the fact that you can close the 2nd window without pressing 'OK' but just closing it.
Then your first button is still disabled.
You could catch the window.closing event with a windowlistener, but that seems like a lot of work for something silly.
Edit:
Alternatively, you can in the main frame class (even though it's drag & dropped, you should still be able to get the code somewhere) You can add the 2nd window as field. and you always use setVisible, so the 2nd frame always exists, but isn't always visible.
Something like this:
public class MainFrame extends JFrame{
private PopupFrame popup;
public MainFrame(){
super();
popup = new PopupFrame();
}
/*ActionListener*/
public void actionPerformed(ActionEvent e){
if(!popup.isVisible() ){
popup.setVisible(true);
}
}
}
#8
Posted 24 March 2011 - 12:47 AM
thank u very much wim I'll check it out at home.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









