0% found this document useful (0 votes)
42 views

05 Jframe

JFrame is a window component in Java Swing that allows you to build graphical user interfaces (GUIs). It has several constructors and methods to customize the window frame. Constructors allow setting the title, graphics configuration, or both. Methods allow setting the title, size, location of the frame window and configuring it to close the application when the frame is closed.

Uploaded by

mhcrnl
Copyright
© © All Rights Reserved
Available Formats
Download as ODP, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

05 Jframe

JFrame is a window component in Java Swing that allows you to build graphical user interfaces (GUIs). It has several constructors and methods to customize the window frame. Constructors allow setting the title, graphics configuration, or both. Methods allow setting the title, size, location of the frame window and configuring it to close the application when the frame is closed.

Uploaded by

mhcrnl
Copyright
© © All Rights Reserved
Available Formats
Download as ODP, PDF, TXT or read online on Scribd
You are on page 1/ 9

Java Swing JFrame

JFrame works like the main window where components like labels, buttons,
textfields are added to create a GUI.
Constructors:

JFrame frame = new JFrame();

JFrame frame = new JFrame (String title);

JFrame frame = new JFrame(GraphicsConfiguration gs);

JFrame frame = new JFrame(String title,


GraphicsConfiguration gs);

2
Methods
import java.awt.GraphicsConfiguration;
import javax.swing.JFrame;

/**
*
* @author mhcrnl
*/
public class Main {

/**
* @param args the command line arguments
*/
static GraphicsConfiguration gc;

public static void main(String[] args) {


// TODO code application logic here
JFrame frame = new JFrame(gc);
frame.setVisible(true);
}

}
3
Photo:

4
Set title of JFrame:

import java.awt.GraphicsConfiguration;
import javax.swing.JFrame;

public class Main {

/**
* @param args the command line arguments
*/
static GraphicsConfiguration gc;

public static void main(String[] args) {


// TODO code application logic here
JFrame frame = new JFrame(gc);
frame.setTitle("JFrame tutorial");
frame.setVisible(true);
}

5
Set title of JFrame:

6
Change window size of a frame

import java.awt.GraphicsConfiguration;
import javax.swing.JFrame;

public class Main {

static GraphicsConfiguration gc;

public static void main(String[] args) {


// TODO code application logic here
JFrame frame = new JFrame(gc);
frame.setTitle("JFrame tutorial");
frame.setSize(600, 400);
frame.setVisible(true);
}

7
Closing a frame:

import java.awt.GraphicsConfiguration;
import javax.swing.JFrame;

public class Main {

static GraphicsConfiguration gc;

public static void main(String[] args) {


// TODO code application logic here
JFrame frame = new JFrame(gc);
frame.setTitle("JFrame tutorial");
frame.setSize(600, 400);
frame.setLocation(200, 200);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(true);
}

8
End

You might also like