top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Graphics programming using AWT (Part I)

0 votes
475 views

                                                        Graphics Programming using AWT

Abstract Window Toolkit (AWT) represents a class library to develop applications using GUI. The java.awt package got classes and interfaces to develop GUI and let the users interact in a more friendly way with the applications.

Whenever an application (or software) is created, the user can work with it in two ways. The first way is where the user can remember some commands on which the application is built and type those commands to achieve the respective tasks. For example, the user may have to type a PRINT command to send a file contents to a printer. Here, the user should know the syntax and correct usage of the PRINT command. Then only he can interact with the application properly. This is called CUI (Character User Interface) since the user has to use characters or commands to interact with the application. The main disadvantage in CUI is that the user has to remember several commands and their use with correct syntax.

Hence, CUI is not user-friendly. A person who does not know any thing about computers will find this CUI very difficult.

The second way is where the user need no t remember any commands but interacts with any application by clicking on some images or graphics. For example, if the user want to print a file, he can click on a printer image and the rest of the things will be taken care of by the application. The user has to tell how many copies he wants and printing continues. This is very easy for the user since the user remembers only some symbols or images, like a magnifying glass symbol for searching, a briefcase symbol for a directory, etc. This environment where the user can interact with an application through graphics or images is called GUI (Graphics User Interface). 

GUI has the following advantages:

1) It is user-friendly. The user need not worry about any commands. Even a layman will be able to work with application developed using GUI.

2) It adds attraction and beauty to any application by adding pictures, colors, menus, animation, etc. We can observe almost all websites lure their visitors on Internet since they are developed attractively using GUI.

3) It is possible to simulate the real life objects using GUI. For example, a calculator program may actually display a real calculator on the screen. The user feels that he is interacting with a real calculator and he would be able to use it without any difficulty or special training. So, GUI eliminates the need of user training.

4) GUI helps to create graphical components like push buttons, radio buttons and check boxes use them effectively in our programs.

                                        Fig: Classes of AWT

Components

A  Component represents an object which is displayed pictorially on the screen. For example, we create an object of Button class as:

 Button b= new Button();

Now, b is the object of Button class. If we display this b on the screen, it displays a push button. Therefore, the object b, on going to the screen is becoming a component called 'push button',. In the same way, any component is a graphical representation of an object. Push button, radio buttons, check boxes, etc. are all components.

posted Jul 7, 2018 by Jon Deck

  Promote This Article
Facebook Share Button Twitter Share Button LinkedIn Share Button


Related Articles

Window and Frame

A window represents any imaginary rectangular area on the screen without any borders or title bar. A frame represents a window with some title and borders.In any application, we create frames to represent various screens where the user can type some data for the application and output screens where the result may be displayed in a particular form. Such screens are nothing but frames only.

Creating a Frame

A frame becomes the basic component in AWT. The frame has to be created before any other component. The reason is that all other components can be displayed in

a frame. There are three ways to create a frame, which are as follows:

1) Create a Frame class object,

Frame f = new Frame();

2) Create a Frame class object and pass its title also,

  Frame f = new Frame("My Frame");

3) The third way is to create a subclass MyFrame to the Frame class and create and object to the subclass as:

class MyFrame extends Frame

MyFrame f= new MyFrame();

Since, MyFrame is a subclass of Frame class, its object f contains a copy of Frame class hence f represents the frame. In all these cases, a frame with initial size of 0 pixels width and 0 pixels height will be created, which is not visible on the screen, You may be wondering what these pixels are. A pixel (Short for picture element) represents any single point or dot on the screen. Any data or pictures which are displayed on the screen are composed of several dots called pixels. Nowadays, monitors can accommodate 800 pixels horizontally and 600 pixels vertically. So the total pixels seen on one screen would be 800x768 pixels resolution.

Since, the size of our frame would be 0px height, it is ot visible and hence we should increase its size so that it would be visible to us. This is done by setSize() method, as:

f.setsize(400,350);

Here, the frame's width is set to 400px and height to 350px. Then, we can display the frame, using setVisible() method, as:

f.setVisible(true);

Small Program to create a frame by creating an object to Frame class.

//Creating a frame 

import java.awt.*;

class MyFrame

{

            public static void main(String args[])

            {

                     //create a frame

                    Frame f = new Frame("My AWT frame");

                    //set the size of the frame  

                    f.setSize(300,250);  

                    //display the frame  f.setVisible(true);

            }

}

Output

READ MORE
...