Generally speaking you should only make the window visible after everything has been added to it, which should make sure everything gets drawn. You could also at some point call repaint(), but if you're setting up a UI that isn't going to change, it is best to completely build the UI prior to making the window visible.
I learned C++ so i can understand but java is such a wonderful language to learn. your teaching very crystal clear to me. you offering a great service to us. God bless you. Thanks Sir.(I have deitel's java How to learn sir)
It's faster to use code completion once you get the hang of it. Eclipse will use context to help you out as well. For example, if you have BufferedInputStream imported, type bu, and press control + spacebar, that will be your first option. So you can type a couple letters, use the shortcut and press enter to complete. It allows for very rapid development, helps to reduce human error due to misspellings and such, and helps you learn by showing you some other classes that are out there.
If that is what you want in your user interface, sure. If you're primarily working with text, it may be easier to work entirely within the console. Maybe something like this would get you started? Scanner scanner = new Scanner(System.in); showGameIntro(); while(gameIsRunning) { String userCommand = scanner.next(); processCommand(userCommand); } The idea being showGameIntro starts the game, then you keep looping and processing the user input according to your game logic.
No, it isn't necessary. You can resize a window after it is visible. Doing so before it is made visible ensures that you won't notice any sudden jump in the window's size that could happen if all the initialization code doesn't execute in a single refresh cycle on your monitor.
There are other components available that may be more appropriate in your case, such as JTextArea (Google for code samples), but you can also put HTML inside of JLabels and have some control over formatting. Here's an example: apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JLabel.html (just pay attention to the labelText Strings) In short, you can use HTML paragraph tags to break up lines inside the label.
@Joncjmc It's called Eclipse. It is a very popular IDE for development in a variety of languages. It's free, just Google it and get one of the Java ones.
If you're certain the code is the same, the data type is correct, and the import is there, try cleaning/rebuilding the project or restarting Eclipse. If you're not having any luck with that, send me your code in a message and I'll take a look at it.
You could do the same sort of thing using a jTextArea, there would just be a little more boilerplate code, and you'd be using getText() and setText(...), etc.
If you dont have JFrame shortcut,download / install current JDK (8u5 currently) R Click MyFirstProject folder in Package Explorer -> properties -> java build path -> libraries tab. remove all libraries then Add Library -> JRE System Library -> next -> select Workspace defult JRE (Java SE 8 [1.8_06]). Finish. OK. Try JF short cut...
I copy pasted this code and the label appears for me. I do not know why it is not working for you. One thing you could try is having the setVisible line be the very last statement.
Thanks for the video, i have a question though: The string object your calling in the end of the video, to me, it looks just the same as a string variable. What's the difference?
Could you maybe add an annotation reminding people to terminate the program? I remember the first time I went through this, Eclipse got really laggy because I didn't realize that closing the window didn't actually end the program so I had about five or possibly more iterations of Object running simultaneously all doing nothing. :/
HEY! this si very useful! thnks ! can u tell me how to keep adding text to the window. I tried making my text longer and it reaches a point where it doesnt fit anymore, i tried to make the window bigger but still, it is a lot of text. i would like to put text in the whole window. can u help me PLEASEEE?!
I'm curious: is it strictly necessary to define the window size and title *before* setting the window as visible? I ask because you seem to be saying it *is* necessary, but when I swap the code around in Eclipse, it doesn't seem to make much difference?
its a really detailed and good video but it doesent work for me? I tried JFrame window new = JFrame (); window.setVisible(true); then ran it and i had like 2 errors so nothing happened
Question, How do you Change the position of the text while it is in the window JFrame window = new JFrame(); window.setTitle("Java App"); window.setSize(800, 600); window.setVisible(true); JLabel label = new JLabel(); label.setText("Java Applet"); window.add(label);
Frames can be configured with layouts that try to keep things organized nicely for you, but can be a little confusing to learn. See here: docs.oracle.com/javase/tutorial/uiswing/layout/using.html Alternatively, you can setLayout(null) and use absolute positioning, but that isn't without its downsides. More work, you have to deal with resizing, etc. Example here: docs.oracle.com/javase/tutorial/uiswing/layout/none.html
Yeah, sorry I have no idea what they mean. It makes everything a billion times easier to learn code when your being taught step by step through a video. By the way, Thank you so much for making these videos, others who try to teach programming don't explain it very well, and you make it step by step, Making it so clear to understand.
Kapil Soni Through trial and error, I've found that calling the revalidate method on the JFrame object after adding the label will get it to show. in this case, window.add(label); window.revalidate(); Hope it helps.
I would like to also know why I’m getting ads for taxes when I have not made any money from anything. I worked at McDonald’s and filled my taxes yesterday I do do what I am supposed to do
Honestly, THIS is video series I have been looking for. Super easy to follow and I can understand this material. Thank you.
My native language is spanish but i understeand this tutorial better than any other spanish tutorial i've seen. Thanks and keep it up.
That is for SURE the best lesson I've ever had about java. THANK YOU!!!!!!!!!
PossessWithin agreed
CodeMonkeyCharlie You are literally better than my Java 1 teacher. Thank you so much. I love how you teach and it seems so straightforward
FAR more informative, and detailed, than all the other videos I've come across thus far. Great Job! Liked, and Sub'd!
Josh Brown same
Thanks for deep description on Java objects. Its is very clear.
Just 20 minutes before my CS125 quiz this sure helped me a lot. Thanks. Ready for the quiz now.
Excellent tutorials, explained, commented and defined for us. Keep it coming!
Generally speaking you should only make the window visible after everything has been added to it, which should make sure everything gets drawn.
You could also at some point call repaint(), but if you're setting up a UI that isn't going to change, it is best to completely build the UI prior to making the window visible.
I learned C++ so i can understand but java is such a wonderful language to learn. your teaching very crystal clear to me. you offering a great service to us. God bless you. Thanks Sir.(I have deitel's java How to learn sir)
It's faster to use code completion once you get the hang of it. Eclipse will use context to help you out as well. For example, if you have BufferedInputStream imported, type bu, and press control + spacebar, that will be your first option.
So you can type a couple letters, use the shortcut and press enter to complete. It allows for very rapid development, helps to reduce human error due to misspellings and such, and helps you learn by showing you some other classes that are out there.
When you clicked run for the first time and an ACTUAL WINDOW popped up on your screen, you blew my mind.
Fuckin' 'ogrammin' maaaaaaaan.
Another great video - this series is really good. Thank you.
I get a lesson about this in college, but I didn't understand it. This video is so clear, thanks ;)
If that is what you want in your user interface, sure. If you're primarily working with text, it may be easier to work entirely within the console.
Maybe something like this would get you started?
Scanner scanner = new Scanner(System.in);
showGameIntro();
while(gameIsRunning) {
String userCommand = scanner.next();
processCommand(userCommand);
}
The idea being showGameIntro starts the game, then you keep looping and processing the user input according to your game logic.
Great works bro thank you.Love from Turkey.
Makes sense. Many thanks, Charlie.
No, it isn't necessary. You can resize a window after it is visible. Doing so before it is made visible ensures that you won't notice any sudden jump in the window's size that could happen if all the initialization code doesn't execute in a single refresh cycle on your monitor.
There are other components available that may be more appropriate in your case, such as JTextArea (Google for code samples), but you can also put HTML inside of JLabels and have some control over formatting. Here's an example: apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JLabel.html (just pay attention to the labelText Strings)
In short, you can use HTML paragraph tags to break up lines inside the label.
u r the man...very clear and precise and informative and blah, blah, blah...:)
@Joncjmc It's called Eclipse. It is a very popular IDE for development in a variety of languages. It's free, just Google it and get one of the Java ones.
If you're certain the code is the same, the data type is correct, and the import is there, try cleaning/rebuilding the project or restarting Eclipse. If you're not having any luck with that, send me your code in a message and I'll take a look at it.
This was verry helpful! thanks, keep up the good work!
You could do the same sort of thing using a jTextArea, there would just be a little more boilerplate code, and you'd be using getText() and setText(...), etc.
Great presentation. Extra points for smooooth voice :D
( ͡° ͜ʖ ͡°)
thank u from sweden
If you dont have JFrame shortcut,download / install current JDK (8u5 currently) R Click MyFirstProject folder in Package Explorer -> properties -> java build path -> libraries tab. remove all libraries then Add Library -> JRE System Library -> next -> select Workspace defult JRE (Java SE 8 [1.8_06]). Finish. OK. Try JF short cut...
Thank you so much I was wondering what was going on
+Skywardbound172 Thank you.
Hi, thank you for your teaching. I want to ask JAVA to make windows which can do that like VB by drawing windows components. Thank you again.
I copy pasted this code and the label appears for me. I do not know why it is not working for you. One thing you could try is having the setVisible line be the very last statement.
When ever I try to use ctrl+spacebar, on JF the only things in the suggestion box are JarFile and JulianFields, anyone know what's up?
Helpful. Thanks.
I would like to include intelligence analyzation on each and every app. The Experian Equifax and Transunion apps have too many permissions
Thanks for the video, i have a question though:
The string object your calling in the end of the video, to me, it looks just the same as a string variable. What's the difference?
very helpful, thanks! :D
Thank you very much.
Could you maybe add an annotation reminding people to terminate the program? I remember the first time I went through this, Eclipse got really laggy because I didn't realize that closing the window didn't actually end the program so I had about five or possibly more iterations of Object running simultaneously all doing nothing. :/
grate .thank you sir
HEY! this si very useful! thnks ! can u tell me how to keep adding text to the window. I tried making my text longer and it reaches a point where it doesnt fit anymore, i tried to make the window bigger but still, it is a lot of text. i would like to put text in the whole window. can u help me PLEASEEE?!
I'm curious: is it strictly necessary to define the window size and title *before* setting the window as visible? I ask because you seem to be saying it *is* necessary, but when I swap the code around in Eclipse, it doesn't seem to make much difference?
THANK YOU SO MUCH
cool stuff, thanks;
At 1:33 what is the shortcut you use to import JFrame up at the top? It appears you don't actually manually type in anything.
+Ashley Elder
Type JFrame and hit "Ctrl + Spacebar"
How can I open the frame without opening the program first?
its a really detailed and good video but it doesent work for me? I tried JFrame window new = JFrame (); window.setVisible(true); then ran it and i had like 2 errors so nothing happened
Question, How do you Change the position of the text while it is in the window
JFrame window = new JFrame();
window.setTitle("Java App");
window.setSize(800, 600);
window.setVisible(true);
JLabel label = new JLabel();
label.setText("Java Applet");
window.add(label);
Frames can be configured with layouts that try to keep things organized nicely for you, but can be a little confusing to learn. See here: docs.oracle.com/javase/tutorial/uiswing/layout/using.html
Alternatively, you can setLayout(null) and use absolute positioning, but that isn't without its downsides. More work, you have to deal with resizing, etc. Example here: docs.oracle.com/javase/tutorial/uiswing/layout/none.html
Yeah, sorry I have no idea what they mean. It makes everything a billion times easier to learn code when your being taught step by step through a video.
By the way, Thank you so much for making these videos, others who try to teach programming don't explain it very well, and you make it step by step, Making it so clear to understand.
+CodeMonkeyCharlie
These are best tutorials i've come accross. Could you please make more... plz
on mac the label component is not adding to window with command window.add(label);
Kapil Soni Through trial and error, I've found that calling the revalidate method on the JFrame object after adding the label will get it to show. in this case,
window.add(label);
window.revalidate();
Hope it helps.
Yes, i shall sub.
:D thank you so much! i wish i was as smart and inteligent as you :$
My JF shortcut doesn't appear.
i love you!
why is it when i run once it dosent let me run a seconed time
It says invalid "Main". Please Help!
the "window" does not store the object but POInts to the object!!!
I do not agree to my privacy being violated it violates my civil rights and I have never agreed to this. I want it stopped.
HOW TO USE DOCTOR JAVA
01:34 OR you could just type JFrame which would be much faster.... ._.
AP COMPUTER SCIENCE IS THE BEST!!!!!
*assuming spelling errors*
I would like to also know why I’m getting ads for taxes when I have not made any money from anything. I worked at McDonald’s and filled my taxes yesterday I do do what I am supposed to do
what in the fuck are you on about?
All apps need to be fixed to make the internet safer
oh maaaaaaaan , THANKS A LOOOOOOOOOOT :'( :'( :'( :'(
2019 anyone ??
class ame objects.. noo.. are you serious.? good way to confused beginner
YOU ARE NOT SHOWING HOW TO CREATE THESE METHODS OMG PLEASE
At the "label.setText()" line I get an error saying "label cannot be resolved"
why is that? The code is exactly the same as yours