Java Swing GUI Tutorial : #JFrame
Hello,
welcome to my first java swing tutorial in JFrame. Let's start from creating a
new project and throw the java project.
Select java
project and then I put the project name as "Swing"
Then create a
new class and I put the class name as "Frame"
And also I'm
going to select the "public static void main(String[] args)"
To create any
swing component will have to import our swing library or type like this.
Here, I'm going to make my
objects like this."JFrame frame = new JFrame();"
and I'll pass the title of my frame in constructive JFrame class and title will be JFrame demo,
"JFrame frame = new JFrame( "JFrame demo");"
"frame.setDefaultCloseOperation();"
"setDefaultCloseOperation()"
is a method which defines how our application ends. So it defines what happens
when we click on exit button.
" frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);"
So some of your friends which have some experiences are probably
wondering why I'm calling "DISPOSE_ON_CLOSE" instead of exiter close.
Calling exiter close will end our application violently.
Next method I'm going to call is,"frame.setSize();"
It's of course self-explanatory but it defines size for free in pixels and I'll set the size like this.
"frame.setSize(320,240);"
Nicley explained ! Keep up the good work
Good article Hasmie!!! Write more...cheers..
ReplyDeleteGood article for beginners!! Well explained..
ReplyDeleteGood work, keep it up
ReplyDeleteGood article for beginners! keep it up..
ReplyDeleteGood article for beginners! keep it up..
ReplyDeletejob done well , keep it up!
ReplyDeletewell explained..!keep it up
ReplyDeleteGood Work.. Keep it up..
ReplyDelete