Should use a modal dialog instead of another frame. Also, realizing the container should be the last thing you do; adding components after the container has been realized may cause serious problems.
Thanks a lot for this. I would like to add things to the existing window... Juse add a couple of lines on the same screen. Adding a new JLabel is not working... any recommendations?
OMG! THANKS! I am 11, and ive been using flash for years. I am making one of my first java projects and your tutorial was just what I needed. But i need something for multiple buttons??
Hey i get an error when i type button.AddActionListener(new Action());
I typed exactly everything you did, i dunno whats wrong it says
"cannot instantiate the type action"
ive been doing java for a few weeks now so im not a total newbie i understand all the basic concepts so normally i can solve my own problems but im stuck here... please help me someone :s thanks
i just wondering can u make button to close the frame/window for example i had a button called cancel in the frame/window and when i click it the frame/window closes down plz help
@ivandonat I'm wondering about the exact same! How to position objects and how to give more than one button different actions! Please tell if you get an answer!
@MrUsman4040 Typical use of Hashtable is where fast-access ranks over sensible ordering. We use paint Childern method when they have watercolors. Named Objects have a name. Anonymous Objects do not exist, to say why would get me war-painted.
Hello MrJawaHelp, i absolutely love the GUI tutorials. Im working on a class project, although everything is Ok but one question.
I am also using eclipse, but in your case eclipse is showing autocomplete options. In my case, it shows for basic java commands but the GUI related commands are not autofilled by eclipse. Am i missing something?
@tarunpai Declare an event handler class and specify that the class either implements an ActionListener interface or extends a class that implements an ActionListener interface -- which means that it has a method public void actionPerformed( ActionEvent e ){} and in that method you have to have a reference to the object you want to do someting with
for those who have watched all the vids and cannot get ActionListeners to do useful work, what I did was give the class SomeClass extends ActionListener a reference to the class upon which it was supposed to act such as FirstClass.actionInvoker = new ActionInvoker(this); and have the ActionListener - SomeClass's ActionPerformed() method work the reference. This raises a circularity error risk but it is incumbent to sort those things as need be.
hi just want to ask wat if i have 2 button how do i type inorder when i click on button one my particular for button1 will appear and same for button 2?
okay, only other question i have, after static class when you name your action, mine gets a syntax error. in the video his did too, but when he puts a close bracket after the pannel.add it fixes it. In my program I have multiple buttons that I eventually want to put sound into when I click them. But I get errors on every other button when I add that close bracket. please help.
Yes, it can become tedious, but you have add an action listener everytime you want to make a button do something. Also, for radioButtons and sliders its a bit different in terms of the actionListeners, but you still have to add it for every single one.
I am using NetBeans also, and was wondering if you could tell me why NetBeans creates a Main.java as the main method starting point? Also, I was able to follow your code rather easily, however with NetBeans, I got the same message, "static is not allowed here". Can you help? BTW, I enjoyed your video. Thanks.
Im a biggner in java and its so easy btw i normally program in visual basic and c# i know the full visual basic lanuage but i also wannna program for linux so im going to learn java as well
when i write the second class (static class action implements ActionListener), netbeans says "static is not allowed here". I don't know how to fix this, i wrote the whole code like you.
Thanks for your explanation. It's a very good tutorials.
sarath7khmer 3 days ago
Should use a modal dialog instead of another frame. Also, realizing the container should be the last thing you do; adding components after the container has been realized may cause serious problems.
77cyclops 3 weeks ago
nice mr. :)
DhawuRacing 1 month ago
suddenly a new import comes at 2:33 "import sun.swing.text........." y is that for y i came like that? you did not not tell any thing about that
haidersajjadHS 1 month ago
i get a error like yours at 5:08 can you show how fix?
gustavoindustry 1 month ago
Thank you so so so much!!! :)
inoneword3 1 month ago
y is that panel so necessary..?? can't v use directly
MrTuhinBagh 2 months ago
Thanks a lot for this. I would like to add things to the existing window... Juse add a couple of lines on the same screen. Adding a new JLabel is not working... any recommendations?
fanes1979 2 months ago
Acctually, all i need are image buttons. I can do the other two things! Figured it it out!
TehAnimatorKing 2 months ago
Also. can you do image buttons?
TehAnimatorKing 2 months ago
Oh and also, how can you make an image appear/ disappear with this?
replacing the label? Sorry, I am such a begginner.
TehAnimatorKing 2 months ago
OMG! THANKS! I am 11, and ive been using flash for years. I am making one of my first java projects and your tutorial was just what I needed. But i need something for multiple buttons??
TehAnimatorKing 2 months ago
hey MrJavaHelp, i realy want to thank you for posting these video's, and you helped me out quite a bit learning java. good going!
Vancha112 2 months ago
Dude you are awesome!!!
Shadowfist1000 2 months ago
@AZCHIM @Olemassacre
MULTIPLE ACTIONS FOR MULTIPLE BUTTONS:
1: Transform your Components into Class Variables (after class definition w/ static).
2: Use the "static inner class" MrJavaHelp gave you and insert the following code:
if (e.getSource() == {insert your source component here}) // do shit and return
else if (e.getSource() == {insert your source component here}) // do some more shit and return
3: {insert your source component here}.addActionListener(new Action());
Thumbs up if it helped.
scarfulify 3 months ago 4
HI great work mate
Could you teach me how to put multiple action listener for multiple buttons ??
AZCHIM 3 months ago
Comment removed
scarfulify 3 months ago
how to get button in other button in same frame?
jhemville17 3 months ago
waaa
jhemville17 3 months ago
thank you, this was very helpful :)
zrebrutibreniti 3 months ago
Wow, very informative, good job.
CriticaLKonflict 4 months ago
How would I add a new label/button/etc. to an existing gui?
Tomba444 4 months ago
nevermind
metalcore098 5 months ago
i get errors bro doesnt work
metalcore098 5 months ago
thanks alot man youre helping me out good in my java programming class :D
ultravanz 6 months ago
Very nice and Thanku very much..........its really very helpful for beginners like me...
honey04041990 6 months ago
Is there a way to pass in another variable with the action
CapitalI6699 8 months ago
@youngday713 it should come with java
CapitalI6699 8 months ago
how do you get java swing???
youngday713 9 months ago
@youngday713 import javax.swing.*;
TheGamerTeamChannel 5 months ago
Hey i get an error when i type button.AddActionListener(new Action());
I typed exactly everything you did, i dunno whats wrong it says
"cannot instantiate the type action"
ive been doing java for a few weeks now so im not a total newbie i understand all the basic concepts so normally i can solve my own problems but im stuck here... please help me someone :s thanks
keywee95 9 months ago
i just wondering can u make button to close the frame/window for example i had a button called cancel in the frame/window and when i click it the frame/window closes down plz help
MrKar0shi 10 months ago
hi dude nice tut. btw . if you don't mind can you send me a copy of this program? we need it for school project.:D thx.
0watever 10 months ago
verry good
MlodyXX0 10 months ago
You could also have used an Inner Class. That would have saved your time writing the Action method and then calling its instance.
button.addActionListener(new ActionListener()
{ public void actionPerformed(ActionEvent ae) { // Fill here with the contents of actionPerformed // method from the video. :-) }
});
khunii 11 months ago
easy pc...:)
viewsonicplastic2222 11 months ago
Umm, how to make the button on specific spot, and
how to make something like: if (action == button clicked) {
}
ivandonat 1 year ago
@ivandonat I'm wondering about the exact same! How to position objects and how to give more than one button different actions! Please tell if you get an answer!
Olemassacre 4 months ago
@Olemassacre Got it, its button.reshape(something,something); i dont remember exactly because i didnt program java for a while
ivandonat 4 months ago
@ivandonat Oki, thanks! :D
Olemassacre 4 months ago
"That's the algorithm for making our acion listener..."
LMAO
RolandSaybe 1 year ago
thanks dude c:
KARLculus 1 year ago
Question No: 17 ( Marks: 1 ) What is the typical use of Hashtable?
Question No: 18 ( Marks: 1 ) Why we use paintChildern( ) method?
Question No: 19 ( Marks: 2 ) Write any two steps of painting strategy.
Question No: 20 ( Marks: 3 ) Name three paint () methods which are used to paint Swing Component.
Question No: 21 ( Marks: 5 ) Differentiate between Named and Anonymous Objects.
MrUsman4040 1 year ago
@MrUsman4040 Typical use of Hashtable is where fast-access ranks over sensible ordering. We use paint Childern method when they have watercolors. Named Objects have a name. Anonymous Objects do not exist, to say why would get me war-painted.
pzmtuthcvpvl 1 year ago
Hello MrJawaHelp, i absolutely love the GUI tutorials. Im working on a class project, although everything is Ok but one question.
I am also using eclipse, but in your case eclipse is showing autocomplete options. In my case, it shows for basic java commands but the GUI related commands are not autofilled by eclipse. Am i missing something?
Please help.
dr8u1 1 year ago
Netbeans is asking me to crate an interface for the action listener, how do i do that? and what should i code inside of it?
tarunpai 1 year ago
@tarunpai Declare an event handler class and specify that the class either implements an ActionListener interface or extends a class that implements an ActionListener interface -- which means that it has a method public void actionPerformed( ActionEvent e ){} and in that method you have to have a reference to the object you want to do someting with
pzmtuthcvpvl 1 year ago
can you do something like. when you click the button the last JFrame will close so that the new JFrame will only be visible?
wad3flash33 1 year ago
yea just remove the JFrame.EXIT_ON_CLOSE in the first frame
TheLyrikz 1 year ago
u explain things so well
283518 1 year ago
for those who have watched all the vids and cannot get ActionListeners to do useful work, what I did was give the class SomeClass extends ActionListener a reference to the class upon which it was supposed to act such as FirstClass.actionInvoker = new ActionInvoker(this); and have the ActionListener - SomeClass's ActionPerformed() method work the reference. This raises a circularity error risk but it is incumbent to sort those things as need be.
pzmtuthcvpvl 1 year ago
What should I do to create some more labels and buttons in the same frame instead of a new frame?
Can some one tell me, have been stuck here for quite sometime now!
panudeep 1 year ago
@panudeep
JButton button1 = new JButton("Button 1");
JButton button2 = new JButton("Button 2");
JButton button3 = new JButton("Button 3");
JButton button4 = new JButton("Button 4");
panel.add(button1);
panel.add(button2);
panel.add(button3);
panel.add(button4);
:)
Olemassacre 4 months ago
All people that are struggeling with that I noticed that Action class is inside swing2 class. Thank for tut very nice
arturzxc 1 year ago
Hmm if anyone wants to be a concerned programmer.. Dont import .* actually find the classes you need. Using .* imports the whole package.
12stringovation 1 year ago
i want to create a bottom which calls a new forms contains database with netbeans .
please help me urgent.
nizarenit 1 year ago
hi just want to ask wat if i have 2 button how do i type inorder when i click on button one my particular for button1 will appear and same for button 2?
josephineling 2 years ago
okay, only other question i have, after static class when you name your action, mine gets a syntax error. in the video his did too, but when he puts a close bracket after the pannel.add it fixes it. In my program I have multiple buttons that I eventually want to put sound into when I click them. But I get errors on every other button when I add that close bracket. please help.
gleboff 2 years ago
Anyone know how to add an actionlistener to play a soud file? please message me.
gleboff 2 years ago
well explained, but you still didn't explain how to use layouts which was suppose to be this video.
ruskido 2 years ago
The same question as the one below:
Do you need to add different action Listeners 4 every object you create?
How about radioButtons, sliders etc?
But thank you for your videos... very helpful.
altisw5 2 years ago
Yes, it can become tedious, but you have add an action listener everytime you want to make a button do something. Also, for radioButtons and sliders its a bit different in terms of the actionListeners, but you still have to add it for every single one.
xxxcoolboyxxx 2 years ago
do u need to add......:
static class action1 implements ActionListener{
public void actionPerformed (ActionEvent e){ .....to every individual button ????
ixy1987 2 years ago
You make it so easier than my lectures!!! haha
z3r0717 2 years ago
thank you very much MrJavaHelp
usernameice 2 years ago
I stumbled onto this just-in-time. very straight forward! ... I will have to watch a few more then possibly recommend.
capitolcee 2 years ago
U r my Hero man...GOD BLESS YOU
vicabelcom 2 years ago
Ugh, you really should learn what an algorithm is before you use it in a video. >____>
The beginning of a class declaration is NOT an algorithm.
rhillner 2 years ago
I am using NetBeans also, and was wondering if you could tell me why NetBeans creates a Main.java as the main method starting point? Also, I was able to follow your code rather easily, however with NetBeans, I got the same message, "static is not allowed here". Can you help? BTW, I enjoyed your video. Thanks.
RoyceWarren 2 years ago
Im a biggner in java and its so easy btw i normally program in visual basic and c# i know the full visual basic lanuage but i also wannna program for linux so im going to learn java as well
computertrick 2 years ago
when i write the second class (static class action implements ActionListener), netbeans says "static is not allowed here". I don't know how to fix this, i wrote the whole code like you.
MrKontraproduktiv 2 years ago
Easy stuff, but good video though!!.
Just try NOT to say (so) so much in ur next video.
SuperMozard 2 years ago
thank you
copsandrobbersgta 2 years ago
Be cool if you could add previous / next lesson at the end of the tutorial as well. :)
thanks. nice tut.
maetosult 2 years ago 10
THere you go,I added that :)
MrJavaHelp 2 years ago 17
do you know how i make a message box in java?
computertrick 2 years ago
This is easy stuff, but good tutorial though.
I am looking forward to your next video.
I really don't know how to position objects in your frame.
MrKiller00224 2 years ago