Java FX
Java FX
GUI is an user interface where the user interacts with the computer
using graphics. Graphics include icons, navigation bars, images, etc. A
mouse can be used while using this interface to interact with the
graphics. It is a very user-friendly interface and requires no expertise.
Eg: Windows has GUI.
AWT(Abstract Windowing Toolkit)
It is a Framework, it will provide very good
environment to prepare GUI Applications.
2. Swing
3.AWT-(Abstract Window
Container class
• The Container is a component in AWT that can contain another
components like buttons, textfields, labels etc. The Container class
extends Frame and Panel.
Commonly used Methods of Component class
Method Description
add(Component c) inserts a component on this component.
setSize(int width,int height) sets the size (width and height) of the component.
setLayout(LayoutManager m) defines the layout manager for the component.
setVisible(boolean status) changes the visibility of the component, by default false.
To create simple awt example, you need a frame. There are two ways to create a
frame in AWT.
• By extending Frame class (inheritance)
Ex:
class Example extends Frame
{
……..
}
• By creating the object of Frame class (association)
Ex:
class Example {
Frame obj=new Frame();
……..
}
A Simple AWT Example
SimpleExample.java
import java.awt.*;
public class AwtExample
{
public static void main(String[] args)
{
Frame f=new Frame();
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
f.setTitle("Simple Example");
}
}
Output:
Javac AwtExample.java
Java AwtExample