How to create a Frame in java
2 posters
Page 1 of 1
How to create a Frame in java
Today I wanna show you how to create a frame and how to manage it in
Java. It is quite simple. There is a class named JFrame in JDK. Now we
just use it. So let us see an example given bellow.
image of my Frame here...
now will do the same program in different way. here we will use
constructor and make customized class that will be our own class and
extends the JFrame class. So lets see the code ..
Java. It is quite simple. There is a class named JFrame in JDK. Now we
just use it. So let us see an example given bellow.
package com.rokon.tutorial;now if you run the program it will create a Frame. you can see the
import javax.swing.JFrame;
public class MyFrame {
public static void main(String[] args) {
JFrame frm = new JFrame(); // instance of JFrame named frm
frm.setTitle("A simple Frame"); // here we set the title of the Frame
// using setTitle() Method existing in
// JFrame class
frm.setSize(300, 400); // here we define the size of the frame. the
// method setSize() take two parameter width and
// height as a integer value.
frm.setVisible(true); // the method setVisible make the frame visible
// and the parameter is boolean type. if the
// parameter is true, the frame will be visible
// to us otherwise not..
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// the
EXIT_ON_CLOSE
// is a constant
// variable in
// JFrame. and
// setDefaultCloseOperation()
// method take the
// variable as a
// parameter and
// close the window
// when we click the
// close button in
// the right corner
// of Frame which is
// default attribute
// of a Frame
}
}
image of my Frame here...
now will do the same program in different way. here we will use
constructor and make customized class that will be our own class and
extends the JFrame class. So lets see the code ..
package com.rokon.tutorial;It will print the same frame as before.
import javax.swing.JFrame;
public class MyJFrame extends JFrame {
public MyJFrame() {
setTitle("My frame");
setSize(400, 400);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new MyJFrame();
}
}
Similar topics
» Setting background of a frame in Java
» Show date and Clock in java Frame
» How to create a .pdf file and write in it by Java
» Java Tutorial: Using Two Java Reference Keywords, this and super
» Create ASCII art in Ubuntu using terminal
» Show date and Clock in java Frame
» How to create a .pdf file and write in it by Java
» Java Tutorial: Using Two Java Reference Keywords, this and super
» Create ASCII art in Ubuntu using terminal
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|
Tue Sep 29, 2015 2:45 pm by Sophiawood
» Cisco EHWIC SFP/GE WAN Card
Mon Sep 07, 2015 11:08 am by Sophiawood
» Huawei S1700-28GFR-4P-AC Price
Thu Jun 25, 2015 2:31 pm by Sophiawood
» teach yourself C++ / Herbert Schildt Solutions
Wed Jun 03, 2015 1:52 pm by Abdullah Al Noman
» teach yourself c by herbert schildt pdf
Wed May 13, 2015 11:01 pm by Raquib Ridwan
» ASA 5506X With Firepower ASA5506-K9
Fri Apr 10, 2015 4:31 pm by Sophiawood
» New Trends in Deal Business
Tue Feb 03, 2015 9:38 pm by nersoa
» PoE Power Allocation for WS-C2960S-24PS-L
Wed Nov 05, 2014 11:12 am by Sophiawood
» How to cure back pain
Fri Oct 31, 2014 7:15 pm by Bergen Guildford