IITDU Forum
Would you like to react to this message? Create an account in a few clicks or log in to continue.

How to create a Frame in java

2 posters

Go down

How to create a Frame in java Empty How to create a Frame in java

Post by BIT0112-Rokon Mon Jun 07, 2010 11:40 pm

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.
package com.rokon.tutorial;
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
}
}
now if you run the program it will create a Frame. you can see the
image of my Frame here...
How to create a Frame in java Jframe

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;
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();
}
}
It will print the same frame as before.
BIT0112-Rokon
BIT0112-Rokon
Programmer
Programmer

Course(s) :
  • BIT

Blood Group : O+
Posts : 673
Points : 1269

http://blog.codexplo.org

Back to top Go down

How to create a Frame in java Empty Re: How to create a Frame in java

Post by BIT0122-Amit Tue Jun 08, 2010 1:51 am

Very Happy good tutorial.
rep++
BIT0122-Amit
BIT0122-Amit
Founder
Founder

Course(s) :
  • BIT

Blood Group : O+
Posts : 4187
Points : 6605

https://iitdu.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum