AWT Event Classes ”; Previous Next The Event classes represent the event. Java provides us various Event classes but we will discuss those which are more frequently used. EventObject class It is the root class from which all event state objects shall be derived. All Events are constructed with a reference to the object, the source, that is logically deemed to be the object upon which the Event in question initially occurred upon.This class is defined in java.util package. Class declaration Following is the declaration for java.util.EventObject class: public class EventObject extends Object implements Serializable Field Following are the fields for java.util.EventObject class: protected Object source — The object on which the Event initially occurred. Class constructors S.N. Constructor & Description 1 EventObject(Object source) Constructs a prototypical Event. Class methods S.N. Method & Description 1 Object getSource() The object on which the Event initially occurred. 2 String toString() Returns a String representation of this EventObject. Methods inherited This class inherits methods from the following classes: java.lang.Object AWT Event Classes: Following is the list of commonly used event classes. Sr. No. Control & Description 1 AWTEvent It is the root event class for all AWT events. This class and its subclasses supercede the original java.awt.Event class. 2 ActionEvent The ActionEvent is generated when button is clicked or the item of a list is double clicked. 3 InputEvent The InputEvent class is root event class for all component-level input events. 4 KeyEvent On entering the character the Key event is generated. 5 MouseEvent This event indicates a mouse action occurred in a component. 6 TextEvent The object of this class represents the text events. 7 WindowEvent The object of this class represents the change in state of a window. 8 AdjustmentEvent The object of this class represents the adjustment event emitted by Adjustable objects. 9 ComponentEvent The object of this class represents the change in state of a window. 10 ContainerEvent The object of this class represents the change in state of a window. 11 MouseMotionEvent The object of this class represents the change in state of a window. 12 PaintEvent The object of this class represents the change in state of a window. Print Page Previous Next Advertisements ”;
Category: awt
AWT – Useful Resources
AWT – Useful Resources ”; Previous Next The following resources contain additional information on AWT. Please use them to get more in-depth knowledge on this topic. Useful Websites on Java The JavaTM Tutorials − The Java Tutorials are practical guides for programmers who want to use the Java programming language to create applications. JavaTM 2 SDK, Standard Edition − Official site for JavaTM 2 SDK, Standard Edition Free Java Download − Download Java for your desktop computer now! Sun Developer Network − Sun Microsystem”s official website listing down all the API documentation, latest Java Technologies, Books and other resource. Useful Books on AWT & Java To enlist your site on this page, please drop an email to [email protected] Print Page Previous Next Advertisements ”;
AWT – Event Listeners
AWT Event Listeners ”; Previous Next The Event listener represent the interfaces responsible to handle events. Java provides us various Event listener classes but we will discuss those which are more frequently used. Every method of an event listener method has a single argument as an object which is subclass of EventObject class. For example, mouse event listener methods will accept instance of MouseEvent, where MouseEvent derives from EventObject. EventListner interface It is a marker interface which every listener interface has to extend.This class is defined in java.util package. Class declaration Following is the declaration for java.util.EventListener interface: public interface EventListener AWT Event Listener Interfaces: Following is the list of commonly used event listeners. Sr. No. Control & Description 1 ActionListener This interface is used for receiving the action events. 2 ComponentListener This interface is used for receiving the component events. 3 ItemListener This interface is used for receiving the item events. 4 KeyListener This interface is used for receiving the key events. 5 MouseListener This interface is used for receiving the mouse events. 6 TextListener This interface is used for receiving the text events. 7 WindowListener This interface is used for receiving the window events. 8 AdjustmentListener This interface is used for receiving the adjusmtent events. 9 ContainerListener This interface is used for receiving the container events. 10 MouseMotionListener This interface is used for receiving the mouse motion events. 11 FocusListener This interface is used for receiving the focus events. Print Page Previous Next Advertisements ”;
AWT – Menu
AWT Menu Classes ”; Previous Next As we know that every top-level window has a menu bar associated with it. This menu bar consist of various menu choices available to the end user. Further each choice contains list of options which is called drop down menus. Menu and MenuItem controls are subclass of MenuComponent class. Menu Hiearchy Menu Controls Sr. No. Control & Description 1 MenuComponent It is the top level class for all menu related controls. 2 MenuBar The MenuBar object is associated with the top-level window. 3 MenuItem The items in the menu must belong to the MenuItem or any of its subclass. 4 Menu The Menu object is a pull-down menu component which is displayed from the menu bar. 5 CheckboxMenuItem CheckboxMenuItem is subclass of MenuItem. 6 PopupMenu PopupMenu can be dynamically popped up at a specified position within a component. Print Page Previous Next Advertisements ”;
AWT – Quick Guide
AWT Quick Guide ”; Previous Next Graphical User Interface Graphical User Interface (GUI) offers user interaction via some graphical components. For example our underlying Operating System also offers GUI via window,frame,Panel, Button, Textfield, TextArea, Listbox, Combobox, Label, Checkbox etc. These all are known as components. Using these components we can create an interactive user interface for an application. GUI provides result to end user in response to raised events.GUI is entirely based events. For example clicking over a button, closing a window, opening a window, typing something in a textarea etc. These activities are known as events.GUI makes it easier for the end user to use an application. It also makes them interesting. Basic Terminologies Term Description Component Component is an object having a graphical representation that can be displayed on the screen and that can interact with the user. For examples buttons, checkboxes, list and scrollbars of a graphical user interface. Container Container object is a component that can contain other components.Components added to a container are tracked in a list. The order of the list will define the components” front-to-back stacking order within the container. If no index is specified when adding a component to a container, it will be added to the end of the list. Panel Panel provides space in which an application can attach any other components, including other panels. Window Window is a rectangular area which is displayed on the screen. In different window we can execute different program and display different data. Window provide us with multitasking environment. A window must have either a frame, dialog, or another window defined as its owner when it”s constructed. Frame A Frame is a top-level window with a title and a border. The size of the frame includes any area designated for the border. Frame encapsulates window. It and has a title bar, menu bar, borders, and resizing corners. Canvas Canvas component represents a blank rectangular area of the screen onto which the application can draw. Application can also trap input events from the use from that blank area of Canvas component. Examples of GUI based Applications Following are some of the examples for GUI based applications. Automated Teller Machine (ATM) Airline Ticketing System Information Kiosks at railway stations Mobile Applications Navigation Systems Advantages of GUI over CUI GUI provides graphical icons to interact while the CUI (Character User Interface) offers the simple text-based interfaces. GUI makes the application more entertaining and interesting on the other hand CUI does not. GUI offers click and execute environment while in CUI every time we have to enter the command for a task. New user can easily interact with graphical user interface by the visual indicators but it is difficult in Character user interface. GUI offers a lot of controls of file system and the operating system while in CUI you have to use commands which is difficult to remember. Windows concept in GUI allow the user to view, manipulate and control the multiple applications at once while in CUI user can control one task at a time. GUI provides multitasking environment so as the CUI also does but CUI does not provide same ease as the GUI do. Using GUI it is easier to control and navigate the operating system which becomes very slow in command user interface. GUI can be easily customized. Environment Setup This section guides you on how to download and set up Java on your machine. Please follow the following steps to set up the environment. Java SE is freely available from the link Download Java. So you download a version based on your operating system. Follow the instructions to download java and run the .exe to install Java on your machine. Once you installed Java on your machine, you would need to set environment variables to point to correct installation directories: Setting up the path for windows 2000/XP: Assuming you have installed Java in c:Program Filesjavajdk directory: Right-click on ”My Computer” and select ”Properties”. Click on the ”Environment variables” button under the ”Advanced” tab. Now alter the ”Path” variable so that it also contains the path to the Java executable. Example, if the path is currently set to ”C:WINDOWSSYSTEM32”, then change your path to read ”C:WINDOWSSYSTEM32;c:Program Filesjavajdkbin”. Setting up the path for windows 95/98/ME: Assuming you have installed Java in c:Program Filesjavajdk directory: Edit the ”C:autoexec.bat” file and add the following line at the end: ”SET PATH=%PATH%;C:Program Filesjavajdkbin” Setting up the path for Linux, UNIX, Solaris, FreeBSD: Environment variable PATH should be set to point to where the java binaries have been installed. Refer to your shell documentation if you have trouble doing this. Example, if you use bash as your shell, then you would add the following line to the end of your ”.bashrc: export PATH=/path/to/java:$PATH” Popular Java Editors: To write your java programs you will need a text editor. There are even more sophisticated IDE available in the market. But for now, you can consider one of the following: Notepad : On Windows machine you can use any simple text editor like Notepad (Recommended for this tutorial), TextPad. Netbeans :is a Java IDE that is open source and free which can be downloaded from http://www.netbeans.org/index.html. Eclipse : is also a java IDE developed by the eclipse open source community and can be downloaded from http://www.eclipse.org/. AWT Controls Every user interface considers the following three main aspects: UI elements : Thes are the core visual elements the user eventually sees and interacts with. GWT provides a huge list of widely used and common elements varying from basic to complex which we will cover in this tutorial. Layouts: They define how UI elements should be organized on the screen and provide a final look and feel to the GUI (Graphical User Interface). This part will be covered in Layout chapter. Behavior: These are events which occur when the user interacts with UI elements. This part will be covered in Event Handling chapter. Every AWT controls inherits properties from Component
AWT – Layouts
AWT Layouts ”; Previous Next Introduction Layout means the arrangement of components within the container. In other way we can say that placing the components at a particular position within the container. The task of layouting the controls is done automatically by the Layout Manager. Layout Manager The layout manager automatically positions all the components within the container. If we do not use layout manager then also the components are positioned by the default layout manager. It is possible to layout the controls by hand but it becomes very difficult because of the following two reasons. It is very tedious to handle a large number of controls within the container. Oftenly the width and height information of a component is not given when we need to arrange them. Java provide us with various layout manager to position the controls. The properties like size,shape and arrangement varies from one layout manager to other layout manager. When the size of the applet or the application window changes the size, shape and arrangement of the components also changes in response i.e. the layout managers adapt to the dimensions of appletviewer or the application window. The layout manager is associated with every Container object. Each layout manager is an object of the class that implements the LayoutManager interface. Following are the interfaces defining functionalities of Layout Managers. Sr. No. Interface & Description 1 LayoutManager The LayoutManager interface declares those methods which need to be implemented by the class whose object will act as a layout manager. 2 LayoutManager2 The LayoutManager2 is the sub-interface of the LayoutManager.This interface is for those classes that know how to layout containers based on layout constraint object. AWT Layout Manager Classes: Following is the list of commonly used controls while designed GUI using AWT. Sr. No. LayoutManager & Description 1 BorderLayout The borderlayout arranges the components to fit in the five regions: east, west, north, south and center. 2 CardLayout The CardLayout object treats each component in the container as a card. Only one card is visible at a time. 3 FlowLayout The FlowLayout is the default layout.It layouts the components in a directional flow. 4 GridLayout The GridLayout manages the components in form of a rectangular grid. 5 GridBagLayout This is the most flexible layout manager class.The object of GridBagLayout aligns the component vertically,horizontally or along their baseline without requiring the components of same size. Print Page Previous Next Advertisements ”;
AWT – Overview
AWT – Overview ”; Previous Next Graphical User Interface Graphical User Interface (GUI) offers user interaction via some graphical components. For example our underlying Operating System also offers GUI via window,frame,Panel, Button, Textfield, TextArea, Listbox, Combobox, Label, Checkbox etc. These all are known as components. Using these components we can create an interactive user interface for an application. GUI provides result to end user in response to raised events.GUI is entirely based events. For example clicking over a button, closing a window, opening a window, typing something in a textarea etc. These activities are known as events.GUI makes it easier for the end user to use an application. It also makes them interesting. Basic Terminologies Term Description Component Component is an object having a graphical representation that can be displayed on the screen and that can interact with the user. For examples buttons, checkboxes, list and scrollbars of a graphical user interface. Container Container object is a component that can contain other components.Components added to a container are tracked in a list. The order of the list will define the components” front-to-back stacking order within the container. If no index is specified when adding a component to a container, it will be added to the end of the list. Panel Panel provides space in which an application can attach any other components, including other panels. Window Window is a rectangular area which is displayed on the screen. In different window we can execute different program and display different data. Window provide us with multitasking environment. A window must have either a frame, dialog, or another window defined as its owner when it”s constructed. Frame A Frame is a top-level window with a title and a border. The size of the frame includes any area designated for the border. Frame encapsulates window. It and has a title bar, menu bar, borders, and resizing corners. Canvas Canvas component represents a blank rectangular area of the screen onto which the application can draw. Application can also trap input events from the use from that blank area of Canvas component. Examples of GUI based Applications Following are some of the examples for GUI based applications. Automated Teller Machine (ATM) Airline Ticketing System Information Kiosks at railway stations Mobile Applications Navigation Systems Advantages of GUI over CUI GUI provides graphical icons to interact while the CUI (Character User Interface) offers the simple text-based interfaces. GUI makes the application more entertaining and interesting on the other hand CUI does not. GUI offers click and execute environment while in CUI every time we have to enter the command for a task. New user can easily interact with graphical user interface by the visual indicators but it is difficult in Character user interface. GUI offers a lot of controls of file system and the operating system while in CUI you have to use commands which is difficult to remember. Windows concept in GUI allow the user to view, manipulate and control the multiple applications at once while in CUI user can control one task at a time. GUI provides multitasking environment so as the CUI also does but CUI does not provide same ease as the GUI do. Using GUI it is easier to control and navigate the operating system which becomes very slow in command user interface. GUI can be easily customized. Print Page Previous Next Advertisements ”;
AWT – Controls
AWT Controls ”; Previous Next Every user interface considers the following three main aspects: UI elements : Thes are the core visual elements the user eventually sees and interacts with. GWT provides a huge list of widely used and common elements varying from basic to complex which we will cover in this tutorial. Layouts: They define how UI elements should be organized on the screen and provide a final look and feel to the GUI (Graphical User Interface). This part will be covered in Layout chapter. Behavior: These are events which occur when the user interacts with UI elements. This part will be covered in Event Handling chapter. Every AWT controls inherits properties from Component class. Sr. No. Control & Description 1 Component A Component is an abstract super class for GUI controls and it represents an object with graphical representation. AWT UI Elements: Following is the list of commonly used controls while designed GUI using AWT. Sr. No. Control & Description 1 Label A Label object is a component for placing text in a container. 2 Button This class creates a labeled button. 3 Check Box A check box is a graphical component that can be in either an on (true) or off (false) state. 4 Check Box Group The CheckboxGroup class is used to group the set of checkbox. 5 List The List component presents the user with a scrolling list of text items. 6 Text Field A TextField object is a text component that allows for the editing of a single line of text. 7 Text Area A TextArea object is a text component that allows for the editing of a multiple lines of text. 8 Choice A Choice control is used to show pop up menu of choices. Selected choice is shown on the top of the menu. 9 Canvas A Canvas control represents a rectangular area where application can draw something or can receive inputs created by user. 10 Image An Image control is superclass for all image classes representing graphical images. 11 Scroll Bar A Scrollbar control represents a scroll bar component in order to enable user to select from range of values. 12 Dialog A Dialog control represents a top-level window with a title and a border used to take some form of input from the user. 13 File Dialog A FileDialog control represents a dialog window from which the user can select a file. Print Page Previous Next Advertisements ”;