Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
CORE JAVA
TOPIC: AWT(ABSTRACT WINDOW TOOLKIT)
MR. JAYANT. P. DALVI
AWT
• Java AWT (Abstract Window Toolkit) is an API to develop GUI or
window-based applications in java.
• Java AWT components are platform-dependent i.e. components are
displayed according to the view of operating system. AWT is
heavyweight i.e. its components are using the resources of OS.
• The java.awt package provides classes for AWT api such as TextField,
Label, TextArea, RadioButton, CheckBox, Choice, List etc.
HIERARCHY OF AWT CLASSES
• Container
The Container is a component in AWT that can contain another components like buttons, textfields,
labels etc. The classes that extends Container class are known as container such as Frame, Dialog
and Panel.
• Window
The window is the container that have no borders and menu bars. You must use frame, dialog or
another window for creating a window.
• Panel
The Panel is the container that doesn't contain title bar and menu bars. It can have other
components like button, textfield etc.
• Frame
The Frame is the container that contain title bar and can have menu bars. It can have other
components like button, textfield etc.

Recommended for you

AWT.pptx
AWT.pptxAWT.pptx
AWT.pptx

The document discusses Java Abstract Window Toolkit (AWT) which provides components to build graphical user interfaces. It describes that AWT components are platform dependent and heavy weight since they are built on top of native OS components. It then discusses the AWT component hierarchy including common components like buttons, text fields and containers like frames and panels that hold components. Specific AWT container types and common methods for working with AWT components are also summarized.

java
Awt, Swing, Layout managers
Awt, Swing, Layout managersAwt, Swing, Layout managers
Awt, Swing, Layout managers

The document discusses Java AWT and Swing GUI programming. It provides details on commonly used AWT and Swing components like Frame, Button, Label, Textfield. It explains the hierarchy and differences between AWT and Swing. Examples are provided to demonstrate creating a simple GUI using various components like Buttons, Labels and adding them to a Frame. The document also covers other Swing components like Checkboxes, Scrollpanes and containers like Frame, Dialog, Panel.

Java awt
Java awtJava awt
Java awt

- Java AWT (Abstract Windowing Toolkit) is an API that provides components to build graphical user interfaces (GUIs) in Java. It includes classes like TextField, Label, TextArea, etc. - AWT components are platform-dependent and heavyweight, using operating system resources. Common containers include Frame, Dialog, and Panel. - This document provides details on various AWT components like Label, Button, Checkbox, List, and TextField. It also covers events, listeners, and methods of these components.

awt ui elementsjava awt
Useful Methods of Component class
• Method and Description
1. public void add(Component c)-inserts a component on this
component.
2. public void setSize(int width,int height)- sets the size (width and
height) of the component.
3. public void setLayout(LayoutManager m)-defines the layout
manager for the component.
4. public void setVisible(boolean status)-changes the visibility of the
component, by default false.
How to write GUI application using AWT
• import the packages of awt and event
• create your class extends Frame implements ActionListener
• create objects/instances of components use in app
• set the positions of components- setBounds()
• register your component using addListener method
• add your instances of component inside the frame- add()
• setsize, setlayout, setvisible() methods
• override actionPerformed method()
• finally calling constructor of ur class inside main method.
AWT EXAMPLE
• To create simple awt example,
you need a frame.
• By extending Frame class
(inheritance)
import java.awt.*;
class First extends Frame{
First(){
Button b=new Button("click me");
b.setBounds(30,100,80,30);// setting button position
add(b);//adding button into frame
setSize(300,300);//frame size 300 width and 300 height
setLayout(null);//no layout manager
setVisible(true);//now frame will be visible, by default
not visible
}
public static void main(String args[]){
First f=new First();
}}
Java AWT Button
• The button class is used to create a
labeled button that has platform
independent implementation. The
application result in some action
when the button is pushed.
• AWT Button Class declaration
• public class Button extends
Component implements Accessible
Java AWT Button Example
import java.awt.*;
public class ButtonExample {
public static void main(String[] args) {
Frame f=new Frame("Button Example");
Button b=new Button("Click Here");
b.setBounds(50,100,80,30);
f.add(b);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
}

Recommended for you

GUI (graphical user interface)
GUI (graphical user interface)GUI (graphical user interface)
GUI (graphical user interface)

Graphical user interface (GUI) allows users to interact with applications visually rather than through text commands. There are two main Java APIs for GUI programming: AWT and Swing. AWT consists of core graphics classes like containers (frames, panels), components (buttons, text fields), and layout managers. It also supports event handling through classes like ActionEvent and interfaces like ActionListener. Applets are Java programs that run in web browsers - they are embedded in HTML pages and their code is downloaded to the user's machine. Applets have a lifecycle of methods like init(), start(), stop() that are called at different times.

gui(graphical user interface)guirisi ram khanal
Advance Java Programming (CM5I) 1.AWT
Advance Java Programming (CM5I) 1.AWTAdvance Java Programming (CM5I) 1.AWT
Advance Java Programming (CM5I) 1.AWT

This document provides an overview of the Abstract Windowing Toolkit (AWT) in Java. It discusses that AWT is platform-dependent and heavyweight, using system resources. The core AWT classes like Container, Component, and Window are described. Common controls like buttons, checkboxes, lists and text fields are also covered. The key classes for building graphical user interfaces with AWT like Frame, Panel and Applet are explained.

awtajpmsbte
Unit 5 java-awt (1)
Unit 5 java-awt (1)Unit 5 java-awt (1)
Unit 5 java-awt (1)

The document discusses the Java Abstract Window Toolkit (AWT). It describes that AWT is used to create graphical user interface applications in Java and its components are platform dependent. It then lists and describes various AWT components like containers, frames, panels, labels, buttons, checkboxes, lists, text fields, text areas, canvases and scroll bars. It also discusses how to create frames using inheritance and association. Finally, it provides examples of using buttons, text fields and text areas in AWT applications.

OUTPUT OF BUTTON EXAMPLE
Event and Listener (Java Event Handling)
• Changing the state of an
object is known as an event.
• For example, click on button,
dragging mouse etc. The
java.awt.event package
provides many event classes
and Listener interfaces for
event handling.
Steps to perform Event Handling
• Following steps are required to perform event
handling:Register the component with the Listener
• Registration Methods
• For registering the component with the Listener, many
classes provide the registration methods. For example:
• Button
public void addActionListener(ActionListener a){}
• MenuItem
public void addActionListener(ActionListener a){}
• TextField
public void addActionListener(ActionListener a){}
public void addTextListener(TextListener a){}
• TextArea
public void addTextListener(TextListener a){}
• Checkbox
public void addItemListener(ItemListener a){}
• Choice
public void addItemListener(ItemListener a){}
• List
public void addActionListener(ActionListener
a){}
public void addItemListener(ItemListener a){}
EXAMPLE
import java.awt.*;
import java.awt.event.*;
class AEvent extends Frame implements ActionListener{
TextField tf;
AEvent(){
//create components
tf=new TextField();
tf.setBounds(60,50,170,20);
Button b=new Button("click me");
b.setBounds(100,120,80,30);
//register listener
b.addActionListener(this);
//add components and set size, layout and visibility
add(b);
add(tf);
setSize(300,300);
setLayout(null);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
tf.setText("Welcome");
}
public static void main(String args[]){
new AEvent();
}
}

Recommended for you

Java awt tutorial javatpoint
Java awt tutorial   javatpointJava awt tutorial   javatpoint
Java awt tutorial javatpoint

This document provides an overview of Java AWT (Abstract Window Toolkit), which is an API for developing GUI applications in Java. It discusses key AWT concepts like components, containers, frames and panels. It also provides examples of creating simple AWT applications by extending the Frame class and by instantiating the Frame class. The examples demonstrate how to add buttons to a frame and set the button position and frame size.

Applet in java
Applet in javaApplet in java
Applet in java

Java Applet Basics, Important points, Life cycle of an applet, AWT, AWT HIERARCHY, Creating Frame by extending Frame class, Creating Frame by creating instance of Frame class, Java Exceptions, Java try and catch, Syntax, Example for try and catch,

appletawt and exception
tL19 awt
tL19 awttL19 awt
tL19 awt

This document provides an overview of GUI programming basics using the AWT API in Java. It discusses the key component, container and layout manager classes used to create graphical user interfaces in Java. Component classes like Button, Label and TextField are used to add interactive elements, while container classes like Frame and Panel hold other components. Layout managers help position and organize components visually. The document also provides examples of creating simple frames and applications using these AWT classes.

javateach4u.in
OUTPUT OF EXAMPLE
Java AWT Label
• The object of Label class is a component for placing text in a
container. It is used to display a single line of read only text. The text
can be changed by an application but a user cannot edit it directly.
import java.awt.*;
class LabelExample{
public static void main(String args[]){
Frame f= new Frame("Label Example");
Label l1,l2;
l1=new Label("First Label.");
l1.setBounds(50,100, 100,30);
l2=new Label("Second Label.");
l2.setBounds(50,150, 100,30);
f.add(l1); f.add(l2);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
}
Java AWT TextField
• The object of a TextField class is a text component that allows the
editing of a single line text. It inherits TextComponent class.

Recommended for you

PPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKD
PPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKDPPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKD
PPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKD

This document discusses event handling in Java. It describes how events are triggered by changes in an object's state. The java.awt.event package provides event classes and listener interfaces for handling events. There are several steps to perform event handling: register a component with a listener using registration methods, implement the listener interface, and add event handling code either within the class, in another class, or as an anonymous class. Examples are provided of each approach to handling button click events and updating a text field.

innovation
Abstract Window Toolkit
Abstract Window ToolkitAbstract Window Toolkit
Abstract Window Toolkit

The document discusses the Abstract Window Toolkit (AWT) in Java. Some key points: - AWT allows developing graphical user interfaces (GUIs) in Java and its components are platform-dependent. - The AWT class hierarchy includes Component, Container, Window, Panel, Frame, and Dialog classes. Containers hold other components. - Layout managers determine how components are arranged. Common layouts include flow, grid, border, and card layouts.

java
CORE JAVA-2
CORE JAVA-2CORE JAVA-2
CORE JAVA-2

The document provides an overview of core Java concepts including Abstract Windowing Toolkit (AWT), event handling, Swing, layout managers, and applets. It discusses AWT components like containers, windows, panels and frames. It also covers creating frames, setting buttons, and different approaches to event handling like within a class, with an outer class, or anonymously. The document reviews Swing components and hierarchies. It includes examples of creating Swing frames and using buttons, radio buttons, and displaying images on buttons.

javacore javabasic java
import java.awt.*;
class TextFieldExample{
public static void main(String args[]){
Frame f= new Frame("TextField Example");
TextField t1,t2;
t1=new TextField("Welcome to Javatpoint.");
t1.setBounds(50,100, 200,30);
t2=new TextField("AWT Tutorial");
t2.setBounds(50,150, 200,30);
f.add(t1); f.add(t2);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
}
import java.awt.*;
import java.awt.event.*;
public class TextFieldExample extends Frame implements ActionListener{
TextField tf1,tf2,tf3;
Button b1,b2;
TextFieldExample(){
tf1=new TextField();
tf1.setBounds(50,50,150,20);
tf2=new TextField();
tf2.setBounds(50,100,150,20);
tf3=new TextField();
tf3.setBounds(50,150,150,20);
tf3.setEditable(false);
b1=new Button("+");
b1.setBounds(50,200,50,50);
b2=new Button("-");
b2.setBounds(120,200,50,50);
b1.addActionListener(this);
b2.addActionListener(this);
add(tf1);add(tf2);add(tf3);add(b1);add(b2);
setSize(300,300);
setLayout(null);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
String s1=tf1.getText();
String s2=tf2.getText();
int a=Integer.parseInt(s1);
int b=Integer.parseInt(s2);
int c=0;
if(e.getSource()==b1){
c=a+b;
}else if(e.getSource()==b2){
c=a-b;
}
String result=String.valueOf(c);
tf3.setText(result);
}
public static void main(String[] args) {
new TextFieldExample();
}
}
Java AWT TextArea
• The object of a TextArea class is
a multi line region that displays
text. It allows the editing of
multiple line text. It inherits
TextComponent class.
import java.awt.*;
public class TextAreaExample
{
TextAreaExample(){
Frame f= new Frame();
TextArea area=new TextArea("Welcome to javatpoint");
area.setBounds(10,30, 300,300);
f.add(area);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
public static void main(String args[])
{
new TextAreaExample();
}
}
import java.awt.*;
import java.awt.event.*;
public class TextAreaExample extends Frame implements
ActionListener{
Label l1,l2;
TextArea area;
Button b;
TextAreaExample(){
l1=new Label();
l1.setBounds(50,50,100,30);
l2=new Label();
l2.setBounds(160,50,100,30);
area=new TextArea();
area.setBounds(20,100,300,300);
b=new Button("Count Words");
b.setBounds(100,400,100,30);
b.addActionListener(this);
add(l1);add(l2);add(area);add(b);
setSize(400,450);
setLayout(null);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
String text=area.getText();
String words[]=text.split("s");
l1.setText("Words: "+words.length);
l2.setText("Characters: "+text.length());
}
public static void main(String[] args) {
new TextAreaExample();
}
}

Recommended for you

28 awt
28 awt28 awt
28 awt

The document discusses Java GUI building using AWT and Swing. It explains that AWT is the original toolkit for building GUIs in Java but that Swing provides more advanced and flexible components. It outlines the basic steps for building a GUI with a container, components, layout managers, and listeners to add interactivity. Key topics covered include common components, adding components to containers, using layout managers, and implementing listeners to handle user events.

SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made EasySwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy

SWTBot is a open source UI testing tool for SWT and Eclipse based applications. It requires bare minimum learning since it is Java based and integrates well with the JUnit framework. An ideal unit testing tool for SWT and Eclipse based applications developers.

unit testingswt botswtbot
Gui
GuiGui
Gui

This document discusses the evolution of graphical user interface (GUI) capabilities in the Java programming language. It describes the Abstract Window Toolkit (AWT) introduced in JDK 1.0, which provided basic cross-platform GUI functionality but had limitations. JDK 1.1 improved on AWT with an event delegation model. JDK 1.2 introduced Swing, a richer GUI library that better integrated with native operating system look and feels. Swing components are lightweight compared to heavyweight AWT components. The document also covers GUI component classes, layout managers, menus, labels and event handling in Java GUI programming.

swingjavagui
Java AWT Checkbox
• The Checkbox class is used to
create a checkbox. It is used to
turn an option on (true) or off
(false). Clicking on a Checkbox
changes its state from "on" to
"off" or from "off" to "on"
import java.awt.*;
public class CheckboxExample
{
CheckboxExample(){
Frame f= new Frame("Checkbox Example");
Checkbox checkbox1 = new Checkbox("C++");
checkbox1.setBounds(100,100, 50,50);
Checkbox checkbox2 = new Checkbox("Java", true);
checkbox2.setBounds(100,150, 50,50);
f.add(checkbox1);
f.add(checkbox2);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
public static void main(String args[])
{
new CheckboxExample();
}
}
import java.awt.*;
import java.awt.event.*;
public class CheckboxExample
{
CheckboxExample(){
Frame f= new Frame("CheckBox Example");
final Label label = new Label();
label.setAlignment(Label.CENTER);
label.setSize(400,100);
Checkbox checkbox1 = new Checkbox("C++");
checkbox1.setBounds(100,100, 50,50);
Checkbox checkbox2 = new Checkbox("Java");
checkbox2.setBounds(100,150, 50,50);
f.add(checkbox1); f.add(checkbox2); f.add(label);
checkbox1.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
label.setText("C++ Checkbox: "
+ (e.getStateChange()==1?"checked":"unchecked"));
}
});
checkbox2.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
label.setText("Java Checkbox: "
+ (e.getStateChange()==1?"checked":"unchecked"));
}
});
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
public static void main(String args[])
{
new CheckboxExample();
}
}
Java AWT List
• The object of List class
represents a list of text items. By
the help of list, user can choose
either one item or multiple
items. It inherits Component
class.
import java.awt.*;
public class ListExample
{
ListExample(){
Frame f= new Frame();
List l1=new List(5);
l1.setBounds(100,100, 75,75);
l1.add("Item 1");
l1.add("Item 2");
l1.add("Item 3");
l1.add("Item 4");
l1.add("Item 5");
f.add(l1);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
public static void main(String args[])
{
new ListExample();
}
}
import java.awt.*;
import java.awt.event.*;
public class ListExample
{
ListExample(){
Frame f= new Frame();
final Label label = new Label();
label.setAlignment(Label.CENTER);
label.setSize(500,100);
Button b=new Button("Show");
b.setBounds(200,150,80,30);
final List l1=new List(4, false);
l1.setBounds(100,100, 70,70);
l1.add("C");
l1.add("C++");
l1.add("Java");
l1.add("PHP");
final List l2=new List(4, true);
l2.setBounds(100,200, 70,70);
l2.add("Turbo C++");
l2.add("Spring");
l2.add("Hibernate");
l2.add("CodeIgniter");
f.add(l1); f.add(l2); f.add(label); f.add(b);
f.setSize(450,450);
f.setLayout(null);
f.setVisible(true);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String data = "Programming language Selected:
"+l1.getItem(l1.getSelectedIndex());
data += ", Framework Selected:";

Recommended for you

Text field and textarea
Text field and textareaText field and textarea
Text field and textarea

This document discusses the TextField and TextArea components in Java. TextField implements a single-line text entry area, allowing users to enter and edit strings. TextArea is for multi-line text input and defines constructors that allow specifying the number of lines and characters. Examples show how to create text fields and areas, set properties like echo characters, and retrieve entered text. Quizzes and frequently asked questions cover using these components and related methods.

13457272.ppt
13457272.ppt13457272.ppt
13457272.ppt

Swing is a Java GUI widget toolkit that improves upon the older AWT toolkit. It includes common GUI components like JFrame, JPanel, and JLabel. JFrame represents a window, JPanel is used to group and layout components, and JLabel displays text. These components have constructors and methods to create, configure, add, and listen to GUI elements. Layout managers automatically position components and should be used for most applications.

java
Linux System Administration
Linux System AdministrationLinux System Administration
Linux System Administration

Bash Shell Scripting, Elements of Shell Scripting, variables, arguments, control structures, pattern matching, substitution operators

linuxshell scripting
for(String
frame:l2.getSelectedItems()){
data += frame + " ";
}
label.setText(data);
}
});
}
public static void main(String
args[])
{
new ListExample();
}
}
Java AWT Scrollbar
• The object of Scrollbar class is
used to add horizontal and
vertical scrollbar. Scrollbar is a
GUI component allows us to see
invisible number of rows and
columns.
import java.awt.*;
class ScrollbarExample{
ScrollbarExample(){
Frame f= new Frame("Scrollbar Example");
Scrollbar s=new Scrollbar();
s.setBounds(100,100, 50,100);
f.add(s);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
public static void main(String args[]){
new ScrollbarExample();
}
}
Java AWT MenuItem and Menu
• The object of MenuItem class adds a simple labeled menu item on
menu. The items used in a menu must belong to the MenuItem or any
of its subclass.
• The object of Menu class is a pull down menu component which is
displayed on the menu bar. It inherits the MenuItem class.
import java.awt.*;
class MenuExample
{
MenuExample(){
Frame f= new Frame("Menu and MenuItem Example");
MenuBar mb=new MenuBar();
Menu menu=new Menu("Menu");
Menu submenu=new Menu("Sub Menu");
MenuItem i1=new MenuItem("Item 1");
MenuItem i2=new MenuItem("Item 2");
MenuItem i3=new MenuItem("Item 3");
MenuItem i4=new MenuItem("Item 4");
MenuItem i5=new MenuItem("Item 5");
menu.add(i1);
menu.add(i2);
menu.add(i3);
submenu.add(i4);
submenu.add(i5);
menu.add(submenu);
mb.add(menu);
f.setMenuBar(mb);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
public static void main(String args[])
{
new MenuExample();
}
}

Recommended for you

Linux System Administration
Linux System AdministrationLinux System Administration
Linux System Administration

Managing Software, RPM, Repositories, Installing software with Yum, Installing Package, Package groups

linux
Structured system analysis and design
Structured system analysis and design Structured system analysis and design
Structured system analysis and design

The document discusses principles and guidelines for designing user interfaces, input, output, and forms for a structured system analysis and design. Some key points: 1. The user interface is the most important part of the system for users and should be informative, appealing, user-friendly, and attractive. 2. Input design involves data collection, validation, and ensuring the interface allows for efficient user interaction. Output design focuses on principles like simplicity, timeliness, and promoting decision making. 3. Guidelines for interface, input, output, and form design include considering objectives, contents, format, frequency, medium, and location. Validation checks and error detection are also important aspects of input design.

ui design
Structured system analysis and design
Structured system analysis and design Structured system analysis and design
Structured system analysis and design

System Testing and Quality Assurance- Need of testing, types of testing, levels of testing, process of testing, quality assurance

ssadtesting
radio buttons example
import java.awt.*;
import java.awt.event.*;
public class CheckboxGroupExample
{
CheckboxGroupExample(){
Frame f= new Frame("CheckboxGroup Example");
final Label label = new Label();
label.setAlignment(Label.CENTER);
label.setSize(400,100);
CheckboxGroup cbg = new CheckboxGroup();
Checkbox checkBox1 = new Checkbox("C++", cbg, false);
checkBox1.setBounds(100,100, 50,50);
Checkbox checkBox2 = new Checkbox("Java", cbg, false);
checkBox2.setBounds(100,150, 50,50);
f.add(checkBox1); f.add(checkBox2); f.add(label);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
checkBox1.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
label.setText("C++ checkbox: Checked");
}
});
checkBox2.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
label.setText("Java checkbox: Checked");
}
});
}
public static void main(String args[])
{
new CheckboxGroupExample();
}
}

More Related Content

Similar to java- Abstract Window toolkit

object oriented programming examples
object oriented programming examplesobject oriented programming examples
object oriented programming examples
Abdii Rashid
 
AWT New-3.pptx
AWT New-3.pptxAWT New-3.pptx
AWT New-3.pptx
SarthakSrivastava70
 
javaprogramming framework-ppt frame.pptx
javaprogramming framework-ppt frame.pptxjavaprogramming framework-ppt frame.pptx
javaprogramming framework-ppt frame.pptx
DrDGayathriDevi
 
AWT.pptx
AWT.pptxAWT.pptx
AWT.pptx
FAHMIDAASEEZ1
 
Awt, Swing, Layout managers
Awt, Swing, Layout managersAwt, Swing, Layout managers
Awt, Swing, Layout managers
swapnac12
 
Java awt
Java awtJava awt
Java awt
Arati Gadgil
 
GUI (graphical user interface)
GUI (graphical user interface)GUI (graphical user interface)
GUI (graphical user interface)
rishi ram khanal
 
Advance Java Programming (CM5I) 1.AWT
Advance Java Programming (CM5I) 1.AWTAdvance Java Programming (CM5I) 1.AWT
Advance Java Programming (CM5I) 1.AWT
Payal Dungarwal
 
Unit 5 java-awt (1)
Unit 5 java-awt (1)Unit 5 java-awt (1)
Unit 5 java-awt (1)
DevaKumari Vijay
 
Java awt tutorial javatpoint
Java awt tutorial   javatpointJava awt tutorial   javatpoint
Java awt tutorial javatpoint
Ricardo Garcia
 
Applet in java
Applet in javaApplet in java
Applet in java
Jancypriya M
 
tL19 awt
tL19 awttL19 awt
tL19 awt
teach4uin
 
PPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKD
PPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKDPPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKD
PPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKD
chessvashisth
 
Abstract Window Toolkit
Abstract Window ToolkitAbstract Window Toolkit
Abstract Window Toolkit
RutvaThakkar1
 
CORE JAVA-2
CORE JAVA-2CORE JAVA-2
28 awt
28 awt28 awt
28 awt
Prachi Vijh
 
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made EasySwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
Ankit Goel
 
Gui
GuiGui
Text field and textarea
Text field and textareaText field and textarea
Text field and textarea
myrajendra
 
13457272.ppt
13457272.ppt13457272.ppt
13457272.ppt
aptechaligarh
 

Similar to java- Abstract Window toolkit (20)

object oriented programming examples
object oriented programming examplesobject oriented programming examples
object oriented programming examples
 
AWT New-3.pptx
AWT New-3.pptxAWT New-3.pptx
AWT New-3.pptx
 
javaprogramming framework-ppt frame.pptx
javaprogramming framework-ppt frame.pptxjavaprogramming framework-ppt frame.pptx
javaprogramming framework-ppt frame.pptx
 
AWT.pptx
AWT.pptxAWT.pptx
AWT.pptx
 
Awt, Swing, Layout managers
Awt, Swing, Layout managersAwt, Swing, Layout managers
Awt, Swing, Layout managers
 
Java awt
Java awtJava awt
Java awt
 
GUI (graphical user interface)
GUI (graphical user interface)GUI (graphical user interface)
GUI (graphical user interface)
 
Advance Java Programming (CM5I) 1.AWT
Advance Java Programming (CM5I) 1.AWTAdvance Java Programming (CM5I) 1.AWT
Advance Java Programming (CM5I) 1.AWT
 
Unit 5 java-awt (1)
Unit 5 java-awt (1)Unit 5 java-awt (1)
Unit 5 java-awt (1)
 
Java awt tutorial javatpoint
Java awt tutorial   javatpointJava awt tutorial   javatpoint
Java awt tutorial javatpoint
 
Applet in java
Applet in javaApplet in java
Applet in java
 
tL19 awt
tL19 awttL19 awt
tL19 awt
 
PPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKD
PPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKDPPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKD
PPThbkjn;l sdc a;s'jjN djkHBSDjhhIDoj LKD
 
Abstract Window Toolkit
Abstract Window ToolkitAbstract Window Toolkit
Abstract Window Toolkit
 
CORE JAVA-2
CORE JAVA-2CORE JAVA-2
CORE JAVA-2
 
28 awt
28 awt28 awt
28 awt
 
SwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made EasySwtBot: Unit Testing Made Easy
SwtBot: Unit Testing Made Easy
 
Gui
GuiGui
Gui
 
Text field and textarea
Text field and textareaText field and textarea
Text field and textarea
 
13457272.ppt
13457272.ppt13457272.ppt
13457272.ppt
 

More from Jayant Dalvi

Linux System Administration
Linux System AdministrationLinux System Administration
Linux System Administration
Jayant Dalvi
 
Linux System Administration
Linux System AdministrationLinux System Administration
Linux System Administration
Jayant Dalvi
 
Structured system analysis and design
Structured system analysis and design Structured system analysis and design
Structured system analysis and design
Jayant Dalvi
 
Structured system analysis and design
Structured system analysis and design Structured system analysis and design
Structured system analysis and design
Jayant Dalvi
 
Structured system analysis and design
Structured system analysis and design Structured system analysis and design
Structured system analysis and design
Jayant Dalvi
 
Java I/O
Java I/OJava I/O
Java I/O
Jayant Dalvi
 
Information system audit 2
Information system audit 2 Information system audit 2
Information system audit 2
Jayant Dalvi
 
Structured system analysis and design
Structured system analysis and design Structured system analysis and design
Structured system analysis and design
Jayant Dalvi
 
Structured system analysis and design
Structured system analysis and design Structured system analysis and design
Structured system analysis and design
Jayant Dalvi
 
Information system audit
Information system audit Information system audit
Information system audit
Jayant Dalvi
 
Information system audit
Information system audit Information system audit
Information system audit
Jayant Dalvi
 
Structured system analysis and design
Structured system analysis and design Structured system analysis and design
Structured system analysis and design
Jayant Dalvi
 
Information system audit
Information system audit Information system audit
Information system audit
Jayant Dalvi
 
Multithreading in Java
Multithreading in JavaMultithreading in Java
Multithreading in Java
Jayant Dalvi
 
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++
Jayant Dalvi
 
Object Oriented Programming using C++
Object Oriented Programming using C++Object Oriented Programming using C++
Object Oriented Programming using C++
Jayant Dalvi
 

More from Jayant Dalvi (16)

Linux System Administration
Linux System AdministrationLinux System Administration
Linux System Administration
 
Linux System Administration
Linux System AdministrationLinux System Administration
Linux System Administration
 
Structured system analysis and design
Structured system analysis and design Structured system analysis and design
Structured system analysis and design
 
Structured system analysis and design
Structured system analysis and design Structured system analysis and design
Structured system analysis and design
 
Structured system analysis and design
Structured system analysis and design Structured system analysis and design
Structured system analysis and design
 
Java I/O
Java I/OJava I/O
Java I/O
 
Information system audit 2
Information system audit 2 Information system audit 2
Information system audit 2
 
Structured system analysis and design
Structured system analysis and design Structured system analysis and design
Structured system analysis and design
 
Structured system analysis and design
Structured system analysis and design Structured system analysis and design
Structured system analysis and design
 
Information system audit
Information system audit Information system audit
Information system audit
 
Information system audit
Information system audit Information system audit
Information system audit
 
Structured system analysis and design
Structured system analysis and design Structured system analysis and design
Structured system analysis and design
 
Information system audit
Information system audit Information system audit
Information system audit
 
Multithreading in Java
Multithreading in JavaMultithreading in Java
Multithreading in Java
 
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++
 
Object Oriented Programming using C++
Object Oriented Programming using C++Object Oriented Programming using C++
Object Oriented Programming using C++
 

Recently uploaded

ENGLISH-7-CURRICULUM MAP- MATATAG CURRICULUM
ENGLISH-7-CURRICULUM MAP- MATATAG CURRICULUMENGLISH-7-CURRICULUM MAP- MATATAG CURRICULUM
ENGLISH-7-CURRICULUM MAP- MATATAG CURRICULUM
HappieMontevirgenCas
 
Righteous among Nations - eTwinning e-book (1).pdf
Righteous among Nations - eTwinning e-book (1).pdfRighteous among Nations - eTwinning e-book (1).pdf
Righteous among Nations - eTwinning e-book (1).pdf
Zuzana Mészárosová
 
Beyond the Advance Presentation for By the Book 9
Beyond the Advance Presentation for By the Book 9Beyond the Advance Presentation for By the Book 9
Beyond the Advance Presentation for By the Book 9
John Rodzvilla
 
Credit limit improvement system in odoo 17
Credit limit improvement system in odoo 17Credit limit improvement system in odoo 17
Credit limit improvement system in odoo 17
Celine George
 
Front Desk Management in the Odoo 17 ERP
Front Desk  Management in the Odoo 17 ERPFront Desk  Management in the Odoo 17 ERP
Front Desk Management in the Odoo 17 ERP
Celine George
 
Book Allied Health Sciences kmu MCQs.docx
Book Allied Health Sciences kmu MCQs.docxBook Allied Health Sciences kmu MCQs.docx
Book Allied Health Sciences kmu MCQs.docx
drtech3715
 
Delegation Inheritance in Odoo 17 and Its Use Cases
Delegation Inheritance in Odoo 17 and Its Use CasesDelegation Inheritance in Odoo 17 and Its Use Cases
Delegation Inheritance in Odoo 17 and Its Use Cases
Celine George
 
The Jewish Trinity : Sabbath,Shekinah and Sanctuary 4.pdf
The Jewish Trinity : Sabbath,Shekinah and Sanctuary 4.pdfThe Jewish Trinity : Sabbath,Shekinah and Sanctuary 4.pdf
The Jewish Trinity : Sabbath,Shekinah and Sanctuary 4.pdf
JackieSparrow3
 
ARCHITECTURAL PATTERNS IN HISTOPATHOLOGY pdf- [Autosaved].pdf
ARCHITECTURAL PATTERNS IN HISTOPATHOLOGY  pdf-  [Autosaved].pdfARCHITECTURAL PATTERNS IN HISTOPATHOLOGY  pdf-  [Autosaved].pdf
ARCHITECTURAL PATTERNS IN HISTOPATHOLOGY pdf- [Autosaved].pdf
DharmarajPawar
 
Capitol Doctoral Presentation -June 2024v2.pptx
Capitol Doctoral Presentation -June 2024v2.pptxCapitol Doctoral Presentation -June 2024v2.pptx
Capitol Doctoral Presentation -June 2024v2.pptx
CapitolTechU
 
How to Configure Time Off Types in Odoo 17
How to Configure Time Off Types in Odoo 17How to Configure Time Off Types in Odoo 17
How to Configure Time Off Types in Odoo 17
Celine George
 
AI_in_HR_Presentation Part 1 2024 0703.pdf
AI_in_HR_Presentation Part 1 2024 0703.pdfAI_in_HR_Presentation Part 1 2024 0703.pdf
AI_in_HR_Presentation Part 1 2024 0703.pdf
SrimanigandanMadurai
 
Bedok NEWater Photostory - COM322 Assessment (Story 2)
Bedok NEWater Photostory - COM322 Assessment (Story 2)Bedok NEWater Photostory - COM322 Assessment (Story 2)
Bedok NEWater Photostory - COM322 Assessment (Story 2)
Liyana Rozaini
 
How to Install Theme in the Odoo 17 ERP
How to  Install Theme in the Odoo 17 ERPHow to  Install Theme in the Odoo 17 ERP
How to Install Theme in the Odoo 17 ERP
Celine George
 
Principles of Roods Approach!!!!!!!.pptx
Principles of Roods Approach!!!!!!!.pptxPrinciples of Roods Approach!!!!!!!.pptx
Principles of Roods Approach!!!!!!!.pptx
ibtesaam huma
 
Is Email Marketing Really Effective In 2024?
Is Email Marketing Really Effective In 2024?Is Email Marketing Really Effective In 2024?
Is Email Marketing Really Effective In 2024?
Rakesh Jalan
 
Lecture_Notes_Unit4_Chapter_8_9_10_RDBMS for the students affiliated by alaga...
Lecture_Notes_Unit4_Chapter_8_9_10_RDBMS for the students affiliated by alaga...Lecture_Notes_Unit4_Chapter_8_9_10_RDBMS for the students affiliated by alaga...
Lecture_Notes_Unit4_Chapter_8_9_10_RDBMS for the students affiliated by alaga...
Murugan Solaiyappan
 
Chapter-2-Era-of-One-party-Dominance-Class-12-Political-Science-Notes-2 (1).pptx
Chapter-2-Era-of-One-party-Dominance-Class-12-Political-Science-Notes-2 (1).pptxChapter-2-Era-of-One-party-Dominance-Class-12-Political-Science-Notes-2 (1).pptx
Chapter-2-Era-of-One-party-Dominance-Class-12-Political-Science-Notes-2 (1).pptx
Brajeswar Paul
 
Split Shifts From Gantt View in the Odoo 17
Split Shifts From Gantt View in the  Odoo 17Split Shifts From Gantt View in the  Odoo 17
Split Shifts From Gantt View in the Odoo 17
Celine George
 
No, it's not a robot: prompt writing for investigative journalism
No, it's not a robot: prompt writing for investigative journalismNo, it's not a robot: prompt writing for investigative journalism
No, it's not a robot: prompt writing for investigative journalism
Paul Bradshaw
 

Recently uploaded (20)

ENGLISH-7-CURRICULUM MAP- MATATAG CURRICULUM
ENGLISH-7-CURRICULUM MAP- MATATAG CURRICULUMENGLISH-7-CURRICULUM MAP- MATATAG CURRICULUM
ENGLISH-7-CURRICULUM MAP- MATATAG CURRICULUM
 
Righteous among Nations - eTwinning e-book (1).pdf
Righteous among Nations - eTwinning e-book (1).pdfRighteous among Nations - eTwinning e-book (1).pdf
Righteous among Nations - eTwinning e-book (1).pdf
 
Beyond the Advance Presentation for By the Book 9
Beyond the Advance Presentation for By the Book 9Beyond the Advance Presentation for By the Book 9
Beyond the Advance Presentation for By the Book 9
 
Credit limit improvement system in odoo 17
Credit limit improvement system in odoo 17Credit limit improvement system in odoo 17
Credit limit improvement system in odoo 17
 
Front Desk Management in the Odoo 17 ERP
Front Desk  Management in the Odoo 17 ERPFront Desk  Management in the Odoo 17 ERP
Front Desk Management in the Odoo 17 ERP
 
Book Allied Health Sciences kmu MCQs.docx
Book Allied Health Sciences kmu MCQs.docxBook Allied Health Sciences kmu MCQs.docx
Book Allied Health Sciences kmu MCQs.docx
 
Delegation Inheritance in Odoo 17 and Its Use Cases
Delegation Inheritance in Odoo 17 and Its Use CasesDelegation Inheritance in Odoo 17 and Its Use Cases
Delegation Inheritance in Odoo 17 and Its Use Cases
 
The Jewish Trinity : Sabbath,Shekinah and Sanctuary 4.pdf
The Jewish Trinity : Sabbath,Shekinah and Sanctuary 4.pdfThe Jewish Trinity : Sabbath,Shekinah and Sanctuary 4.pdf
The Jewish Trinity : Sabbath,Shekinah and Sanctuary 4.pdf
 
ARCHITECTURAL PATTERNS IN HISTOPATHOLOGY pdf- [Autosaved].pdf
ARCHITECTURAL PATTERNS IN HISTOPATHOLOGY  pdf-  [Autosaved].pdfARCHITECTURAL PATTERNS IN HISTOPATHOLOGY  pdf-  [Autosaved].pdf
ARCHITECTURAL PATTERNS IN HISTOPATHOLOGY pdf- [Autosaved].pdf
 
Capitol Doctoral Presentation -June 2024v2.pptx
Capitol Doctoral Presentation -June 2024v2.pptxCapitol Doctoral Presentation -June 2024v2.pptx
Capitol Doctoral Presentation -June 2024v2.pptx
 
How to Configure Time Off Types in Odoo 17
How to Configure Time Off Types in Odoo 17How to Configure Time Off Types in Odoo 17
How to Configure Time Off Types in Odoo 17
 
AI_in_HR_Presentation Part 1 2024 0703.pdf
AI_in_HR_Presentation Part 1 2024 0703.pdfAI_in_HR_Presentation Part 1 2024 0703.pdf
AI_in_HR_Presentation Part 1 2024 0703.pdf
 
Bedok NEWater Photostory - COM322 Assessment (Story 2)
Bedok NEWater Photostory - COM322 Assessment (Story 2)Bedok NEWater Photostory - COM322 Assessment (Story 2)
Bedok NEWater Photostory - COM322 Assessment (Story 2)
 
How to Install Theme in the Odoo 17 ERP
How to  Install Theme in the Odoo 17 ERPHow to  Install Theme in the Odoo 17 ERP
How to Install Theme in the Odoo 17 ERP
 
Principles of Roods Approach!!!!!!!.pptx
Principles of Roods Approach!!!!!!!.pptxPrinciples of Roods Approach!!!!!!!.pptx
Principles of Roods Approach!!!!!!!.pptx
 
Is Email Marketing Really Effective In 2024?
Is Email Marketing Really Effective In 2024?Is Email Marketing Really Effective In 2024?
Is Email Marketing Really Effective In 2024?
 
Lecture_Notes_Unit4_Chapter_8_9_10_RDBMS for the students affiliated by alaga...
Lecture_Notes_Unit4_Chapter_8_9_10_RDBMS for the students affiliated by alaga...Lecture_Notes_Unit4_Chapter_8_9_10_RDBMS for the students affiliated by alaga...
Lecture_Notes_Unit4_Chapter_8_9_10_RDBMS for the students affiliated by alaga...
 
Chapter-2-Era-of-One-party-Dominance-Class-12-Political-Science-Notes-2 (1).pptx
Chapter-2-Era-of-One-party-Dominance-Class-12-Political-Science-Notes-2 (1).pptxChapter-2-Era-of-One-party-Dominance-Class-12-Political-Science-Notes-2 (1).pptx
Chapter-2-Era-of-One-party-Dominance-Class-12-Political-Science-Notes-2 (1).pptx
 
Split Shifts From Gantt View in the Odoo 17
Split Shifts From Gantt View in the  Odoo 17Split Shifts From Gantt View in the  Odoo 17
Split Shifts From Gantt View in the Odoo 17
 
No, it's not a robot: prompt writing for investigative journalism
No, it's not a robot: prompt writing for investigative journalismNo, it's not a robot: prompt writing for investigative journalism
No, it's not a robot: prompt writing for investigative journalism
 

java- Abstract Window toolkit

  • 1. CORE JAVA TOPIC: AWT(ABSTRACT WINDOW TOOLKIT) MR. JAYANT. P. DALVI
  • 2. AWT • Java AWT (Abstract Window Toolkit) is an API to develop GUI or window-based applications in java. • Java AWT components are platform-dependent i.e. components are displayed according to the view of operating system. AWT is heavyweight i.e. its components are using the resources of OS. • The java.awt package provides classes for AWT api such as TextField, Label, TextArea, RadioButton, CheckBox, Choice, List etc.
  • 4. • Container The Container is a component in AWT that can contain another components like buttons, textfields, labels etc. The classes that extends Container class are known as container such as Frame, Dialog and Panel. • Window The window is the container that have no borders and menu bars. You must use frame, dialog or another window for creating a window. • Panel The Panel is the container that doesn't contain title bar and menu bars. It can have other components like button, textfield etc. • Frame The Frame is the container that contain title bar and can have menu bars. It can have other components like button, textfield etc.
  • 5. Useful Methods of Component class • Method and Description 1. public void add(Component c)-inserts a component on this component. 2. public void setSize(int width,int height)- sets the size (width and height) of the component. 3. public void setLayout(LayoutManager m)-defines the layout manager for the component. 4. public void setVisible(boolean status)-changes the visibility of the component, by default false.
  • 6. How to write GUI application using AWT • import the packages of awt and event • create your class extends Frame implements ActionListener • create objects/instances of components use in app • set the positions of components- setBounds() • register your component using addListener method • add your instances of component inside the frame- add() • setsize, setlayout, setvisible() methods • override actionPerformed method() • finally calling constructor of ur class inside main method.
  • 7. AWT EXAMPLE • To create simple awt example, you need a frame. • By extending Frame class (inheritance) import java.awt.*; class First extends Frame{ First(){ Button b=new Button("click me"); b.setBounds(30,100,80,30);// setting button position add(b);//adding button into frame setSize(300,300);//frame size 300 width and 300 height setLayout(null);//no layout manager setVisible(true);//now frame will be visible, by default not visible } public static void main(String args[]){ First f=new First(); }}
  • 8. Java AWT Button • The button class is used to create a labeled button that has platform independent implementation. The application result in some action when the button is pushed. • AWT Button Class declaration • public class Button extends Component implements Accessible Java AWT Button Example import java.awt.*; public class ButtonExample { public static void main(String[] args) { Frame f=new Frame("Button Example"); Button b=new Button("Click Here"); b.setBounds(50,100,80,30); f.add(b); f.setSize(400,400); f.setLayout(null); f.setVisible(true); } }
  • 10. Event and Listener (Java Event Handling) • Changing the state of an object is known as an event. • For example, click on button, dragging mouse etc. The java.awt.event package provides many event classes and Listener interfaces for event handling.
  • 11. Steps to perform Event Handling • Following steps are required to perform event handling:Register the component with the Listener • Registration Methods • For registering the component with the Listener, many classes provide the registration methods. For example: • Button public void addActionListener(ActionListener a){} • MenuItem public void addActionListener(ActionListener a){} • TextField public void addActionListener(ActionListener a){} public void addTextListener(TextListener a){} • TextArea public void addTextListener(TextListener a){} • Checkbox public void addItemListener(ItemListener a){} • Choice public void addItemListener(ItemListener a){} • List public void addActionListener(ActionListener a){} public void addItemListener(ItemListener a){}
  • 12. EXAMPLE import java.awt.*; import java.awt.event.*; class AEvent extends Frame implements ActionListener{ TextField tf; AEvent(){ //create components tf=new TextField(); tf.setBounds(60,50,170,20); Button b=new Button("click me"); b.setBounds(100,120,80,30); //register listener b.addActionListener(this); //add components and set size, layout and visibility add(b); add(tf); setSize(300,300); setLayout(null); setVisible(true); } public void actionPerformed(ActionEvent e){ tf.setText("Welcome"); } public static void main(String args[]){ new AEvent(); } }
  • 14. Java AWT Label • The object of Label class is a component for placing text in a container. It is used to display a single line of read only text. The text can be changed by an application but a user cannot edit it directly.
  • 15. import java.awt.*; class LabelExample{ public static void main(String args[]){ Frame f= new Frame("Label Example"); Label l1,l2; l1=new Label("First Label."); l1.setBounds(50,100, 100,30); l2=new Label("Second Label."); l2.setBounds(50,150, 100,30); f.add(l1); f.add(l2); f.setSize(400,400); f.setLayout(null); f.setVisible(true); } }
  • 16. Java AWT TextField • The object of a TextField class is a text component that allows the editing of a single line text. It inherits TextComponent class.
  • 17. import java.awt.*; class TextFieldExample{ public static void main(String args[]){ Frame f= new Frame("TextField Example"); TextField t1,t2; t1=new TextField("Welcome to Javatpoint."); t1.setBounds(50,100, 200,30); t2=new TextField("AWT Tutorial"); t2.setBounds(50,150, 200,30); f.add(t1); f.add(t2); f.setSize(400,400); f.setLayout(null); f.setVisible(true); } }
  • 18. import java.awt.*; import java.awt.event.*; public class TextFieldExample extends Frame implements ActionListener{ TextField tf1,tf2,tf3; Button b1,b2; TextFieldExample(){ tf1=new TextField(); tf1.setBounds(50,50,150,20); tf2=new TextField(); tf2.setBounds(50,100,150,20); tf3=new TextField(); tf3.setBounds(50,150,150,20); tf3.setEditable(false); b1=new Button("+"); b1.setBounds(50,200,50,50); b2=new Button("-"); b2.setBounds(120,200,50,50); b1.addActionListener(this); b2.addActionListener(this); add(tf1);add(tf2);add(tf3);add(b1);add(b2); setSize(300,300); setLayout(null); setVisible(true); } public void actionPerformed(ActionEvent e) { String s1=tf1.getText(); String s2=tf2.getText(); int a=Integer.parseInt(s1); int b=Integer.parseInt(s2); int c=0; if(e.getSource()==b1){ c=a+b; }else if(e.getSource()==b2){ c=a-b; } String result=String.valueOf(c); tf3.setText(result); } public static void main(String[] args) { new TextFieldExample(); } }
  • 19. Java AWT TextArea • The object of a TextArea class is a multi line region that displays text. It allows the editing of multiple line text. It inherits TextComponent class. import java.awt.*; public class TextAreaExample { TextAreaExample(){ Frame f= new Frame(); TextArea area=new TextArea("Welcome to javatpoint"); area.setBounds(10,30, 300,300); f.add(area); f.setSize(400,400); f.setLayout(null); f.setVisible(true); } public static void main(String args[]) { new TextAreaExample(); } }
  • 20. import java.awt.*; import java.awt.event.*; public class TextAreaExample extends Frame implements ActionListener{ Label l1,l2; TextArea area; Button b; TextAreaExample(){ l1=new Label(); l1.setBounds(50,50,100,30); l2=new Label(); l2.setBounds(160,50,100,30); area=new TextArea(); area.setBounds(20,100,300,300); b=new Button("Count Words"); b.setBounds(100,400,100,30); b.addActionListener(this); add(l1);add(l2);add(area);add(b); setSize(400,450); setLayout(null); setVisible(true); } public void actionPerformed(ActionEvent e){ String text=area.getText(); String words[]=text.split("s"); l1.setText("Words: "+words.length); l2.setText("Characters: "+text.length()); } public static void main(String[] args) { new TextAreaExample(); } }
  • 21. Java AWT Checkbox • The Checkbox class is used to create a checkbox. It is used to turn an option on (true) or off (false). Clicking on a Checkbox changes its state from "on" to "off" or from "off" to "on" import java.awt.*; public class CheckboxExample { CheckboxExample(){ Frame f= new Frame("Checkbox Example"); Checkbox checkbox1 = new Checkbox("C++"); checkbox1.setBounds(100,100, 50,50); Checkbox checkbox2 = new Checkbox("Java", true); checkbox2.setBounds(100,150, 50,50); f.add(checkbox1); f.add(checkbox2); f.setSize(400,400); f.setLayout(null); f.setVisible(true); } public static void main(String args[]) { new CheckboxExample(); } }
  • 22. import java.awt.*; import java.awt.event.*; public class CheckboxExample { CheckboxExample(){ Frame f= new Frame("CheckBox Example"); final Label label = new Label(); label.setAlignment(Label.CENTER); label.setSize(400,100); Checkbox checkbox1 = new Checkbox("C++"); checkbox1.setBounds(100,100, 50,50); Checkbox checkbox2 = new Checkbox("Java"); checkbox2.setBounds(100,150, 50,50); f.add(checkbox1); f.add(checkbox2); f.add(label); checkbox1.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { label.setText("C++ Checkbox: " + (e.getStateChange()==1?"checked":"unchecked")); } }); checkbox2.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { label.setText("Java Checkbox: " + (e.getStateChange()==1?"checked":"unchecked")); } }); f.setSize(400,400); f.setLayout(null); f.setVisible(true); } public static void main(String args[]) { new CheckboxExample(); } }
  • 23. Java AWT List • The object of List class represents a list of text items. By the help of list, user can choose either one item or multiple items. It inherits Component class. import java.awt.*; public class ListExample { ListExample(){ Frame f= new Frame(); List l1=new List(5); l1.setBounds(100,100, 75,75); l1.add("Item 1"); l1.add("Item 2"); l1.add("Item 3"); l1.add("Item 4"); l1.add("Item 5"); f.add(l1); f.setSize(400,400); f.setLayout(null); f.setVisible(true); } public static void main(String args[]) { new ListExample(); } }
  • 24. import java.awt.*; import java.awt.event.*; public class ListExample { ListExample(){ Frame f= new Frame(); final Label label = new Label(); label.setAlignment(Label.CENTER); label.setSize(500,100); Button b=new Button("Show"); b.setBounds(200,150,80,30); final List l1=new List(4, false); l1.setBounds(100,100, 70,70); l1.add("C"); l1.add("C++"); l1.add("Java"); l1.add("PHP"); final List l2=new List(4, true); l2.setBounds(100,200, 70,70); l2.add("Turbo C++"); l2.add("Spring"); l2.add("Hibernate"); l2.add("CodeIgniter"); f.add(l1); f.add(l2); f.add(label); f.add(b); f.setSize(450,450); f.setLayout(null); f.setVisible(true); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String data = "Programming language Selected: "+l1.getItem(l1.getSelectedIndex()); data += ", Framework Selected:";
  • 25. for(String frame:l2.getSelectedItems()){ data += frame + " "; } label.setText(data); } }); } public static void main(String args[]) { new ListExample(); } }
  • 26. Java AWT Scrollbar • The object of Scrollbar class is used to add horizontal and vertical scrollbar. Scrollbar is a GUI component allows us to see invisible number of rows and columns. import java.awt.*; class ScrollbarExample{ ScrollbarExample(){ Frame f= new Frame("Scrollbar Example"); Scrollbar s=new Scrollbar(); s.setBounds(100,100, 50,100); f.add(s); f.setSize(400,400); f.setLayout(null); f.setVisible(true); } public static void main(String args[]){ new ScrollbarExample(); } }
  • 27. Java AWT MenuItem and Menu • The object of MenuItem class adds a simple labeled menu item on menu. The items used in a menu must belong to the MenuItem or any of its subclass. • The object of Menu class is a pull down menu component which is displayed on the menu bar. It inherits the MenuItem class.
  • 28. import java.awt.*; class MenuExample { MenuExample(){ Frame f= new Frame("Menu and MenuItem Example"); MenuBar mb=new MenuBar(); Menu menu=new Menu("Menu"); Menu submenu=new Menu("Sub Menu"); MenuItem i1=new MenuItem("Item 1"); MenuItem i2=new MenuItem("Item 2"); MenuItem i3=new MenuItem("Item 3"); MenuItem i4=new MenuItem("Item 4"); MenuItem i5=new MenuItem("Item 5"); menu.add(i1); menu.add(i2); menu.add(i3); submenu.add(i4); submenu.add(i5); menu.add(submenu); mb.add(menu); f.setMenuBar(mb); f.setSize(400,400); f.setLayout(null); f.setVisible(true); } public static void main(String args[]) { new MenuExample(); } }
  • 29. radio buttons example import java.awt.*; import java.awt.event.*; public class CheckboxGroupExample { CheckboxGroupExample(){ Frame f= new Frame("CheckboxGroup Example"); final Label label = new Label(); label.setAlignment(Label.CENTER); label.setSize(400,100); CheckboxGroup cbg = new CheckboxGroup(); Checkbox checkBox1 = new Checkbox("C++", cbg, false); checkBox1.setBounds(100,100, 50,50); Checkbox checkBox2 = new Checkbox("Java", cbg, false); checkBox2.setBounds(100,150, 50,50); f.add(checkBox1); f.add(checkBox2); f.add(label); f.setSize(400,400); f.setLayout(null); f.setVisible(true); checkBox1.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { label.setText("C++ checkbox: Checked"); } }); checkBox2.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent e) { label.setText("Java checkbox: Checked"); } }); } public static void main(String args[]) { new CheckboxGroupExample(); } }