Java – Swings

Previous
Next

GUI:

  • Java API is providing classes and interfaces to implement GUI programming.
  • We were used Applets to implement GUI in early days.
  • Applets run with HTML pages.
  • Java code not run by JVM, applets run by browser interpreter.

javax.swing:

  • Swing is an extended package to applets.
  • Using swings, we can develop pure java based GUI applications.
  • Swing applications run by JVM only.
  • GUI is windows based.
  • Object creation of swing.JFrame class results a window.
import javax.swing.JFrame;
class GUI 
{
	public static void main(String[] args) 
	{
		JFrame frame = new JFrame();
		frame.setVisible(true); 
	}
}

We can create Custom frame by extending the functionality of JFrame class.

import javax.swing.JFrame;
class MyFrame extends JFrame
{
	MyFrame()
	{
		this.setTitle("First Frame");
		this.setSize(400,300);
	}
}
class GUI 
{
	public static void main(String[] args) 
	{
		MyFrame frame = new MyFrame();
		frame.setVisible(true); 
	}
}
Previous
Next

Add Comment

Courses Enquiry Form