Technical talk .net
Hello, Technicals !
hope you all doing well ^^
well, I'm still a very beginner and not sure whether i shall post this tutorial, and also not sure if this is going to go straight to your minds, but i'll try my best and i'll tell all what i know.
so please, read. i'll be appreciated if someone got the idea

. leave a comment when feel like ^^
let's just start ..
So,
the tutorial will be talking about GUI (Graphical User Interface) in java programming language. we all know that java is a OOp language. it means that we could design interfaces for the software we develop, so that the user could interact much easily with it. That's what graphical interfaces aimed to.
let's write a code to show a window, or a FRAME as we call it in Java. let's see how the code would look like :
import javax.swing.*;
public class JFrameTest {
public static void main (String [] args) {
JFrame f = new JFrame();
}
}
now we've already created our frame.
let's take it line by line :
import javax.swing.*;
this line is concerned for calling the package (javax.swing) which contains the JFrame component.
simply, the frame cannot be created without including this package.public class JFrameTest {
creating the class and name it as JFrameTest.
i'm sure that if you are learning GUIs , you would know what that means as we all learned in previous levels .public static void main (String [] args) {
this line also is understood perfectly. no need to talk a lot here.JFrame f = new JFrame();
Here comes creating the frame and give it the name of f .
(the first) JFrame : the class name
f : creating the object (frame)
new : key word used for creating the frame which we gave f as the name of it .
(the last) JFrame : the constructor , which has to be named the same as the class name .and the last two lines are of course the closing brackets for
JFrameTest and
main classes.
[copy and paste the code in your IDE to see the result]nothing showed up, right? you would think that there might be an error in the code, but NO. when running the program , it will stop automatically after few seconds, why ?
actually, the frame was definitely created , but HIDDEN . so the program stopped.
in this case, we need to set some attributes to the frame, at lease to make it visible.
so what we do ?
look at the following :
import javax.swing.*;
public class JFrameTest {
public static void main (String [] args) {
JFrame f = new JFrame();
f.setVisible(true);
}
}
One line was added.
f.setVisible(true);
so this is the code responsible for making the frame VISIBLE .
(the object name) f [dot] (the method) setVisible ([the boolean value] true ) in between the brackets ()
of course we don't forget the semi colon ;Now let's try adding some other features to our frame .
Here goes the code :
import javax.swing.*;
public class JFrameTest {
public static void main (String [] args) {
JFrame f = new JFrame("Testing the Frame");
f.setVisible(true);
f.setSize(300,200);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
THREE more things were added. let's pick them up one by one .
First one was giving the frame a title : "Testing the frame"
we wrote it in between the brackets in the same line of creating the frame. this looks simple, doesn't it ? note that title has to be in between Double Quotes " "Next thing
f.setSize(300,200);
setting the size of the frame by adding the arguments in between the brackets (WIDTH , HEIGHT);
we set 300 as the width, 200 as the height.Last one ..
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this is a very useful line. well, it is a must in every frame we create. (may be some exceptions in higher levels)
this line is used for terminating the program. if we click on the (x) button, the program will still running, even though the frame disappears , but the operation will still ON.
so we should include that code to stop the program when wanted.
it goes like this :
(frame name) f [dot] (method name, which is.. ) setDefaultCloseOperation (in between the brackets) we call the class name which is JFrame [dot] (the method, which is.. ) CLOSE_ON_EXIT (note: java is case sensitive so write it exactly like i wrote)
anyhow , you don't need the explanation of it right now .WELL, that's all i guess. don't know how i was doing. just hoping i covered everything well.
i need your comments.
Experts, how was the tutorial ? is there anything missing ? do you have any suggestions ? any corrections ? i'll be appreciated.
Beginners, hope my words make you get the basic Idea .
Many Thanks to everyone .
You can find more information here :-
*** Please do not forget to leave your comments about this article ***