Advance Java Programs

Java Program to Create Frame

Welcome to advance java programs, this is simple basic program of advance java.

In this program we will see how to create JFrame window by using (extending)JFrame class. For Graphical User Interface in Java need to use of Swing, so we need to import package javax.swing

Program

import javax.swing.*;

public class SimpleFrameTest

 {

 public static void main(String[] args)

 {

 SimpleFrame frame = new SimpleFrame();

 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.show();

 }

 }

 class SimpleFrame extends JFrame

 {

 public SimpleFrame()

 {

 setSize(300,500);

 }

 public static final int WIDTH = 800;

 public static final int HEIGHT = 200;

 }

When Run The Program Following Output:

See the following window

Description

To Create Graphical User Interface (GUI) application in Java needs to use of Swings.

Java swing components are platform independent, lightweight, provide powerful components like tables, textfield, panels, layouts, scroll panels, buttons, grid, list, font chooser ,color chooser, etc.

 Swing Framework contains a large set of components which allow us to create GUI components. javax.swing package contains classes and interfaces that are useful to create the GUI components using that we can create custom GUI applications.

In above program, we inheriting JFrame class to create JFrame window

Ex: class SimpleFrame extends JFrame

extends keyword is used to inherits one class in other class.

setSize() methoed is used to set size to window, we need to specify height and width of frame.

Releted Programs

© 2017 codewmAll rights reserved.