0% found this document useful (0 votes)
280 views11 pages

Swings Lecture Notes PDF

This document provides an overview of Java Swings and GUI creation in Java. It discusses containers like Frame and JFrame, components like buttons and text fields, and how to create and size both containers and components. It also covers how to add components to containers and how event handling works in Java by listening for events from sources and notifying listeners. The key classes and interfaces for GUI creation and event handling in Java are java.awt.*, javax.swing.*, java.applet.*, and java.awt.event.*.

Uploaded by

kartheek
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)
280 views11 pages

Swings Lecture Notes PDF

This document provides an overview of Java Swings and GUI creation in Java. It discusses containers like Frame and JFrame, components like buttons and text fields, and how to create and size both containers and components. It also covers how to add components to containers and how event handling works in Java by listening for events from sources and notifying listeners. The key classes and interfaces for GUI creation and event handling in Java are java.awt.*, javax.swing.*, java.applet.*, and java.awt.event.*.

Uploaded by

kartheek
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
You are on page 1/ 11

Lecture_Series

CO-4

JAVA SWINGS
-NIRANJAN A
GUI- Graphical User Interface
Frame

Containers Main
Applet
Container

JFrame

Sub
Panel
Container

Canvas

Components Button TextField Label

CheckBox List
Java Packages for GUI creation
java.awt.*;
javax.swing.*;
java.applet.*;- Not Covered

Java Package for Event Handling


java.awt.event.*;
Classes used for Container Creation
java.awt.Frame;
Javax.swing.JFrame;
java.applet.Applet;
How are Containers Created?
Frame f=new Frame();
Or
Frame f=new Frame(“Title”);
JFrame jf= new JFrame();
Or
JFrame jf=new JFrame(“Title”);
How are Components Created?
Button b=new Button(); JButton b=new JButton();
Or Or
Button b=new Button(“Text”); JButton b=new JButton(“Text”);
Label l= new Label(); JLabel l= new JLabel();
Or Or
Label l=new Label(“Text”); JLabel l=new JLabel(“Text”);
TextField tf=new TextField(); JTextField tf=new JTextField();
Or Or
TextField tf=new TextField(size); JTextField tf=new JTextField(size);
How are sizes fixed for
Containers/Components?
Obj of Obj of
Cont/Comp . setSize(width,height); Cont/Comp . setBounds(x,y,width,height);

Frame f=new Frame(); JFrame jf=newJFrame();


Button b=new Button(); JButton b=new JButton();
Label l= new Label(); JLabel l= new JLabel();
TextField tf=new TextField(); JTextField tf=new JTextField();
f.setSize(700,800); jf.setBounds(20,30,700,800);
b.setSize(30,40); b.setBounds(20,70,30,40);
l.setSize(50,30); l.setBounds(20,130,50,30);
How are Components added onto a
Container?
Obj of Obj of
Container . add(Object of Component); Cont/Comp . setBounds(x,y,width,height);

Frame f=new Frame(); JFrame jf=newJFrame();


Button b=new Button(); JButton b=new JButton();
Label l= new Label(); JLabel l= new JLabel();
TextField tf=new TextField(); JTextField tf=new JTextField();
f.add(b); jf. add(b);
f.add(l); jf. add(l);
f.add(tf); jf. add(tf);
Event Handling
1. An event is generated by a source.
2. One who listens to an event is called the listeners.
3. The listener will continuously be waiting for an event to occur and once an
event is generated the listener Notifies to take appropriate action:
4. In Java all the listeners are available as interfaces. To write such programs
we need to follow few steps
1. import statement should be written in the following way import java.awt.event.*;
2. The class must implement an appropriate listener interface.
3. The event must be registered with the listener interface for which an appropriate
type of add() method should be used.
4. Finally, we need to override the methods which are declared abstract in the
interfaces.
Sample Outputs
AWT SWING

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy