

Text2=new TextField("This tutorial is of Java") Text1=new TextField("Welcome to studytonight") This text is editable in nature, see the below example.įrame TextF_f= new Frame("studytonight =>TextField") We are creating two textfields to display single line text string. Public class TextField extends TextComponent Example: It is used for displaying single line text. Lab2=new Label("This Tutorial is of Java") In this example, we are creating two labels to display text to the frame.įrame l_Frame= new Frame("studytonight => Label Demo") Public class Label extends Component implements Accessible Example:

Only Single line text is allowed and the text can not be changed directly. It is used for placing text in a container. Lets take an example to create a button and it to the frame by providing coordinates.įrame f1=new Frame("studytonight => Button Demo")

Public class Button extends Component implements Accessible Example: It is used for creating a labelled button which can perform an action.

You can add the following method also for resizing the frame - setResizable(true).Then you need to add it to the frame by using the method - add(Component's Object) When you create other components like Buttons, TextFields, etc.While creating a frame (either by instantiating or extending Frame class), Following two attributes are must for visibility of the frame:.Testawt ta = new Testawt() //creating a frame. SetVisible(true) //set frame visibilty true. SetLayout(new FlowLayout()) //set default layout for frame. SetTitle("StudyTonight") //setting title. Label lb = new Label("welcome to java graphics") //Creating a labelįm.setSize(300, 300) //setting frame size.įm.setVisible(true) //set frame visibilty trueĬreating Frame window by extending Frame class They are,Ĭreating Frame Window by Instantiating Frame class import java.awt.* Frame class has two different constructors, Frame() throws HeadlessExceptionįrame(String title) throws HeadlessException Creating a Frame In Java, most of the AWT applications are created using Frame window. It is a container that contain several different components like button, title bar, textfield, label etc. Window does not have borders and menubar.įrame is a subclass of Window and have resizing canvas. It is container that is used for holding components. Panel does not contain title bar, menu bar or border. Panel class is a concrete subclass of Container. Container class keeps track of components that are added to another component. Container is a subclass of component class. ContainerĬontainer is a component in AWT that contains another component like button, text field, tables etc. A component object is responsible for remembering the current foreground and background colors and the currently selected text font. It is an abstract class that encapsulates all the attributes of visual component. The hierarchy of Java AWT classes are given below, all the classes are available in java.awt package.Ĭomponent class is at the top of AWT hierarchy. But now a days AWT is merely used because most GUI Java programs are implemented using Swing because of its rich implementation of GUI controls and light-weighted nature. But the disadvantage of such an approach is that GUI designed on one platform may look different when displayed on another platform that means AWT component are platform dependent.ĪWT is the foundation upon which Swing is made i.e Swing is a improved GUI API that extends the AWT. The tools provided by the AWT are implemented using each platform's native GUI toolkit, hence preserving the look and feel of each platform. The AWT was designed to provide a common set of tools for GUI design that could work on a variety of platforms. Java AWT is an API that contains large number of classes and methods to create and manage graphical user interface ( GUI ) applications.
#The class at the top of the awt hierarchy is driver
