SlideShare a Scribd company logo
Graphical User
Interface (GUI) II
Objectives
 Differentiate the use of event handling for each
component.
 Apply appropriate event handling based on
given problem.
 Transform program from java application to
java applet and vice versa.
Event-Driven Programming
 In event-driven programming, code is executed upon
activation of events.
 Ex: a button click, or mouse movement
3
Events and Event Source
 An event can be defined as a type of signal to the
program that something has happened.
 The event is generated by external user actions such as
mouse movements, mouse button clicks, and
keystrokes, or by the operating system, such as a timer.
 The component on which an event is generated is called
the source object.
 Ex: source object: Button for a button-clicking action event.
4
Event Classes
Subclasses an event is an object of the EventObject class
Event Information
 An event object contains whatever properties are pertinent
to the event.
 You can identify the source object of the event using the
getSource() instance method in the EventObject class.
 The subclasses of EventObject deal with special types of
events, such as button actions, window events, component
events, mouse movements, and keystrokes.
6
Selected User Actions
7
Source Event Type
User Action Object Generated
Click a button JButton ActionEvent
Click a check box JCheckBox ItemEvent, ActionEvent
Click a radio button JRadioButton ItemEvent, ActionEvent
Press Enter on a text field JTextField ActionEvent
Select a new item JComboBox ItemEvent, ActionEvent
Select item(s) JList ListSelectionEvent
Select a menu item JMenuItem ActionEvent
Window opened, closed, etc. Window WindowEvent
Mouse pressed, released, etc. Component MouseEvent
Key released, pressed, etc. Component KeyEvent
In detail, refer to Table 16.1 pg 559
Listeners, Registartions, and
Handling Events
 Java uses a delegation-based model for event
handling
 An external user action on a source object triggers an event
 An object interested in the event receives the event
 The latter object is called a listener
8
Listeners, Registrations, and
Handling Events
 Two things are needed for an object to be a listener for an event on
a source object:
1. The listener object’s class must implement the corresponding event-
listener interface. Java provides a listener interface for every type of
GUI event.
The listener interface is usually named XListener for XEvent ,
Ex: Listener interface for ActionEvent is ActionListener
each listener for ActionEvent should implement the ActionListener
interface
9
Selected Event Handlers
10
Event Class Listener Interface Listener Methods (Handlers)
ActionEvent ActionListener actionPerformed(ActionEvent)
ItemEvent ItemListener itemStateChanged(ItemEvent)
WindowEvent WindowListener windowClosing(WindowEvent)
windowOpened(WindowEvent)
windowIconified(WindowEvent)
windowDeiconified(WindowEvent)
windowClosed(WindowEvent)
windowActivated(WindowEvent)
windowDeactivated(WindowEvent)
ContainerEvent ContainerListener componentAdded(ContainerEvent)
componentRemoved(ContainerEvent)
MouseEvent MouseListener mousePressed(MouseEvent)
mouseReleased(MouseEvent)
mouseClicked(MouseEvent)
mouseExited(MouseEvent)
mouseEntered(MouseEvent)
KeyEvent KeyListener keyPressed(KeyEvent)
keyReleased(KeyEvent)
keyTypeed(KeyEvent)
In detail, refer to Table 16.2 pg 561
Listeners, Registrations, and
Handling Events
 Two things are needed for an object to be a listener for an event on
a source object:
2. The listener object must be registered by the source object. Registration
methods are dependent on the event type
Ex: For ActionEvent, the method is addActionListener
In general: the method is named addXListener for XEvent
11
Listeners, Registrations, and
Handling Events
 For each event, the source object maintains a list of listeners and
notifies all the registered listeners by invoking the handler on the
listener object to respond to the event.
12
The Delegation Model: Example
13
source: JButton
+addActionListener(ActionListener listener)
listener: ListenerClass
ActionListener
+actionPerformed(ActionEvent event)
Register by invoking
source.addActionListener(listener);
ListenerClass listener = new ListenerClass();
JButton jbt = new JButton("OK");
jbt.addActionListener(listener);
class ListenerClass implements ActionListener {
public void actionPerformed(ActionEvent e) {
S.o.p (“Button “+ e.getActionCommand()+ “ is
clicked.”);}
Example:
 Class must implement the listener interface (ex: ActionListener).
and method to handle the event (ex: actionPerformed())
 The listener object must register with source object (ex: button)
 Done by invoking the addActionListener in the button object
 Ex::
public class TestActionButton extends JFrame implements ActionListener
{
JButton btn = new JButton(“Click Here");
btn.addActionListener(this);
public void actionPerformed(ActionEvent e)
{
}
}
Registration method (XEvent  addXListener)
ActionEvent
 The components that involved with this event are:
 JButton – clicka a button
 JMenuItem – select a menu item
 JTextField – press return on a text field
 Event listener interface – ActionListener
 Event handler method
public void actionPerformed(ActionEvent e)
java.awt.event.ActionEvent
16
java.awt.event.ActionEvent
+getActionCommand(): String
+getModifier(): int
+getWhen(): long
Returns the command string associated with this action. For a
button, its text is the command string.
Returns the modifier keys held down during this action event.
Returns the timestamp when this event occurred. The time is
the number of milliseconds since January 1, 1970, 00:00:00
GMT.
java.util.EventObject
+getSource(): Object Returns the object on which the event initially occurred.
java.awt.event.AWTEvent
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class UjiActionButang extends JFrame implements ActionListener
{
JButton btg = new JButton("Sila Klik");
JTextField txtField = new JTextField(10);
JLabel lbl = new JLabel(" ");
public UjiActionButang()
{
super("Melaksanakan ActionEvent");
Container bekas = getContentPane();
bekas.setLayout(new FlowLayout());
bekas.add(btg);
btg.addActionListener(this);
bekas.add(txtField);
bekas.add(lbl);
setSize(300,200);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()== btg)
{
lbl.setText("Terima Kasih");
txtField.setText("Sama-sama");
}
}
public static void main(String[] arg)
{
UjiActionButang teks = new UjiActionButang();
teks.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
To display label, and text on text field
when button is clicked
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class ActionTextField extends JFrame implements ActionListener
{
JLabel lbl = new JLabel("Nama ");
JTextField txtField = new JTextField(10);
public ActionTextField()
{
super("Melaksanakan ActionEvent- TextField");
Container bekas = getContentPane();
bekas.setLayout(new FlowLayout());
bekas.add(lbl);
bekas.add(txtField);
txtField.addActionListener(this);
setSize(300,200);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()== txtField)
{
JOptionPane.showMessageDialog(this,"Nama anda = "+
txtField.getText(),"Pemberitahuan",
JOptionPane.INFORMATION_MESSAGE);
}
}
public static void main(String[] arg)
{
ActionTextField teks = new ActionTextField();
teks.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
To display name from text field on dialog
box
when pressing <enter> on text field
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class ActionButton extends JFrame implements ActionListener
{
JLabel lbl = new JLabel("Nama ");
JTextField txtField = new JTextField(10);
JButton btg = new JButton("Klik");
JTextArea txtArea = new JTextArea("Ali",10,6);
public ActionButton()
{
super("Melaksanakan ActionEvent- Butang");
Container bekas = getContentPane();
bekas.setLayout(new FlowLayout());
bekas.add(lbl);
bekas.add(txtField);
bekas.add(btg);
bekas.add(txtArea);
btg.addActionListener(this);
setSize(300,200);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()== btg)
{
txtArea.append("n"+txtField.getText());
}
}
public static void main(String[] arg)
{
ActionButton teks = new ActionButton();
teks.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
To append text on text area when button is
clicked
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class UjiActionMenu extends JFrame implements ActionListener
{
JFrame frame = new JFrame();
JMenuBar jmb = new JMenuBar();
JMenu fileMenu = new JMenu("File");
JMenuItem baru= new JMenuItem("New");
JMenuItem buka= new JMenuItem("Open");
public UjiActionMenu()
{
frame.setTitle("membuat menu");
baru.addActionListener(this);
fileMenu.add(baru);
fileMenu.add(buka);
jmb.add(fileMenu);
frame.setJMenuBar(jmb);
frame.setSize(400,200);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == baru)
JOptionPane.showMessageDialog(this,"Anda telah memilih menu New",
"Pemberitahuan",JOptionPane.INFORMATION_MESSAGE);
}
public static void main(String[] arg)
{
UjiActionMenu teks = new UjiActionMenu();
teks.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
Display dialog box when menu item is clicked
comboBox
 Generate two types of event
 ActionEvent
 ItemEvent
 For the case of ItemEvent:
 Event listener Interface : ItemListener
 Event handler method
 public void ItemStateChanged(ItemEvent e)
○ When select an item in the combo box
 Index for the first item in the combo box will be started
by 0..n-1.
comboBox
javax.swing.JComboBox
+JComboBox()
+JComboBox(items: Object[])
+addItem(item: Object): void
+getItemAt(index: int): Object
+getItemCount(): int
+getSelectedIndex(): int
+setSelectedIndex(index: int): void
+getSelectedItem(): Object
+setSelectedItem(item: Object): void
+removeItem(anObject: Object): void
+removeItemAt(anIndex: int): void
+removeAllItems(): void
Creates a default empty combo box.
Creates a combo box that contains the elements in the specified array.
Adds an item to the combo box.
Returns the item at the specified index.
Returns the number of items in the combo box.
Returns the index of the selected item.
Sets the selected index in the combo box.
Returns the selected item.
Sets the selected item in the combo box.
Removes an item from the item list.
Removes the item at the specified index in the combo box.
Removes all items in the combo box.
javax.swing.JComponent
22
Using the
itemStateChanged Handler
public void itemStateChanged(ItemEvent e)
{
// Make sure the source is a combo box
if (e.getSource() instanceof JComboBox)
String s = (String)e.getItem();
}
23
When a new item is selected, itemStateChanged() for
ItemEvent is invoked .
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class UjiItemEventComboBox extends JFrame
implements ItemListener
{
JComboBox jcb = new JComboBox();
public UjiItemEventComboBox()
{
super("Membuat combobox");
Container bekas = getContentPane();
bekas.setLayout(new FlowLayout());
jcb.addItem("wira");
jcb.addItem("waja");
jcb.addItemListener(this);
bekas.add(jcb);
setSize(400,200);
setVisible(true);
}
public void itemStateChanged(ItemEvent e)
{
if (e.getSource()== jcb)
{
if (e.getStateChange() == ItemEvent.SELECTED)
{
String s1 = (String) jcb.getSelectedItem();
JOptionPane.showMessageDialog(this,"Anda telah memilih "+s1,"Maklumat",
JOptionPane.INFORMATION_MESSAGE);
}
}
}
ItemEvent: Display item on dialog box when
item in Combo Box is selected
public static void main(String[] arg)
{
UjiItemEventComboBox teks = new UjiItemEventComboBox();
teks.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class UjiActionEventComboBox extends JFrame implements ActionListener
{
JComboBox jcb = new JComboBox();
JButton btg = new JButton("Klik");
public UjiActionEventComboBox()
{
super("Membuat combobox");
Container bekas = getContentPane();
bekas.setLayout(new FlowLayout());
jcb.addItem("wira");
jcb.addItem("waja");
btg.addActionListener(this);
bekas.add(jcb);
bekas.add(btg);
setSize(400,200);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()== btg)
{
String s1 = (String)jcb.getSelectedItem();
JOptionPane.showMessageDialog(this,"Anda telah memilih "+s1,“
Maklumat",JOptionPane.INFORMATION_MESSAGE);
}
}
public static void main(String[] arg)
{
UjiActionEventComboBox teks = new UjiActionEventComboBox();
teks.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
ActionEvent: Display selected item on dialog
box when a button is clicked
ListSelectionEvent -
JList Generates javax.swing.event.ListSelectionEvent to notify the
listeners of the slections
 Event listener interface : ListSelectionListener
 Event handler interface:
public void valueChanged(ListSelectionEvent e)
○ When select item(s) in JList
 Index for the first item in the JList will be started by
0..n-1.
ListSelectionEvent - JList
javax.swing.JList
+JList()
+JList(items: Object[])
+getSelectedIndex(): int
+setSelectedIndex(index: int): void
+getSelectedIndices(): int[]
+setSelectedIndices(indices: int[]): void
+getSelectedValue(): Object
+getSelectedValues(): Object[]
+getVisibleRowCount(): int
+setVisibleRowCount(count: int): void
+getSelectionBackground(): Color
+setSelectionBackground(c: Color): void
+getSelectionForeground(): Color
+setSelectionForeground(c: Color): void
+getSelectionMode(): int
+setSelectionMode(selectionMode: int):
Creates a default empty list.
Creates a list that contains the elements in the specified array.
Returns the index of the first selected item.
Selects the cell at the specified index.
Returns an array of all of the selected indices in increasing order.
Selects the cells at the specified indices.
Returns the first selected item in the list.
Returns an array of the values for the selected cells in increasing index order.
Returns the number of visible rows displayed without a scrollbar. (default: 8)
Sets the preferred number of visible rows displayed without a scrollbar.
Returns the background color of the selected cells.
Sets the background color of the selected cells.
Returns the foreground color of the selected cells.
Sets the foreground color of the selected cells.
Returns the selection mode for the list.
Sets the selection mode for the list.
javax.swing.JComponent
28
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
class UjiSelectionEventList extends JFrame implements ListSelectionListener
{
String[] jenisWarna= {"merah","hijau","kuning","jingga","biru"};
JList senaraiWarna;
public UjiSelectionEventList()
{
super("Membuat JList");
Container bekas = getContentPane();
bekas.setLayout(new FlowLayout());
senaraiWarna = new JList(jenisWarna);
senaraiWarna.addListSelectionListener(this);
senaraiWarna.setVisibleRowCount(3);
senaraiWarna.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
bekas.add(new JScrollPane(senaraiWarna));
setSize(300,200);
setVisible(true);
}
public void valueChanged(ListSelectionEvent e)
{
if (e.getSource()== senaraiWarna)
{
String s1 = (String)senaraiWarna.getSelectedValue();
JOptionPane.showMessageDialog(this,s1,"maklumat",
JOptionPane.INFORMATION_MESSAGE);
}
}
SelectionEvent: Display selected item when
item in JList is clicked
public static void main(String[] arg)
{
UjiSelectionEventList list = new UjiSelectionEventList();
list.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
class DataListEventt extends JFrame implements ActionListener
{
String[] jenisWarna= {"merah","hijau","kuning","jingga","biru"};
JList senaraiWarna;
JButton btg = new JButton("Klik");
public DataListEventt()
{
super("Membuat JList");
Container bekas = getContentPane();
bekas.setLayout(new FlowLayout());
senaraiWarna = new JList(jenisWarna);
senaraiWarna.setVisibleRowCount(3);
senaraiWarna.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
bekas.add(new JScrollPane(senaraiWarna));
bekas.add(btg);
btg.addActionListener(this);
setSize(300,200);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()== btg)
{
String s1 = (String)senaraiWarna.getSelectedValue();
JOptionPane.showMessageDialog(this,s1,"maklumat",
JOptionPane.INFORMATION_MESSAGE);
}
}
ActionEvent: Display selected item in JList
when a button is clicked
public static void main(String[] arg)
{
DataListEventt list = new DataListEventt();
list.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
ItemEvent -
RadioButton Event Listener Interface : ItemListener
 Event handler method :
 public void ItemStateChanged(ItemEvent e)
○ Click a radio button
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class UjiItemListenerRadioButton extends JFrame implements ItemListener
{
JRadioButton rdButton1,rdButton2;
public UjiItemListenerRadioButton()
{
super("Membuat RadioButton");
Container bekas = getContentPane();
bekas.setLayout(new FlowLayout());
rdButton1 = new JRadioButton("wira");
rdButton2 = new JRadioButton("Waja",true);
rdButton1.addItemListener(this);
rdButton2.addItemListener(this);
bekas.add(rdButton1);
bekas.add(rdButton2);
ButtonGroup butang = new ButtonGroup();
butang.add(rdButton1);
butang.add(rdButton2);
setSize(400,200);
setVisible(true);
}
ItemEvent: Display item on dialog box when a
radio button is clicked
public void itemStateChanged(ItemEvent e)
{
if (e.getSource()== rdButton1)
{
if (e.getStateChange() == ItemEvent.SELECTED)
JOptionPane.showMessageDialog(this,"kereta wira","Maklumat",
JOptionPane.INFORMATION_MESSAGE);
}
if (e.getSource()== rdButton2)
{
if (e.getStateChange() == ItemEvent.SELECTED)
JOptionPane.showMessageDialog(this,"kereta waja","Maklumat",
JOptionPane.INFORMATION_MESSAGE);
}
}
public static void main(String[] arg)
{
UjiItemListenerRadioButton teks = new UjiItemListenerRadioButton();
teks.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class DataRadioButton extends JFrame implements ActionListener
{
JRadioButton rdButton1,rdButton2;
JButton btg = new JButton("Klik");
String kereta;
public DataRadioButton()
{
super("Membuat RadioButton");
Container bekas = getContentPane();
bekas.setLayout(new FlowLayout());
rdButton1 = new JRadioButton("wira");
rdButton2 = new JRadioButton("Waja",true);
bekas.add(rdButton1);
bekas.add(rdButton2);
bekas.add(btg);
btg.addActionListener(this);
ButtonGroup butang = new ButtonGroup();
butang.add(rdButton1);
butang.add(rdButton2);
setSize(400,200);
setVisible(true);
}
ActionEvent: Display selected item from
radio button when a button is clicked
public void actionPerformed(ActionEvent e)
{
if (e.getSource()== btg)
{
if (rdButton1.isSelected())
kereta = "Wira";
if (rdButton2.isSelected())
kereta = "Waja";
JOptionPane.showMessageDialog(this,kereta,"maklumat",
JOptionPane.INFORMATION_MESSAGE);
}
}
public static void main(String[] arg)
{
DataRadioButton teks = new DataRadioButton();
teks.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
ItemEvent - CheckBox
 Event Listener Interface : ItemListener
 Event handler metod :
 public void ItemStateChanged(ItemEvent e)
○ Click a check box
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class UjiItemEventCheckBox extends JFrame implements ItemListener
{
JCheckBox chkBox1,chkBox2;
public UjiItemEventCheckBox()
{
super("Membuat CheckBox");
Container bekas = getContentPane();
bekas.setLayout(new FlowLayout());
chkBox1 = new JCheckBox("Wira");
chkBox1.addItemListener(this);
chkBox2 = new JCheckBox("Waja");
bekas.add(chkBox1);
bekas.add(chkBox2);
setSize(400,200);
setVisible(true);
}
public void itemStateChanged(ItemEvent e)
{
if (e.getSource()== chkBox1)
{
if (e.getStateChange() == ItemEvent.SELECTED)
JOptionPane.showMessageDialog(this,"Di tanda","Maklumat",
JOptionPane.INFORMATION_MESSAGE);
}
}
public static void main(String[] arg)
{
UjiItemEventCheckBox teks = new UjiItemEventCheckBox();
teks.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
ItemEvent: Display a message when clicking a
check box
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class DataCheckBox extends JFrame implements ActionListener
{
JCheckBox chkBox1,chkBox2;
JButton btg = new JButton("Klik");
String kereta;
public DataCheckBox()
{
super("Membuat CheckBox");
Container bekas = getContentPane();
bekas.setLayout(new FlowLayout());
chkBox1 = new JCheckBox("Wira");
chkBox2 = new JCheckBox("Waja");
bekas.add(chkBox1);
bekas.add(chkBox2);
bekas.add(btg);
btg.addActionListener(this);
setSize(400,200);
setVisible(true);
}
ActionEvent: Display selected item from
check box when button is clicked
public void actionPerformed(ActionEvent e)
{
if (e.getSource()== btg)
{
if (chkBox1.isSelected())
kereta = "Wira";
if (chkBox2.isSelected())
kereta = "Waja";
JOptionPane.showMessageDialog(this,kereta,"maklumat",
JOptionPane.INFORMATION_MESSAGE);
}
}
public static void main(String[] arg)
{
DataCheckBox teks = new DataCheckBox();
teks.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

More Related Content

What's hot

Event handling in Java(part 2)
Event handling in Java(part 2)Event handling in Java(part 2)
Event handling in Java(part 2)
RAJITHARAMACHANDRAN1
 
tL20 event handling
tL20 event handlingtL20 event handling
tL20 event handling
teach4uin
 
Event Handling in Java
Event Handling in JavaEvent Handling in Java
Event Handling in Java
Ayesha Kanwal
 
Java Event Handling
Java Event HandlingJava Event Handling
Java Event Handling
Shraddha
 
Unit-3 event handling
Unit-3 event handlingUnit-3 event handling
Unit-3 event handling
Amol Gaikwad
 
Event handling63
Event handling63Event handling63
Event handling63myrajendra
 
Event handling
Event handlingEvent handling
Event handling
swapnac12
 
Adding a action listener to button
Adding a action listener to buttonAdding a action listener to button
Adding a action listener to button
yugandhar vadlamudi
 
JAVA GUI PART III
JAVA GUI PART IIIJAVA GUI PART III
JAVA GUI PART III
OXUS 20
 
J query
J queryJ query
J query
bosco1303
 
Jp notes
Jp notesJp notes
Java gui event
Java gui eventJava gui event
Java gui event
SoftNutx
 
jquery examples
jquery examplesjquery examples
jquery examples
Danilo Sousa
 
Ajp notes-chapter-03
Ajp notes-chapter-03Ajp notes-chapter-03
Ajp notes-chapter-03
Ankit Dubey
 
Advance Java Programming (CM5I) 2.Swing
Advance Java Programming (CM5I) 2.SwingAdvance Java Programming (CM5I) 2.Swing
Advance Java Programming (CM5I) 2.Swing
Payal Dungarwal
 

What's hot (18)

Event handling in Java(part 2)
Event handling in Java(part 2)Event handling in Java(part 2)
Event handling in Java(part 2)
 
Swing
SwingSwing
Swing
 
tL20 event handling
tL20 event handlingtL20 event handling
tL20 event handling
 
Event Handling in Java
Event Handling in JavaEvent Handling in Java
Event Handling in Java
 
Java Event Handling
Java Event HandlingJava Event Handling
Java Event Handling
 
Unit-3 event handling
Unit-3 event handlingUnit-3 event handling
Unit-3 event handling
 
Event handling63
Event handling63Event handling63
Event handling63
 
Event handling
Event handlingEvent handling
Event handling
 
Adding a action listener to button
Adding a action listener to buttonAdding a action listener to button
Adding a action listener to button
 
JAVA GUI PART III
JAVA GUI PART IIIJAVA GUI PART III
JAVA GUI PART III
 
J query
J queryJ query
J query
 
Jp notes
Jp notesJp notes
Jp notes
 
Java gui event
Java gui eventJava gui event
Java gui event
 
Calculadora
CalculadoraCalculadora
Calculadora
 
Ms Ajax Dom Event Class
Ms Ajax Dom Event ClassMs Ajax Dom Event Class
Ms Ajax Dom Event Class
 
jquery examples
jquery examplesjquery examples
jquery examples
 
Ajp notes-chapter-03
Ajp notes-chapter-03Ajp notes-chapter-03
Ajp notes-chapter-03
 
Advance Java Programming (CM5I) 2.Swing
Advance Java Programming (CM5I) 2.SwingAdvance Java Programming (CM5I) 2.Swing
Advance Java Programming (CM5I) 2.Swing
 

Viewers also liked

Evolving Glitch Art
Evolving Glitch ArtEvolving Glitch Art
Evolving Glitch Art
Eelco den Heijer
 
iOS Human Interface Guideline
iOS Human Interface GuidelineiOS Human Interface Guideline
iOS Human Interface Guideline
Design My Template LLP
 
Summary of Apple watch human interface design guideline
Summary of Apple watch human interface design guidelineSummary of Apple watch human interface design guideline
Summary of Apple watch human interface design guideline
Bryan Woo
 
iPhone - Human Interface Guidelines
iPhone - Human Interface GuidelinesiPhone - Human Interface Guidelines
iPhone - Human Interface Guidelines
Martin Ebner
 
iPhone / iPad - Human Interface Guidelines
iPhone / iPad - Human Interface GuidelinesiPhone / iPad - Human Interface Guidelines
iPhone / iPad - Human Interface Guidelines
Martin Ebner
 
Graphical User Interface
Graphical User InterfaceGraphical User Interface
Graphical User Interface
Deepa Ram Suthar
 
Gui
GuiGui
iOS Platform & Architecture
iOS Platform & ArchitectureiOS Platform & Architecture
iOS Platform & Architecturekrishguttha
 
HCI Basics
HCI BasicsHCI Basics
HCI Basics
Zdeněk Lanc
 
Week 4 IxD History: Personal Computing
Week 4 IxD History: Personal ComputingWeek 4 IxD History: Personal Computing
Week 4 IxD History: Personal Computing
Karen McGrane
 
Chapter 2 — Program and Graphical User Interface Design
Chapter 2 — Program and Graphical User Interface DesignChapter 2 — Program and Graphical User Interface Design
Chapter 2 — Program and Graphical User Interface Design
francopw
 
Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1
PRN USM
 
Graphical User Interface
Graphical User Interface Graphical User Interface
Graphical User Interface
Bivek Pakuwal
 
Brain Computer Interface
Brain Computer InterfaceBrain Computer Interface
Brain Computer Interface
guest9fd1acd
 
HCI Presentation
HCI PresentationHCI Presentation
HCI Presentation
Abdul Rasheed Memon
 
Introduction to HCI
Introduction to HCI Introduction to HCI
Introduction to HCI Deskala
 
BRAIN COMPUTER INTERFACE
BRAIN COMPUTER INTERFACEBRAIN COMPUTER INTERFACE
BRAIN COMPUTER INTERFACEnitish_kumar
 
Lecture 1: Human-Computer Interaction Introduction (2014)
Lecture 1: Human-Computer Interaction Introduction (2014)Lecture 1: Human-Computer Interaction Introduction (2014)
Lecture 1: Human-Computer Interaction Introduction (2014)
Lora Aroyo
 
Human-Computer Interaction: An Overview
Human-Computer Interaction: An OverviewHuman-Computer Interaction: An Overview
Human-Computer Interaction: An Overview
Sabin Buraga
 

Viewers also liked (20)

Evolving Glitch Art
Evolving Glitch ArtEvolving Glitch Art
Evolving Glitch Art
 
iOS Human Interface Guideline
iOS Human Interface GuidelineiOS Human Interface Guideline
iOS Human Interface Guideline
 
Summary of Apple watch human interface design guideline
Summary of Apple watch human interface design guidelineSummary of Apple watch human interface design guideline
Summary of Apple watch human interface design guideline
 
iPhone - Human Interface Guidelines
iPhone - Human Interface GuidelinesiPhone - Human Interface Guidelines
iPhone - Human Interface Guidelines
 
iPhone / iPad - Human Interface Guidelines
iPhone / iPad - Human Interface GuidelinesiPhone / iPad - Human Interface Guidelines
iPhone / iPad - Human Interface Guidelines
 
Glitch Studies Manifesto
Glitch Studies ManifestoGlitch Studies Manifesto
Glitch Studies Manifesto
 
Graphical User Interface
Graphical User InterfaceGraphical User Interface
Graphical User Interface
 
Gui
GuiGui
Gui
 
iOS Platform & Architecture
iOS Platform & ArchitectureiOS Platform & Architecture
iOS Platform & Architecture
 
HCI Basics
HCI BasicsHCI Basics
HCI Basics
 
Week 4 IxD History: Personal Computing
Week 4 IxD History: Personal ComputingWeek 4 IxD History: Personal Computing
Week 4 IxD History: Personal Computing
 
Chapter 2 — Program and Graphical User Interface Design
Chapter 2 — Program and Graphical User Interface DesignChapter 2 — Program and Graphical User Interface Design
Chapter 2 — Program and Graphical User Interface Design
 
Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1Graphical User Interface (GUI) - 1
Graphical User Interface (GUI) - 1
 
Graphical User Interface
Graphical User Interface Graphical User Interface
Graphical User Interface
 
Brain Computer Interface
Brain Computer InterfaceBrain Computer Interface
Brain Computer Interface
 
HCI Presentation
HCI PresentationHCI Presentation
HCI Presentation
 
Introduction to HCI
Introduction to HCI Introduction to HCI
Introduction to HCI
 
BRAIN COMPUTER INTERFACE
BRAIN COMPUTER INTERFACEBRAIN COMPUTER INTERFACE
BRAIN COMPUTER INTERFACE
 
Lecture 1: Human-Computer Interaction Introduction (2014)
Lecture 1: Human-Computer Interaction Introduction (2014)Lecture 1: Human-Computer Interaction Introduction (2014)
Lecture 1: Human-Computer Interaction Introduction (2014)
 
Human-Computer Interaction: An Overview
Human-Computer Interaction: An OverviewHuman-Computer Interaction: An Overview
Human-Computer Interaction: An Overview
 

Similar to Graphical User Interface (GUI) - 2

event handling new.ppt
event handling new.pptevent handling new.ppt
event handling new.ppt
usama537223
 
Synapseindia dotnet development chapter 14 event-driven programming
Synapseindia dotnet development  chapter 14 event-driven programmingSynapseindia dotnet development  chapter 14 event-driven programming
Synapseindia dotnet development chapter 14 event-driven programming
Synapseindiappsdevelopment
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
usvirat1805
 
ITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptxITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptx
udithaisur
 
Androd Listeners
Androd ListenersAndrod Listeners
Androd Listeners
ksheerod shri toshniwal
 
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
 
Dr Jammi Ashok - Introduction to Java Material (OOPs)
 Dr Jammi Ashok - Introduction to Java Material (OOPs) Dr Jammi Ashok - Introduction to Java Material (OOPs)
Dr Jammi Ashok - Introduction to Java Material (OOPs)
jammiashok123
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
Good657694
 
01 Java Is Architecture Neutral
01 Java Is Architecture Neutral01 Java Is Architecture Neutral
01 Java Is Architecture Neutralrajuglobal
 
Swing_Introduction.ppt
Swing_Introduction.pptSwing_Introduction.ppt
Swing_Introduction.ppt
Satyanandaram Nandigam
 
Lecture 8.pdf
Lecture 8.pdfLecture 8.pdf
Lecture 8.pdf
SakhilejasonMsibi
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
shanmuga rajan
 
Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024
kashyapneha2809
 
Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024
nehakumari0xf
 
openFrameworks 007 - events
openFrameworks 007 - eventsopenFrameworks 007 - events
openFrameworks 007 - eventsroxlu
 
engineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.pptengineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.ppt
sharanyak0721
 

Similar to Graphical User Interface (GUI) - 2 (20)

event handling new.ppt
event handling new.pptevent handling new.ppt
event handling new.ppt
 
Synapseindia dotnet development chapter 14 event-driven programming
Synapseindia dotnet development  chapter 14 event-driven programmingSynapseindia dotnet development  chapter 14 event-driven programming
Synapseindia dotnet development chapter 14 event-driven programming
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
 
What is Event
What is EventWhat is Event
What is Event
 
Swing
SwingSwing
Swing
 
ITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptxITE 1122_ Event Handling.pptx
ITE 1122_ Event Handling.pptx
 
Lecture8 oopj
Lecture8 oopjLecture8 oopj
Lecture8 oopj
 
Androd Listeners
Androd ListenersAndrod Listeners
Androd Listeners
 
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
 
Dr Jammi Ashok - Introduction to Java Material (OOPs)
 Dr Jammi Ashok - Introduction to Java Material (OOPs) Dr Jammi Ashok - Introduction to Java Material (OOPs)
Dr Jammi Ashok - Introduction to Java Material (OOPs)
 
event-handling.pptx
event-handling.pptxevent-handling.pptx
event-handling.pptx
 
CORE JAVA-2
CORE JAVA-2CORE JAVA-2
CORE JAVA-2
 
01 Java Is Architecture Neutral
01 Java Is Architecture Neutral01 Java Is Architecture Neutral
01 Java Is Architecture Neutral
 
Swing_Introduction.ppt
Swing_Introduction.pptSwing_Introduction.ppt
Swing_Introduction.ppt
 
Lecture 8.pdf
Lecture 8.pdfLecture 8.pdf
Lecture 8.pdf
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
 
Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024
 
Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024Java Abstract Window Toolkit (AWT) Presentation. 2024
Java Abstract Window Toolkit (AWT) Presentation. 2024
 
openFrameworks 007 - events
openFrameworks 007 - eventsopenFrameworks 007 - events
openFrameworks 007 - events
 
engineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.pptengineeringdsgtnotesofunitfivesnists.ppt
engineeringdsgtnotesofunitfivesnists.ppt
 

More from PRN USM

File Input & Output
File Input & OutputFile Input & Output
File Input & Output
PRN USM
 
Exception Handling
Exception HandlingException Handling
Exception Handling
PRN USM
 
Inheritance & Polymorphism - 2
Inheritance & Polymorphism - 2Inheritance & Polymorphism - 2
Inheritance & Polymorphism - 2
PRN USM
 
Inheritance & Polymorphism - 1
Inheritance & Polymorphism - 1Inheritance & Polymorphism - 1
Inheritance & Polymorphism - 1
PRN USM
 
Array
ArrayArray
Array
PRN USM
 
Class & Object - User Defined Method
Class & Object - User Defined MethodClass & Object - User Defined Method
Class & Object - User Defined Method
PRN USM
 
Class & Object - Intro
Class & Object - IntroClass & Object - Intro
Class & Object - Intro
PRN USM
 
Repetition Structure
Repetition StructureRepetition Structure
Repetition Structure
PRN USM
 
Selection Control Structures
Selection Control StructuresSelection Control Structures
Selection Control Structures
PRN USM
 
Numerical Data And Expression
Numerical Data And ExpressionNumerical Data And Expression
Numerical Data And Expression
PRN USM
 
Introduction To Computer and Java
Introduction To Computer and JavaIntroduction To Computer and Java
Introduction To Computer and Java
PRN USM
 
Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...
Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...
Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...PRN USM
 
Empowering Women Towards Smokefree Homes
Empowering  Women  Towards  Smokefree  HomesEmpowering  Women  Towards  Smokefree  Homes
Empowering Women Towards Smokefree HomesPRN USM
 
Sfe The Singaporean Experience
Sfe The Singaporean ExperienceSfe The Singaporean Experience
Sfe The Singaporean ExperiencePRN USM
 
Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...
Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...
Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...PRN USM
 
Malaysian Health Promotion Board (Mhpb) Objectives, Functions And Priorities
Malaysian Health Promotion Board (Mhpb) Objectives, Functions And PrioritiesMalaysian Health Promotion Board (Mhpb) Objectives, Functions And Priorities
Malaysian Health Promotion Board (Mhpb) Objectives, Functions And PrioritiesPRN USM
 
Role Of Ng Os In Tobacco Control
Role Of Ng Os In Tobacco ControlRole Of Ng Os In Tobacco Control
Role Of Ng Os In Tobacco ControlPRN USM
 
Application Of Grants From Mhpb
Application Of Grants From MhpbApplication Of Grants From Mhpb
Application Of Grants From MhpbPRN USM
 

More from PRN USM (18)

File Input & Output
File Input & OutputFile Input & Output
File Input & Output
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
Inheritance & Polymorphism - 2
Inheritance & Polymorphism - 2Inheritance & Polymorphism - 2
Inheritance & Polymorphism - 2
 
Inheritance & Polymorphism - 1
Inheritance & Polymorphism - 1Inheritance & Polymorphism - 1
Inheritance & Polymorphism - 1
 
Array
ArrayArray
Array
 
Class & Object - User Defined Method
Class & Object - User Defined MethodClass & Object - User Defined Method
Class & Object - User Defined Method
 
Class & Object - Intro
Class & Object - IntroClass & Object - Intro
Class & Object - Intro
 
Repetition Structure
Repetition StructureRepetition Structure
Repetition Structure
 
Selection Control Structures
Selection Control StructuresSelection Control Structures
Selection Control Structures
 
Numerical Data And Expression
Numerical Data And ExpressionNumerical Data And Expression
Numerical Data And Expression
 
Introduction To Computer and Java
Introduction To Computer and JavaIntroduction To Computer and Java
Introduction To Computer and Java
 
Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...
Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...
Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...
 
Empowering Women Towards Smokefree Homes
Empowering  Women  Towards  Smokefree  HomesEmpowering  Women  Towards  Smokefree  Homes
Empowering Women Towards Smokefree Homes
 
Sfe The Singaporean Experience
Sfe The Singaporean ExperienceSfe The Singaporean Experience
Sfe The Singaporean Experience
 
Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...
Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...
Corporate Social Responsibility And Challenges In Creating Smoke Free Environ...
 
Malaysian Health Promotion Board (Mhpb) Objectives, Functions And Priorities
Malaysian Health Promotion Board (Mhpb) Objectives, Functions And PrioritiesMalaysian Health Promotion Board (Mhpb) Objectives, Functions And Priorities
Malaysian Health Promotion Board (Mhpb) Objectives, Functions And Priorities
 
Role Of Ng Os In Tobacco Control
Role Of Ng Os In Tobacco ControlRole Of Ng Os In Tobacco Control
Role Of Ng Os In Tobacco Control
 
Application Of Grants From Mhpb
Application Of Grants From MhpbApplication Of Grants From Mhpb
Application Of Grants From Mhpb
 

Recently uploaded

Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
Nguyen Thanh Tu Collection
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 

Recently uploaded (20)

Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 

Graphical User Interface (GUI) - 2

  • 2. Objectives  Differentiate the use of event handling for each component.  Apply appropriate event handling based on given problem.  Transform program from java application to java applet and vice versa.
  • 3. Event-Driven Programming  In event-driven programming, code is executed upon activation of events.  Ex: a button click, or mouse movement 3
  • 4. Events and Event Source  An event can be defined as a type of signal to the program that something has happened.  The event is generated by external user actions such as mouse movements, mouse button clicks, and keystrokes, or by the operating system, such as a timer.  The component on which an event is generated is called the source object.  Ex: source object: Button for a button-clicking action event. 4
  • 5. Event Classes Subclasses an event is an object of the EventObject class
  • 6. Event Information  An event object contains whatever properties are pertinent to the event.  You can identify the source object of the event using the getSource() instance method in the EventObject class.  The subclasses of EventObject deal with special types of events, such as button actions, window events, component events, mouse movements, and keystrokes. 6
  • 7. Selected User Actions 7 Source Event Type User Action Object Generated Click a button JButton ActionEvent Click a check box JCheckBox ItemEvent, ActionEvent Click a radio button JRadioButton ItemEvent, ActionEvent Press Enter on a text field JTextField ActionEvent Select a new item JComboBox ItemEvent, ActionEvent Select item(s) JList ListSelectionEvent Select a menu item JMenuItem ActionEvent Window opened, closed, etc. Window WindowEvent Mouse pressed, released, etc. Component MouseEvent Key released, pressed, etc. Component KeyEvent In detail, refer to Table 16.1 pg 559
  • 8. Listeners, Registartions, and Handling Events  Java uses a delegation-based model for event handling  An external user action on a source object triggers an event  An object interested in the event receives the event  The latter object is called a listener 8
  • 9. Listeners, Registrations, and Handling Events  Two things are needed for an object to be a listener for an event on a source object: 1. The listener object’s class must implement the corresponding event- listener interface. Java provides a listener interface for every type of GUI event. The listener interface is usually named XListener for XEvent , Ex: Listener interface for ActionEvent is ActionListener each listener for ActionEvent should implement the ActionListener interface 9
  • 10. Selected Event Handlers 10 Event Class Listener Interface Listener Methods (Handlers) ActionEvent ActionListener actionPerformed(ActionEvent) ItemEvent ItemListener itemStateChanged(ItemEvent) WindowEvent WindowListener windowClosing(WindowEvent) windowOpened(WindowEvent) windowIconified(WindowEvent) windowDeiconified(WindowEvent) windowClosed(WindowEvent) windowActivated(WindowEvent) windowDeactivated(WindowEvent) ContainerEvent ContainerListener componentAdded(ContainerEvent) componentRemoved(ContainerEvent) MouseEvent MouseListener mousePressed(MouseEvent) mouseReleased(MouseEvent) mouseClicked(MouseEvent) mouseExited(MouseEvent) mouseEntered(MouseEvent) KeyEvent KeyListener keyPressed(KeyEvent) keyReleased(KeyEvent) keyTypeed(KeyEvent) In detail, refer to Table 16.2 pg 561
  • 11. Listeners, Registrations, and Handling Events  Two things are needed for an object to be a listener for an event on a source object: 2. The listener object must be registered by the source object. Registration methods are dependent on the event type Ex: For ActionEvent, the method is addActionListener In general: the method is named addXListener for XEvent 11
  • 12. Listeners, Registrations, and Handling Events  For each event, the source object maintains a list of listeners and notifies all the registered listeners by invoking the handler on the listener object to respond to the event. 12
  • 13. The Delegation Model: Example 13 source: JButton +addActionListener(ActionListener listener) listener: ListenerClass ActionListener +actionPerformed(ActionEvent event) Register by invoking source.addActionListener(listener); ListenerClass listener = new ListenerClass(); JButton jbt = new JButton("OK"); jbt.addActionListener(listener); class ListenerClass implements ActionListener { public void actionPerformed(ActionEvent e) { S.o.p (“Button “+ e.getActionCommand()+ “ is clicked.”);}
  • 14. Example:  Class must implement the listener interface (ex: ActionListener). and method to handle the event (ex: actionPerformed())  The listener object must register with source object (ex: button)  Done by invoking the addActionListener in the button object  Ex:: public class TestActionButton extends JFrame implements ActionListener { JButton btn = new JButton(“Click Here"); btn.addActionListener(this); public void actionPerformed(ActionEvent e) { } } Registration method (XEvent  addXListener)
  • 15. ActionEvent  The components that involved with this event are:  JButton – clicka a button  JMenuItem – select a menu item  JTextField – press return on a text field  Event listener interface – ActionListener  Event handler method public void actionPerformed(ActionEvent e)
  • 16. java.awt.event.ActionEvent 16 java.awt.event.ActionEvent +getActionCommand(): String +getModifier(): int +getWhen(): long Returns the command string associated with this action. For a button, its text is the command string. Returns the modifier keys held down during this action event. Returns the timestamp when this event occurred. The time is the number of milliseconds since January 1, 1970, 00:00:00 GMT. java.util.EventObject +getSource(): Object Returns the object on which the event initially occurred. java.awt.event.AWTEvent
  • 17. import java.awt.*; import javax.swing.*; import java.awt.event.*; public class UjiActionButang extends JFrame implements ActionListener { JButton btg = new JButton("Sila Klik"); JTextField txtField = new JTextField(10); JLabel lbl = new JLabel(" "); public UjiActionButang() { super("Melaksanakan ActionEvent"); Container bekas = getContentPane(); bekas.setLayout(new FlowLayout()); bekas.add(btg); btg.addActionListener(this); bekas.add(txtField); bekas.add(lbl); setSize(300,200); setVisible(true); } public void actionPerformed(ActionEvent e) { if (e.getSource()== btg) { lbl.setText("Terima Kasih"); txtField.setText("Sama-sama"); } } public static void main(String[] arg) { UjiActionButang teks = new UjiActionButang(); teks.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } To display label, and text on text field when button is clicked
  • 18. import java.awt.*; import javax.swing.*; import java.awt.event.*; public class ActionTextField extends JFrame implements ActionListener { JLabel lbl = new JLabel("Nama "); JTextField txtField = new JTextField(10); public ActionTextField() { super("Melaksanakan ActionEvent- TextField"); Container bekas = getContentPane(); bekas.setLayout(new FlowLayout()); bekas.add(lbl); bekas.add(txtField); txtField.addActionListener(this); setSize(300,200); setVisible(true); } public void actionPerformed(ActionEvent e) { if (e.getSource()== txtField) { JOptionPane.showMessageDialog(this,"Nama anda = "+ txtField.getText(),"Pemberitahuan", JOptionPane.INFORMATION_MESSAGE); } } public static void main(String[] arg) { ActionTextField teks = new ActionTextField(); teks.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } To display name from text field on dialog box when pressing <enter> on text field
  • 19. import java.awt.*; import javax.swing.*; import java.awt.event.*; public class ActionButton extends JFrame implements ActionListener { JLabel lbl = new JLabel("Nama "); JTextField txtField = new JTextField(10); JButton btg = new JButton("Klik"); JTextArea txtArea = new JTextArea("Ali",10,6); public ActionButton() { super("Melaksanakan ActionEvent- Butang"); Container bekas = getContentPane(); bekas.setLayout(new FlowLayout()); bekas.add(lbl); bekas.add(txtField); bekas.add(btg); bekas.add(txtArea); btg.addActionListener(this); setSize(300,200); setVisible(true); } public void actionPerformed(ActionEvent e) { if (e.getSource()== btg) { txtArea.append("n"+txtField.getText()); } } public static void main(String[] arg) { ActionButton teks = new ActionButton(); teks.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } To append text on text area when button is clicked
  • 20. import java.awt.*; import javax.swing.*; import java.awt.event.*; public class UjiActionMenu extends JFrame implements ActionListener { JFrame frame = new JFrame(); JMenuBar jmb = new JMenuBar(); JMenu fileMenu = new JMenu("File"); JMenuItem baru= new JMenuItem("New"); JMenuItem buka= new JMenuItem("Open"); public UjiActionMenu() { frame.setTitle("membuat menu"); baru.addActionListener(this); fileMenu.add(baru); fileMenu.add(buka); jmb.add(fileMenu); frame.setJMenuBar(jmb); frame.setSize(400,200); frame.setVisible(true); } public void actionPerformed(ActionEvent e) { if (e.getSource() == baru) JOptionPane.showMessageDialog(this,"Anda telah memilih menu New", "Pemberitahuan",JOptionPane.INFORMATION_MESSAGE); } public static void main(String[] arg) { UjiActionMenu teks = new UjiActionMenu(); teks.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } Display dialog box when menu item is clicked
  • 21. comboBox  Generate two types of event  ActionEvent  ItemEvent  For the case of ItemEvent:  Event listener Interface : ItemListener  Event handler method  public void ItemStateChanged(ItemEvent e) ○ When select an item in the combo box  Index for the first item in the combo box will be started by 0..n-1.
  • 22. comboBox javax.swing.JComboBox +JComboBox() +JComboBox(items: Object[]) +addItem(item: Object): void +getItemAt(index: int): Object +getItemCount(): int +getSelectedIndex(): int +setSelectedIndex(index: int): void +getSelectedItem(): Object +setSelectedItem(item: Object): void +removeItem(anObject: Object): void +removeItemAt(anIndex: int): void +removeAllItems(): void Creates a default empty combo box. Creates a combo box that contains the elements in the specified array. Adds an item to the combo box. Returns the item at the specified index. Returns the number of items in the combo box. Returns the index of the selected item. Sets the selected index in the combo box. Returns the selected item. Sets the selected item in the combo box. Removes an item from the item list. Removes the item at the specified index in the combo box. Removes all items in the combo box. javax.swing.JComponent 22
  • 23. Using the itemStateChanged Handler public void itemStateChanged(ItemEvent e) { // Make sure the source is a combo box if (e.getSource() instanceof JComboBox) String s = (String)e.getItem(); } 23 When a new item is selected, itemStateChanged() for ItemEvent is invoked .
  • 24. import java.awt.*; import javax.swing.*; import java.awt.event.*; public class UjiItemEventComboBox extends JFrame implements ItemListener { JComboBox jcb = new JComboBox(); public UjiItemEventComboBox() { super("Membuat combobox"); Container bekas = getContentPane(); bekas.setLayout(new FlowLayout()); jcb.addItem("wira"); jcb.addItem("waja"); jcb.addItemListener(this); bekas.add(jcb); setSize(400,200); setVisible(true); } public void itemStateChanged(ItemEvent e) { if (e.getSource()== jcb) { if (e.getStateChange() == ItemEvent.SELECTED) { String s1 = (String) jcb.getSelectedItem(); JOptionPane.showMessageDialog(this,"Anda telah memilih "+s1,"Maklumat", JOptionPane.INFORMATION_MESSAGE); } } } ItemEvent: Display item on dialog box when item in Combo Box is selected
  • 25. public static void main(String[] arg) { UjiItemEventComboBox teks = new UjiItemEventComboBox(); teks.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
  • 26. import java.awt.*; import javax.swing.*; import java.awt.event.*; public class UjiActionEventComboBox extends JFrame implements ActionListener { JComboBox jcb = new JComboBox(); JButton btg = new JButton("Klik"); public UjiActionEventComboBox() { super("Membuat combobox"); Container bekas = getContentPane(); bekas.setLayout(new FlowLayout()); jcb.addItem("wira"); jcb.addItem("waja"); btg.addActionListener(this); bekas.add(jcb); bekas.add(btg); setSize(400,200); setVisible(true); } public void actionPerformed(ActionEvent e) { if (e.getSource()== btg) { String s1 = (String)jcb.getSelectedItem(); JOptionPane.showMessageDialog(this,"Anda telah memilih "+s1,“ Maklumat",JOptionPane.INFORMATION_MESSAGE); } } public static void main(String[] arg) { UjiActionEventComboBox teks = new UjiActionEventComboBox(); teks.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } ActionEvent: Display selected item on dialog box when a button is clicked
  • 27. ListSelectionEvent - JList Generates javax.swing.event.ListSelectionEvent to notify the listeners of the slections  Event listener interface : ListSelectionListener  Event handler interface: public void valueChanged(ListSelectionEvent e) ○ When select item(s) in JList  Index for the first item in the JList will be started by 0..n-1.
  • 28. ListSelectionEvent - JList javax.swing.JList +JList() +JList(items: Object[]) +getSelectedIndex(): int +setSelectedIndex(index: int): void +getSelectedIndices(): int[] +setSelectedIndices(indices: int[]): void +getSelectedValue(): Object +getSelectedValues(): Object[] +getVisibleRowCount(): int +setVisibleRowCount(count: int): void +getSelectionBackground(): Color +setSelectionBackground(c: Color): void +getSelectionForeground(): Color +setSelectionForeground(c: Color): void +getSelectionMode(): int +setSelectionMode(selectionMode: int): Creates a default empty list. Creates a list that contains the elements in the specified array. Returns the index of the first selected item. Selects the cell at the specified index. Returns an array of all of the selected indices in increasing order. Selects the cells at the specified indices. Returns the first selected item in the list. Returns an array of the values for the selected cells in increasing index order. Returns the number of visible rows displayed without a scrollbar. (default: 8) Sets the preferred number of visible rows displayed without a scrollbar. Returns the background color of the selected cells. Sets the background color of the selected cells. Returns the foreground color of the selected cells. Sets the foreground color of the selected cells. Returns the selection mode for the list. Sets the selection mode for the list. javax.swing.JComponent 28
  • 29. import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; class UjiSelectionEventList extends JFrame implements ListSelectionListener { String[] jenisWarna= {"merah","hijau","kuning","jingga","biru"}; JList senaraiWarna; public UjiSelectionEventList() { super("Membuat JList"); Container bekas = getContentPane(); bekas.setLayout(new FlowLayout()); senaraiWarna = new JList(jenisWarna); senaraiWarna.addListSelectionListener(this); senaraiWarna.setVisibleRowCount(3); senaraiWarna.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); bekas.add(new JScrollPane(senaraiWarna)); setSize(300,200); setVisible(true); } public void valueChanged(ListSelectionEvent e) { if (e.getSource()== senaraiWarna) { String s1 = (String)senaraiWarna.getSelectedValue(); JOptionPane.showMessageDialog(this,s1,"maklumat", JOptionPane.INFORMATION_MESSAGE); } } SelectionEvent: Display selected item when item in JList is clicked
  • 30. public static void main(String[] arg) { UjiSelectionEventList list = new UjiSelectionEventList(); list.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
  • 31. import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; class DataListEventt extends JFrame implements ActionListener { String[] jenisWarna= {"merah","hijau","kuning","jingga","biru"}; JList senaraiWarna; JButton btg = new JButton("Klik"); public DataListEventt() { super("Membuat JList"); Container bekas = getContentPane(); bekas.setLayout(new FlowLayout()); senaraiWarna = new JList(jenisWarna); senaraiWarna.setVisibleRowCount(3); senaraiWarna.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); bekas.add(new JScrollPane(senaraiWarna)); bekas.add(btg); btg.addActionListener(this); setSize(300,200); setVisible(true); } public void actionPerformed(ActionEvent e) { if (e.getSource()== btg) { String s1 = (String)senaraiWarna.getSelectedValue(); JOptionPane.showMessageDialog(this,s1,"maklumat", JOptionPane.INFORMATION_MESSAGE); } } ActionEvent: Display selected item in JList when a button is clicked
  • 32. public static void main(String[] arg) { DataListEventt list = new DataListEventt(); list.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
  • 33. ItemEvent - RadioButton Event Listener Interface : ItemListener  Event handler method :  public void ItemStateChanged(ItemEvent e) ○ Click a radio button
  • 34. import java.awt.*; import javax.swing.*; import java.awt.event.*; public class UjiItemListenerRadioButton extends JFrame implements ItemListener { JRadioButton rdButton1,rdButton2; public UjiItemListenerRadioButton() { super("Membuat RadioButton"); Container bekas = getContentPane(); bekas.setLayout(new FlowLayout()); rdButton1 = new JRadioButton("wira"); rdButton2 = new JRadioButton("Waja",true); rdButton1.addItemListener(this); rdButton2.addItemListener(this); bekas.add(rdButton1); bekas.add(rdButton2); ButtonGroup butang = new ButtonGroup(); butang.add(rdButton1); butang.add(rdButton2); setSize(400,200); setVisible(true); } ItemEvent: Display item on dialog box when a radio button is clicked
  • 35. public void itemStateChanged(ItemEvent e) { if (e.getSource()== rdButton1) { if (e.getStateChange() == ItemEvent.SELECTED) JOptionPane.showMessageDialog(this,"kereta wira","Maklumat", JOptionPane.INFORMATION_MESSAGE); } if (e.getSource()== rdButton2) { if (e.getStateChange() == ItemEvent.SELECTED) JOptionPane.showMessageDialog(this,"kereta waja","Maklumat", JOptionPane.INFORMATION_MESSAGE); } } public static void main(String[] arg) { UjiItemListenerRadioButton teks = new UjiItemListenerRadioButton(); teks.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
  • 36. import java.awt.*; import javax.swing.*; import java.awt.event.*; public class DataRadioButton extends JFrame implements ActionListener { JRadioButton rdButton1,rdButton2; JButton btg = new JButton("Klik"); String kereta; public DataRadioButton() { super("Membuat RadioButton"); Container bekas = getContentPane(); bekas.setLayout(new FlowLayout()); rdButton1 = new JRadioButton("wira"); rdButton2 = new JRadioButton("Waja",true); bekas.add(rdButton1); bekas.add(rdButton2); bekas.add(btg); btg.addActionListener(this); ButtonGroup butang = new ButtonGroup(); butang.add(rdButton1); butang.add(rdButton2); setSize(400,200); setVisible(true); } ActionEvent: Display selected item from radio button when a button is clicked
  • 37. public void actionPerformed(ActionEvent e) { if (e.getSource()== btg) { if (rdButton1.isSelected()) kereta = "Wira"; if (rdButton2.isSelected()) kereta = "Waja"; JOptionPane.showMessageDialog(this,kereta,"maklumat", JOptionPane.INFORMATION_MESSAGE); } } public static void main(String[] arg) { DataRadioButton teks = new DataRadioButton(); teks.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
  • 38. ItemEvent - CheckBox  Event Listener Interface : ItemListener  Event handler metod :  public void ItemStateChanged(ItemEvent e) ○ Click a check box
  • 39. import java.awt.*; import javax.swing.*; import java.awt.event.*; public class UjiItemEventCheckBox extends JFrame implements ItemListener { JCheckBox chkBox1,chkBox2; public UjiItemEventCheckBox() { super("Membuat CheckBox"); Container bekas = getContentPane(); bekas.setLayout(new FlowLayout()); chkBox1 = new JCheckBox("Wira"); chkBox1.addItemListener(this); chkBox2 = new JCheckBox("Waja"); bekas.add(chkBox1); bekas.add(chkBox2); setSize(400,200); setVisible(true); } public void itemStateChanged(ItemEvent e) { if (e.getSource()== chkBox1) { if (e.getStateChange() == ItemEvent.SELECTED) JOptionPane.showMessageDialog(this,"Di tanda","Maklumat", JOptionPane.INFORMATION_MESSAGE); } } public static void main(String[] arg) { UjiItemEventCheckBox teks = new UjiItemEventCheckBox(); teks.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } } ItemEvent: Display a message when clicking a check box
  • 40. import java.awt.*; import javax.swing.*; import java.awt.event.*; public class DataCheckBox extends JFrame implements ActionListener { JCheckBox chkBox1,chkBox2; JButton btg = new JButton("Klik"); String kereta; public DataCheckBox() { super("Membuat CheckBox"); Container bekas = getContentPane(); bekas.setLayout(new FlowLayout()); chkBox1 = new JCheckBox("Wira"); chkBox2 = new JCheckBox("Waja"); bekas.add(chkBox1); bekas.add(chkBox2); bekas.add(btg); btg.addActionListener(this); setSize(400,200); setVisible(true); } ActionEvent: Display selected item from check box when button is clicked
  • 41. public void actionPerformed(ActionEvent e) { if (e.getSource()== btg) { if (chkBox1.isSelected()) kereta = "Wira"; if (chkBox2.isSelected()) kereta = "Waja"; JOptionPane.showMessageDialog(this,kereta,"maklumat", JOptionPane.INFORMATION_MESSAGE); } } public static void main(String[] arg) { DataCheckBox teks = new DataCheckBox(); teks.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }