AWT , Abstract Window Toolkit in Java is used to write GUI programs.Today most of the front ends are using Graphical User Interface(GUI) programming due to many benefits such as user friendly,attractive,uses
different colors,uses many pictures,uses images,simulates real world components etc…
Java provides powerful GUI programming by using AWT.
The super class of all AWT components is Component.The sub class of Component is Container.
Container has two sub classes namely Window and Panel Window:
Window is the top level class which sits directly on the desktop.It has again two sub classes namely Frame and Dialog.
Frame:
It is the sub class of Window.A Frame contains title,background,foreground,other controls like
minimize,maximize etc…
Most of the AWT Programs are using a Frame window as their container.
The default Layout Manager of a Frame Window is a BorderLayout.
The two important methods used in a Frame class are void setSize(int width,int height)
where width and height are the dimensions of the Frame in pixels.
void setVissible(boolen b)
where b is a boolean data type and the Frame window will be visible if boolean value is true
Panel :
A Panel is a super class of Applet.
Generally a Panel is used as a subcontainer of componenets.
The default Layout Manager of a Panel and Applet is a FlowLayout
Creating a Frame Window:
We can create a Frame Window by importing java.awt package and extending a Frame class.
//Sample Frame Window program import java.awt.*;
class MyFrame extends Frame {
public static void main(String args[]) {
MyFrame mf=new MyFrame();
Mf.setTitle(“Frame Window Example”);
The above program creates a Frame Window with title name as Frame Window Example with pixels as 200 and 300.
Working with Graphics:
Graphics is a class available in java.awt
package.There are many methods available in Graphics class.This Graphics class is used to display anything on the Frame or Applet Window by using the method called paint() method.
Syntax of a paint() method:
public void paint(Graphics g)
There are many methods available in Graphics class.
void drawstring() is used to display any String or Message on the Applet or Frame window.
We can use Color and Font classes in Graphics class.
Color and Font are also the predefined classes in java.awt package.
Color:
It is class in java.awt package.
We can create an object of a Color class by using the constructor
Color(int red,int green, int blue)
Where red,green and blue are the integer values lies between 0 and 255.
Eg:
Color c1=new Color(0,0,0);
Color c2=new Color(255,255,255);
Color c3=new Color(100,50,200);
Color c4=new Color(20,100,240);
Where c1,c2,c3 and c4 are different Colors.
Font:
It is another class in java.awt package.
We can create an object of a Font class by using the constructor
Font(String s,int style,int size)
Where s is the name of the Font like TimesRoman,Sanserif,Monospaced etc…
Where style is BOLD,ITALIC,PLAIN or combination of styles and size is the size of Font
Eg:
Font f1=new Font(“TimesRoman”,Font.BOLD,40);
Font f2=new Font(“Monospaced”,Font.ITALIC,70);
Where f1,f2 are different objects of class Font
//Program working with Graphics by using Color and Font classes.
import java.awt.*;
import java.applet.*;
/*<Applet code=”NameApplet” width=300 height=500></Applet>*/
public class NameApplet extends Applet {
public void paint(Graphics g) {
Font f=new Font(“TimesRoman”,Font.BOLD,50);
g.setFont(f);
Color c=new Color(100,200,60);
g.setColor(c);
g.drawString(“Working with Graphics”,100,200);
} }
Controls used in AWT:
There are many controls used in AWT.
Some of the important controls used in AWT are
Label
Except Label Component all other Components have listeners.
Layout Managers :
It is essential to align the components properly in a given Container.Alignment of Components is very
difficult .This difficulty is avoided by using a proper Layout Manager.
There are many types of Layout managers used in AWT.Some of the important Layout Managers are
(i)BorderLayout
Reflection is the ability of a program to analyze itself. The java.lang.reflect package provides the ability to obtain information about the fields,constructors,methods, and modifiers of a class.
Reflection is used to determine dynamically the characteristics of a component
Remote Method Invocation(RMI) :
Remote method invocation(RMI) is a distributed
application developed in Java.By using RMI, we can invoke the method available in a remote machine.\
In RMI we have two machines where one machine acts as a Server and another machine acts as a Client.
To run an RMI application, we have to start RMIRegistry and we are using rmic compiler to create stubs and skeleton.
**************** E N D ********
Swing
Swing is an extension of AWT components in Java. Even though Java is platform independent language AWT
components are platform dependent.Hence the look and feel of AWT Components varies from one operating system to other
.
Swing components are platform independent and hence look and feel of these components is same on all operating systems.In addition Swing includes have more features such as TabbedPanes,Trees,Tables etc…
In Swing the visible components starts with “J” and the super class of all components is JComponent.
Some of the important Components in Swing are JLabel
We have to import java.awt and javax.swing package to write Swing programs
All the above Swing Components extends JApplet.
The main difference between Applet and JApplet is,in Applet we are directly adding components to the Applet where as in JApplet we are adding components to the ContentPane.
JApplet:Swing version of Applet.All swing visible components extends JApplet
Icons and Labels:
InSwing,icons are encapsulated by the ImageIcon class.Two of its constructors are
ImageIcon(String filename) where filename is the name of the image
ImageIcon(URL url) where url is the location of the image.
JLabel:
We can create an object of a JLabel component by using the constructor
JLabel() which is an empty constructor
JLabel(String s) where s is the name of the label JTextField :
We can create an object of a TextField in swing by using the constrcuctors
JTextField(int width) where width is the width of the text field
JTextField(String s) where s is a String displayed in the text
field.
JButton :
We can create an object of a Button in swing by using the constructors
JButton() where it creates a button without any name
JButton(String s) where it creates a button where s is it’s name
JComboBox :
It is similar to Choice in AWT.
We can create an object of a JComboBox by using it’s default constructor.
JComboBox()
We can add item to the combo box by using addItem(Object obj) method
TabbedPane :
It is a component that appears as a group of folders in a file cabinet.Each folder has a title.When a user selects a folder, its contents become visible.Only one of the folder is selected at a time.Tabbed panes are generally used for configuration options.
We can create an object of a Tabbed Pane by using the class
default constructor of JTabbedPane class ScrollPane:
ScrollPane is a component that presents a rectangular area in which a component may be viewed.Horizontal and /or vertical scroll bars may be provided if necessary.
We can create aa object by using a default constructor JScrollPane()
Tree:
A Tree is a component that presents a hierarchical view of data.A user has the ability to expand or collapse individual subtrees in this display.
A Tree in swing is obtained by extending JTree which extends JComponent
Table :
Table is a component that displays rows and columns of data.You can drag the cursor on column boundaries to resize columns.
We can create a Table in swing by extending JTable which extends JComponent.
************ E N D *********
JDBC(Java Data Base Connectivity)
Jdbc is a technology used to connect a Java program to any data base.
We have to import java.sql package for writing JDBC programs in Java