0% found this document useful (0 votes)
14 views48 pages

Chapter1 AWT

The document outlines the curriculum and teaching methods for advanced Java programming at Government Polytechnic Aurangabad, focusing on GUI development using AWT and SWING. It details various components, classes, and methods used in Java for creating graphical user interfaces, including event handling, layout management, and menu creation. The document serves as a comprehensive guide for students learning to develop web and stand-alone applications in Java.

Uploaded by

sayaligayke810
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views48 pages

Chapter1 AWT

The document outlines the curriculum and teaching methods for advanced Java programming at Government Polytechnic Aurangabad, focusing on GUI development using AWT and SWING. It details various components, classes, and methods used in Java for creating graphical user interfaces, including event handling, layout management, and menu creation. The document serves as a comprehensive guide for students learning to develop web and stand-alone applications in Java.

Uploaded by

sayaligayke810
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Government Polytechnic Aurangabd

Department Of Computer Engineering

-With Mr. [Link]


Lecturer in Computer Engineering
1. Develop web and stand-alone applications using
advanced java concepts.

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
1. Develop Programs using GUI Framework (AWT and SWING).
2. Handle events of AWT and SWING.
3. Develops programs to handle events in Java programming.
4. Develop Java Programs using networking concepts.
5. Develop programs using Database
6. Develop programs using Servlet.

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Mr. Gajanan Jadhav
Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
1. AWT is an API ( Application Programming Interface) to develop
GUI or Window Based Application.
2. A GUI is built of graphical elements called COMPONENT like
Button, Scrollbar, Text Field etc.
3. To learn in detail about AWT we require in built java package
[Link] .
4. And need to import in program using statement
import [Link].*;

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
1. Java awt package contains different classes For example---
1. Button 9. MenuBar 16. Font
2. Label 10. Menu 17. Event
3. TextField 11. MenuItem 18. Dialog
4. Scrollbar 12. Frame 19. Canvas
5. Checkbox 13. Container 20. AWTEvent
6. Panel 14. Graphics
7. Window 15. TextArea And So many…..
8. GridLayout

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic, Ambad
Mr. Gajanan Jadhav
Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
1. At the top of AWT hierarchy is the Component class.
2. Component is an abstract class that encapsulates all of the
attributes of a Visual Component.

Container
1. The Container class is a subclass of Component.
2. It has additional methods that allow other Component objects to
be nested within it.
3. A container is responsible for laying out (that is, positioning) any
components that it contains. It does this through the use of various
layout managers

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
1. The window is the container that have no borders and menu
bars.
2. You must use frame, dialog or another window for creating
a window.
Frame
1. The Frame is the container that contain title bar and can have
menu bars.
2. It can have other components like button, text field etc.

Panel
1. The Panel is the container that doesn't contain title bar and menu
bars.
2. It can have other components like button, text field and etc.

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
1. It represents a rectangular area where application can draw
something or can receive inputs created by user

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Mr. Gajanan Jadhav
Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
1. In Java frame is graphical window.

2. The frame can be displayed using Frame class

1. Frame() – Creates frame which is invisible initially

2. Frame( String title)---Creates frame with title

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
1. setVisible(boolean visile) - sets visibility mode

2. setSize(int Width, int Height) - sets frame size

3. setTitle(String title) - sets title of frame

4. String getTitle() -Retrives title of frame

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
1. We can write text on frame by using paint() method .

2. Include or override paint() method of Component Class in frame class.


Signature is
public void paint(Graphics g)

3. Use drawString(String txt, int x, int y) method of Graphics class.

4. Graphics class belong to [Link] package

5. In same way we can use different methods of Graphics class to draw


different shapes.

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
1. [Link] class has two methods—

a. setBackground (Color c) - sets Background color of frame and


applet

b. setForeground( Color c) - sets Foreground color i.e text color


displayed on frame and applet

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
1. Firstly Create applet class with required applet methods i.e
init(),start(), stop().

2. Create Frame class in same program.

3. Now create object of Frame class in init() method of Applet


so that frame will be created after initialization of applet.

4. Now frame becomes within applet.

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
1. AWT has two types of controls
a. Passive Controls
b. Active Controls
2. We will learns following AWT controls

• Label
• Button
• Checkbox
• CheckboxGroup These classes are subclasses of
• Choice Component Class
• List
• Scrollbar
• TextField
• TextArea

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
1. Controls can be added into container i.e Frame ,Applet,
Panel,Window.

2. Using add() method of Container class.


Object
3. Signature of add() method is— of
Control
Component add ( Component obj)

4. Using remove() method Controls can be removed from


container.

Void remove ( Component obj)

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Constructor
1. Label() - Create label without Text

2. Label(String labeltext) - Create Label with Text

1. Label(String str, int how)- Label with text with Alignment

Ex : Label L1= new Label(“Name”);

Where how is—

[Link]
[Link]
[Link]

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Methods
1. void setText(String str) - Sets text on Label

2. String getText( ) - Retrives text from label

3. void setAlignment(int how) – Sets Alignment of text

4. int getAlignment( ) - Retrives Alignment from Label

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Push Button
with label
Submit
Constructor

1. Button () --Constructs a button with an empty string for


its label.

2. Button (String labelonbutton) - Constructs a new button


with specified label.

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Methods

1. void setLabel (String str) - Sets the button's label to be


the specified string.

2. String getLabel ( ) -- Gets the label of this button.

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Checkbox
with label
Constructor c++ , Java

1. Checkbox( )

2. Checkbox(String str)

3. Checkbox(String str, boolean on)

4. Checkbox(String str, boolean on, CheckboxGroup cbGroup)

5. Checkbox(String str, CheckboxGroup cbGroup, boolean on)

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Methods
1. boolean getState( )

2. void setState (boolean on)

3. String getLabel( )

4. void setLabel (String str)

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Constructor
1. CheckboxGroup ()

Ex: CheckboxGroup cb= new CheckboxGroup()

Methods
1. Checkbox getSelectedCheckbox( )

2. void setSelectedCheckbox(Checkbox wh)

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Constructor
1. Choice ()

Ex: Choice ch= new Choice()

Like Combo Box


in Visual Basic

Choice control with five items namely c,


c++, Java, PHP, Android at index
0,1,2,3,4. we can select one of them

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Methods
1. void add(String name)

2. String getSelectedItem( )

3. int getSelectedIndex( )

4. int getItemCount( )

5. void select(int index)

6. void select(String name)

7. String getItem(int index)

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Constructor
1. List( )

2. List(int numRows)

3. List(int numRows, boolean multipleSelect)

Ex: List L= new List()

List control with five items namely


item1, Item2, Item3, Item4, Item5 at
index 0,1,2,3,4. we can select one of
them or multiple Item at a time.

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Methods
1. void add(String name)

2. void add(String name, int index)

3. String getSelectedItem( )

4. int getSelectedIndex( )

5. String[ ] getSelectedItems( )

6. int[ ] getSelectedIndexes( )

7. int getItemCount( ) 8. void select(int index)

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Constructor
1. Scrollbar( ) - Creates vertical scrollbar

2. Scrollbar(int style)

3. Scrollbar(int style, int iValue, int tSize, int min, int max)

Ex: Scrollbar sc = new Scrollbar();

Style = 1. [Link]
2. [Link]

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Methods
1. void setValues(int iValue, int tSize, int min, int max)

2. int getValue( )

3. void setValue(int newValue)

4. int getMinimum( )

5. int getMaximum( )

6. void setUnitIncrement(int newIncr)

7. void setBlockIncrement(int newIncr)

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Component

TextField Constructor

1. TextField( )

2. TextField(int numChars)

3. TextField(String str)

4. TextField(String str, int numChars)

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Methods
1. String getText( )
6. void setEditable(boolean canEdit)
2. void setText(String str)
7. void setEchoChar(char ch)
3. String getSelectedText( )
8. boolean echoCharIsSet( )
4. void select(int startIndex,
int endIndex) 9. char getEchoChar( )

5. boolean isEditable( )

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Constructor
1. TextArea( )

2. TextArea(int numLines, int numChars)

3. TextArea(String str)

4. TextArea(String str, int numLines, int numChars)

5. TextArea(String str, int numLines, int numChars, int sBars)

SCROLLBARS_BOTH TextArea control with


SCROLLBARS_NONE rows,coloum, Horizontal
SCROLLBARS_HORIZONTAL_ONLY and Vertical scrollbar .
SCROLLBARS_VERTICAL_ONLY

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Methods
1. void append(String str) - Appends or adds text to end of TextArea

2. void insert(String str, int index) – Inserts specified text in TextArea at


specified index

3. void replaceRange(String str, int startIndex, int endIndex)

Replaces text from specified start index to end index by specified string

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
▪A top-level window can have a menu bar associated with it. A menu bar
displays a list of top-level menu choices. Each choice is associated with a
dropdown menu and Each menu contains menuitems.
▪ This Concept is implemented in java using following classes
MenuBar , Menu , MenuItem

General Steps For Creating MenuBar , Menu , MenuItem

1. Create Menubar using MenuBar class Object


2. Attach Menubar to Frame using setMenuBar() method to Frame.
3. Create Menu using Menu Class object.
4. Add menu to menubar.
5. Create MenuItem using MenuItem Class Object.
6. Add MenuItem to Menu

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Creating Menu
- Menu is subclass of MenuItem
- MenuItem is subclass of MenuComponent
Steps:
1. Create Menu using Following Menu ClassConstructor
Menu ()
Menu ( String name)
Menu (String name, boolean removable)

Ex : 1. Menu m1= new Menu();


2. Menu m1=new Menu(“File”);
3. Menu m1=new Menu(“Edit”, true);
2. Add menu object to MenuBar using add() method of MenuBar
Menu add (Menu object)
Ex : [Link](m1);

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Creating MenuItem
Steps:
1. Create MenuItem using Following MenuItem Constructor
MenuItem ()
MenuItem ( String name)
Menu tem(String name, MenuShortcut KeyAccel)

Ex : 1. MenuItem mi1= new MenuItem();


2. MenuItem mi1=new MenuItem(“New”);
3. MenuItem mi1=new MenuItem(“Open”, new MenuShortcut(KeyEvent.VK_O);

2. Add menuitem object to Menu using add() method of Menu


MenuItem add (MenuItem object)
Ex : [Link](mi1);

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
MenuItem Methods
1. Void setEnabled(boolean flag)
- If false menuitem will be disabled.

2. Boolean isEnabled()
- Retrives true if enabled else false.

3. Void setLabel(String Label)


- sets label to menuitem

4. String getLabel()
- Retrives label of menuitem

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Creating MenuItem
Steps:
1. Create MenuItem using Following MenuItem Constructor
MenuItem ()
MenuItem ( String name)
Menu tem(String name, MenuShortcut KeyAccel)

Ex : 1. MenuItem mi1= new MenuItem();


2. MenuItem mi1=new MenuItem(“New”);
3. MenuItem mi1=new MenuItem(“Open”, new MenuShortcut(KeyEvent.VK_O);

2. Add menuitem object to Menu using add() method of Menu


MenuItem add (MenuItem object)
Ex : [Link](mi1);

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Creating CheckboxMenuItem

Constructors:

1. CheckboxMenuItem()
2. CheckboxMenuItem(String itemname)
3. CheckboxMenuItem(String itemname, boolean on)

Methods:
1. boolean getState()
2. void setState( boolean state)

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
LayoutManager

- Used to arrange component in particular manner.


- Responsible for positioning, resizing, defining default size of
component.
- It is an interface implemented by all classes of Layout manger.
- Each Container object has layout manager associated with it.
- The layout manager is set by setLayout() method
- Void setLayout( LayoutManager obj)
- If we wish to disable layout manager then pass null to setLayout()
method.
- And then use setBounds(int x, int y, int W, int H) method to set manual
position and size to component on Container.

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
1. FlowLayout

- Default layout for Applet.


- Components are placed from upper left corner, left to right and top to
bottom like words flow in notepad. When no more components fits on
line , next one will appear on next line.
- Constructors
FlowLayout()
FlowLayout( int how)
FlowLayout ( int how , int hor , int ver)
- Default Horizonatal and vertical space between components is 5 pixel

Wherer how ---


1. [Link]
2. [Link]
3. [Link]

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
2. BorderLayout

- Default layout for Frame.


- Components are placed in five region NORTH, SOUTH, EAST, WEST and
CENTER of container
- Constructors
BorderLayout()

BorderLayout (int hor , int ver)

- add( Component obj,)


- Where region is int region
1. [Link]
2. [Link]
3. [Link]
4. [Link]
5. [Link]

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
3. GridLayout

- Components are placed in row and column matrix


- Constructors
GridLayout()
GridLayout( int row, int col)
GridLayout ( int row , int col , int horz, int vert)

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
Dialog

- Constructors

Dialog(Frame parent, boolean mode)


Dialog(Frame parent, String title, boolean mode)

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
FileDialog

- Constructors

FileDialog(Frame parent)
FileDialog(Frame Parent, String title)
FileDialog(Frame Parent, String title, int mode)

[Link]
[Link]

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad
FileDialog

- Methods

[Link] getFile()
[Link] getMode()
[Link] setDirectory(String str)
[Link] getDirectory()

Mr. Gajanan Jadhav


Lecturer In Computer Engineering
Government Polytechnic,
Aurangabad

You might also like