SlideShare a Scribd company logo
https://www.facebook.com/Oxus20 
oxus20@gmail.com 
JAVA Virtual Keyboard 
»Exception 
Handling 
»JToggleButton Class 
»Robot Class 
»Toolkit Class 
Prepared By: Nahid Ahmadi 
Edited By: Abdul Rahman Sherzad
Agenda 
»Virtual Keyboard 
»Exception Handling 
»JToggleButton Class 
»Robot Class 
»Toolkit Class 
»Virtual Keyboard Implementation 
2 
https://www.facebook.com/Oxus20
https://www.facebook.com/Oxus20 
3
Virtual Keyboard Using JAVA 
4 
https://www.facebook.com/Oxus20
Introduction to Virtual Keyboard 
»A virtual keyboard is considered to be a component to use on computers without a real keyboard e.g. 
˃touch screen computer 
»A mouse can utilize the keyboard functionalities and features. 
5 
https://www.facebook.com/Oxus20
Virtual Keyboard Usage 
»It is possible to obtain keyboards for the following specific purposes: 
˃Keyboards to fill specific forms on sites 
˃Special key arrangements 
˃Keyboards for dedicated commercial sites 
˃etc. 
»In addition, Virtual Keyboard used for the following subjects: 
˃Foreign Character Sets 
˃Touchscreens 
˃Bypass key loggers 
6 
https://www.facebook.com/Oxus20
https://www.facebook.com/Oxus20 
7
Exception Handling 
»A program can be written assuming that nothing unusual or incorrect will happen. 
˃The user will always enter an integer when prompted to do so. 
˃There will always be a nonempty list for a program that takes an entry from the list. 
˃The file containing the needed information will always exist. 
»Unfortunately, it isn't always so. 
»Once the core program is written for the usual, expected case(s), Java's exception-handling facilities should be added to accommodate the unusual, unexpected case(s). 
8
Exception Hierarchy 
9 
https://www.facebook.com/Oxus20
Exception Handling Demo Source code 
public class ExceptionHandlingDemo { 
public static void main(String args[]) { 
try { 
int scores[] = { 90, 85, 75, 100 }; 
System.out.println("Access element nine:" + scores[9]); 
} catch (ArrayIndexOutOfBoundsException e) { 
System.out.println("Exception thrown:" + e); 
} 
System.out.println("nWithout Exception Handling I was not able to execute and print!"); 
} 
} 
10 
https://www.facebook.com/Oxus20
Exception Handling Demo OUTPUT 
Exception thrown:java.lang.ArrayIndexOutOfBoundsException: 9 
Without Exception Handling I was not able to execute and print! 
11 
https://www.facebook.com/Oxus20
https://www.facebook.com/Oxus20 
12
JToggleButton Class 
»JToggleButton is an implementation of a two-state button and is used to represent buttons that can be toggled ON and OFF 
»The JRadioButton and JCheckBox classes are subclasses of this class. 
»The events fired by JToggleButtons are slightly different than those fired by JButton. 
13 
https://www.facebook.com/Oxus20
JToggleButton Demo 
»The following example on next slide demonstrates a toggle button. Each time the toggle button is pressed, its state is displayed in a label. 
»Creating JToggleButton involves these steps: 
1.Create an instance of JToggleButton. 
2.Register an ItemListener to handle item events generated by the button. 
3.To determine if the button is on or off, call isSelected(). 
14 
https://www.facebook.com/Oxus20
JToggleButton Demo Source Code 
import java.awt.FlowLayout; 
import java.awt.event.ItemEvent; 
import java.awt.event.ItemListener; 
import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.JToggleButton; 
class JToggleButtonDemo { 
JLabel lblOutput; 
JToggleButton btnOnOff; 
JFrame win; 
JToggleButtonDemo() { 
// JFrame Customization 
win = new JFrame("Using JToggleButton"); 
win.setLayout(new FlowLayout()); 
win.setSize(300, 80); 
win.setLocationRelativeTo(null); 
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
15 
https://www.facebook.com/Oxus20
// JToggleButton and JLabel Customization 
lblOutput = new JLabel("State : OFF"); 
btnOnOff = new JToggleButton("On / Off", false); 
// Add item listener for JToggleButton. 
btnOnOff.addItemListener(new ItemListener() { 
public void itemStateChanged(ItemEvent ie) { 
if (btnOnOff.isSelected()) { 
lblOutput.setText("State : ON"); 
} else { 
lblOutput.setText("State : OFF"); 
} 
} 
}); 
// Add toggle button and label to the content pane. 
win.add(btnOnOff); 
win.add(lblOutput); 
win.setVisible(true); 
} 
public static void main(String args[]) { 
new JToggleButtonDemo(); 
} 
} 
16 
https://www.facebook.com/Oxus20
JToggleButton Demo OUTPUT 
17 
https://www.facebook.com/Oxus20
https://www.facebook.com/Oxus20 
18
Java Robot Class 
»This class is used to generate native system input events for the purposes of 
˃test automation 
˃self-running demos 
˃and other applications where control of the mouse and keyboard is needed. 
»This class has three main functionalities: 
˃mouse control 
˃keyboard control 
˃and screen capture. 
https://www.facebook.com/Oxus20 
19
Robot Class Demo 
»Perform keyboard operation with help of java Robot class. 
»The following example on next slide will demonstrate the Robot class usage to handle the keyboard events. 
»The program will write the word "OXUS20" inside the TextArea automatically after running the program. 
»The word "OXUS20" will be written character by character with one second delay between each on of the characters. 
20 
https://www.facebook.com/Oxus20
Robot Class Demo Source Code 
import java.awt.AWTException; 
import java.awt.BorderLayout; 
import java.awt.Robot; 
import java.awt.event.KeyEvent; 
import javax.swing.JFrame; 
import javax.swing.JTextArea; 
public class RobotDemo extends JFrame { 
public RobotDemo() { 
// JFrame with TextArea Settings 
setTitle("OXUS20 Robot Demo"); 
setSize(400, 200); 
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
setLocationRelativeTo(null); 
JTextArea txtOXUS = new JTextArea(); 
add(txtOXUS, BorderLayout.CENTER); 
setVisible(true); 
} 
21 
https://www.facebook.com/Oxus20
public static void main(String[] args) { 
new RobotDemo(); 
// Store Keystrokes "OXUS20" in an array 
int keyInput[] = { KeyEvent.VK_O, KeyEvent.VK_X, KeyEvent.VK_U, 
KeyEvent.VK_S, KeyEvent.VK_2, KeyEvent.VK_0 }; 
try { 
Robot robot = new Robot(); 
// press the shift key 
robot.keyPress(KeyEvent.VK_SHIFT); 
// This types the word 'OXUS20' in the TextArea 
for (int i = 0; i < keyInput.length; i++) { 
if (i > 0) { 
robot.keyRelease(KeyEvent.VK_SHIFT); 
} 
robot.keyPress(keyInput[i]); 
// pause typing for one second 
robot.delay(1000); 
} 
} catch (AWTException e) { 
System.err.println("Exception is happening!"); 
} 
} // end of main() 
} // end of RobotDemo class 
22 
https://www.facebook.com/Oxus20
https://www.facebook.com/Oxus20 
23
Toolkit class 
»Toolkit is an AWT class acting as a base class for all implementations of AWT. 
»This class offers a static method getDefaultToolkit() to return a Toolkit object representing the default implementation of AWT. 
»You can use this default toolkit object to get information of the default graphics device, the local screen, and other purposes. 
»Next slide demonstrate an example finding out the actual size and resolution of your screen. 
24 
https://www.facebook.com/Oxus20
Toolkit Class Demo Source Code 
import java.awt.Dimension; 
import java.awt.Toolkit; 
public class ToolkitDemo { 
public static void main(String[] a) { 
Toolkit tk = Toolkit.getDefaultToolkit(); 
Dimension d = tk.getScreenSize(); 
System.out.println("Screen size: " + d.width + "x" + d.height); 
System.out.println("nScreen Resolution: " + tk.getScreenResolution()); 
} 
} 
25 
https://www.facebook.com/Oxus20
Toolkit Class Demo OUTPUT 
Screen Size: 1366x768 
Screen Resolution: 96 
26 
https://www.facebook.com/Oxus20
Another Toolkit Example 
»Change the state of the Caps Lock key 
˃If Caps Lock key is ON turn it OFF 
˃Otherwise, if Caps Lock key is OFF turn it ON 
»Toolkit.getDefaultToolkit().setLockingKeyState( KeyEvent.VK_CAPS_LOCK, false); 
˃This line of code will change the state of the Caps Lock key OFF. 
»Toolkit.getDefaultToolkit().setLockingKeyState( KeyEvent.VK_CAPS_LOCK, true); 
˃This line of code will change the state of the Caps Lock key ON. 
»Accordingly the keyboard LEDs flash will become ON or OFF. 
27 
https://www.facebook.com/Oxus20
Another Toolkit Class Demo Source Code 
import java.awt.FlowLayout; 
import java.awt.Toolkit; 
import java.awt.event.ItemEvent; 
import java.awt.event.ItemListener; 
import java.awt.event.KeyEvent; 
import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.JToggleButton; 
class ChangeCapsLockStateDemo { 
JLabel lblOutput; 
JToggleButton btnOnOff; 
JFrame win; 
ChangeCapsLockStateDemo() { 
// JFrame Customization 
win = new JFrame("Using JToggleButton"); 
win.setLayout(new FlowLayout()); 
win.setSize(300, 80); 
win.setLocationRelativeTo(null); 
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
28 
https://www.facebook.com/Oxus20
// JToggleButton and JLabel Customization 
lblOutput = new JLabel("CapsLock : OFF"); 
Toolkit.getDefaultToolkit().setLockingKeyState(KeyEvent.VK_CAPS_LOCK, false); 
btnOnOff = new JToggleButton("On / Off", false); 
// Add item listener for JToggleButton. 
btnOnOff.addItemListener(new ItemListener() { 
public void itemStateChanged(ItemEvent ie) { 
if (btnOnOff.isSelected()) { 
lblOutput.setText("CapsLock : ON"); 
Toolkit.getDefaultToolkit().setLockingKeyState(KeyEvent.VK_CAPS_LOCK, true); 
} else { 
lblOutput.setText("CapsLock : OFF"); 
Toolkit.getDefaultToolkit().setLockingKeyState(KeyEvent.VK_CAPS_LOCK, false); 
} 
} 
}); 
// Add toggle button and label to the content pane. 
win.add(btnOnOff); 
win.add(lblOutput); 
win.setVisible(true); 
} 
public static void main(String args[]) { 
new ChangeCapsLockStateDemo(); 
} 
} 
29 
https://www.facebook.com/Oxus20
Another Toolkit Class Demo OUPUT 
30 
https://www.facebook.com/Oxus20
https://www.facebook.com/Oxus20 
31
Java Virtual Keyboard Source Code 
import java.awt.AWTException; 
import java.awt.Color; 
import java.awt.Robot; 
import java.awt.Toolkit; 
import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 
import java.awt.event.ItemEvent; 
import java.awt.event.ItemListener; 
import java.awt.event.KeyEvent; 
import javax.swing.ImageIcon; 
import javax.swing.JButton; 
import javax.swing.JFrame; 
import javax.swing.JLabel; 
import javax.swing.JPanel; 
import javax.swing.JToggleButton; 
public class JavaVirtualKeyboard implements ActionListener, ItemListener { 
32 
https://www.facebook.com/Oxus20
Java Virtual Keyboard OUTPUT 
33 
https://www.facebook.com/Oxus20
Complete Source Code will be published very soon Check Our Facebook Page (https://www.facebook.com/Oxus20) 
34 
https://www.facebook.com/Oxus20
END 
https://www.facebook.com/Oxus20 
35

More Related Content

What's hot

[XCode] Automating UI Testing
[XCode] Automating UI Testing[XCode] Automating UI Testing
[XCode] Automating UI Testing
Phineas Huang
 
Create Splash Screen with Java Step by Step
Create Splash Screen with Java Step by StepCreate Splash Screen with Java Step by Step
Create Splash Screen with Java Step by Step
Abdul Rahman Sherzad
 
iOS Automation: XCUITest + Gherkin
iOS Automation: XCUITest + GherkiniOS Automation: XCUITest + Gherkin
iOS Automation: XCUITest + Gherkin
Kenneth Poon
 
Gdg san diego android 11 meetups what's new in android - ui and dev tools
Gdg san diego android 11 meetups  what's new in android  - ui and dev toolsGdg san diego android 11 meetups  what's new in android  - ui and dev tools
Gdg san diego android 11 meetups what's new in android - ui and dev tools
Svetlin Stanchev
 
Getting touchy - an introduction to touch and pointer events / TPAC 2016 / Li...
Getting touchy - an introduction to touch and pointer events / TPAC 2016 / Li...Getting touchy - an introduction to touch and pointer events / TPAC 2016 / Li...
Getting touchy - an introduction to touch and pointer events / TPAC 2016 / Li...
Patrick Lauke
 
The Ring programming language version 1.5.1 book - Part 67 of 180
The Ring programming language version 1.5.1 book - Part 67 of 180The Ring programming language version 1.5.1 book - Part 67 of 180
The Ring programming language version 1.5.1 book - Part 67 of 180
Mahmoud Samir Fayed
 
Getting touchy - an introduction to touch events / Webinale / Berlin 04.06.2013
Getting touchy - an introduction to touch events / Webinale / Berlin 04.06.2013Getting touchy - an introduction to touch events / Webinale / Berlin 04.06.2013
Getting touchy - an introduction to touch events / Webinale / Berlin 04.06.2013Patrick Lauke
 
Tutorial 8 menu
Tutorial 8   menuTutorial 8   menu
Tutorial 8 menu
Erlang Herlambang
 
Connecting Flash and Javascript using ExternalInterface
Connecting Flash and Javascript using ExternalInterfaceConnecting Flash and Javascript using ExternalInterface
Connecting Flash and Javascript using ExternalInterface
Bri Lance
 
More android code puzzles
More android code puzzlesMore android code puzzles
More android code puzzles
Danny Preussler
 
Crash Wars - The handling awakens
Crash Wars  - The handling awakensCrash Wars  - The handling awakens
Crash Wars - The handling awakens
Željko Plesac
 
Getting touchy - an introduction to touch events / Web Standards Days / Mosco...
Getting touchy - an introduction to touch events / Web Standards Days / Mosco...Getting touchy - an introduction to touch events / Web Standards Days / Mosco...
Getting touchy - an introduction to touch events / Web Standards Days / Mosco...Patrick Lauke
 
Daejeon IT Developer Conference Web Service Practice
Daejeon IT Developer Conference Web Service PracticeDaejeon IT Developer Conference Web Service Practice
Daejeon IT Developer Conference Web Service Practice
plusperson
 
DrupalCon Dublin 2016 - Automated browser testing with Nightwatch.js
DrupalCon Dublin 2016 - Automated browser testing with Nightwatch.jsDrupalCon Dublin 2016 - Automated browser testing with Nightwatch.js
DrupalCon Dublin 2016 - Automated browser testing with Nightwatch.js
Vladimir Roudakov
 
Eyes or heart
Eyes or heartEyes or heart
Eyes or heart
Yevhen Rudiev
 
Google Plus SignIn : l'Authentification Google
Google Plus SignIn : l'Authentification GoogleGoogle Plus SignIn : l'Authentification Google
Google Plus SignIn : l'Authentification Google
Mathias Seguy
 
The Ring programming language version 1.8 book - Part 78 of 202
The Ring programming language version 1.8 book - Part 78 of 202The Ring programming language version 1.8 book - Part 78 of 202
The Ring programming language version 1.8 book - Part 78 of 202
Mahmoud Samir Fayed
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Mahmoud Hamed Mahmoud
 
Android code puzzlers + tips & tricks
Android code puzzlers + tips & tricksAndroid code puzzlers + tips & tricks
Android code puzzlers + tips & tricksNLJUG
 

What's hot (20)

[XCode] Automating UI Testing
[XCode] Automating UI Testing[XCode] Automating UI Testing
[XCode] Automating UI Testing
 
Create Splash Screen with Java Step by Step
Create Splash Screen with Java Step by StepCreate Splash Screen with Java Step by Step
Create Splash Screen with Java Step by Step
 
Swtbot
SwtbotSwtbot
Swtbot
 
iOS Automation: XCUITest + Gherkin
iOS Automation: XCUITest + GherkiniOS Automation: XCUITest + Gherkin
iOS Automation: XCUITest + Gherkin
 
Gdg san diego android 11 meetups what's new in android - ui and dev tools
Gdg san diego android 11 meetups  what's new in android  - ui and dev toolsGdg san diego android 11 meetups  what's new in android  - ui and dev tools
Gdg san diego android 11 meetups what's new in android - ui and dev tools
 
Getting touchy - an introduction to touch and pointer events / TPAC 2016 / Li...
Getting touchy - an introduction to touch and pointer events / TPAC 2016 / Li...Getting touchy - an introduction to touch and pointer events / TPAC 2016 / Li...
Getting touchy - an introduction to touch and pointer events / TPAC 2016 / Li...
 
The Ring programming language version 1.5.1 book - Part 67 of 180
The Ring programming language version 1.5.1 book - Part 67 of 180The Ring programming language version 1.5.1 book - Part 67 of 180
The Ring programming language version 1.5.1 book - Part 67 of 180
 
Getting touchy - an introduction to touch events / Webinale / Berlin 04.06.2013
Getting touchy - an introduction to touch events / Webinale / Berlin 04.06.2013Getting touchy - an introduction to touch events / Webinale / Berlin 04.06.2013
Getting touchy - an introduction to touch events / Webinale / Berlin 04.06.2013
 
Tutorial 8 menu
Tutorial 8   menuTutorial 8   menu
Tutorial 8 menu
 
Connecting Flash and Javascript using ExternalInterface
Connecting Flash and Javascript using ExternalInterfaceConnecting Flash and Javascript using ExternalInterface
Connecting Flash and Javascript using ExternalInterface
 
More android code puzzles
More android code puzzlesMore android code puzzles
More android code puzzles
 
Crash Wars - The handling awakens
Crash Wars  - The handling awakensCrash Wars  - The handling awakens
Crash Wars - The handling awakens
 
Getting touchy - an introduction to touch events / Web Standards Days / Mosco...
Getting touchy - an introduction to touch events / Web Standards Days / Mosco...Getting touchy - an introduction to touch events / Web Standards Days / Mosco...
Getting touchy - an introduction to touch events / Web Standards Days / Mosco...
 
Daejeon IT Developer Conference Web Service Practice
Daejeon IT Developer Conference Web Service PracticeDaejeon IT Developer Conference Web Service Practice
Daejeon IT Developer Conference Web Service Practice
 
DrupalCon Dublin 2016 - Automated browser testing with Nightwatch.js
DrupalCon Dublin 2016 - Automated browser testing with Nightwatch.jsDrupalCon Dublin 2016 - Automated browser testing with Nightwatch.js
DrupalCon Dublin 2016 - Automated browser testing with Nightwatch.js
 
Eyes or heart
Eyes or heartEyes or heart
Eyes or heart
 
Google Plus SignIn : l'Authentification Google
Google Plus SignIn : l'Authentification GoogleGoogle Plus SignIn : l'Authentification Google
Google Plus SignIn : l'Authentification Google
 
The Ring programming language version 1.8 book - Part 78 of 202
The Ring programming language version 1.8 book - Part 78 of 202The Ring programming language version 1.8 book - Part 78 of 202
The Ring programming language version 1.8 book - Part 78 of 202
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development
 
Android code puzzlers + tips & tricks
Android code puzzlers + tips & tricksAndroid code puzzlers + tips & tricks
Android code puzzlers + tips & tricks
 

Viewers also liked

Java Regular Expression PART II
Java Regular Expression PART IIJava Regular Expression PART II
Java Regular Expression PART II
OXUS 20
 
Java Applet and Graphics
Java Applet and GraphicsJava Applet and Graphics
Java Applet and Graphics
OXUS 20
 
Java Regular Expression PART I
Java Regular Expression PART IJava Regular Expression PART I
Java Regular Expression PART I
OXUS 20
 
PHP Basic and Fundamental Questions and Answers with Detail Explanation
PHP Basic and Fundamental Questions and Answers with Detail ExplanationPHP Basic and Fundamental Questions and Answers with Detail Explanation
PHP Basic and Fundamental Questions and Answers with Detail Explanation
OXUS 20
 
Everything about Object Oriented Programming
Everything about Object Oriented ProgrammingEverything about Object Oriented Programming
Everything about Object Oriented Programming
Abdul Rahman Sherzad
 
TKP Java Notes for Teaching Kids Programming
TKP Java Notes for Teaching Kids ProgrammingTKP Java Notes for Teaching Kids Programming
TKP Java Notes for Teaching Kids Programming
Lynn Langit
 
Java Unicode with Cool GUI Examples
Java Unicode with Cool GUI ExamplesJava Unicode with Cool GUI Examples
Java Unicode with Cool GUI Examples
OXUS 20
 
Conditional Statement
Conditional Statement Conditional Statement
Conditional Statement
OXUS 20
 
Fal-e-Hafez (Omens of Hafez) Cards in Persian using Java
Fal-e-Hafez (Omens of Hafez) Cards in Persian using JavaFal-e-Hafez (Omens of Hafez) Cards in Persian using Java
Fal-e-Hafez (Omens of Hafez) Cards in Persian using Java
OXUS 20
 
Java Guessing Game Number Tutorial
Java Guessing Game Number TutorialJava Guessing Game Number Tutorial
Java Guessing Game Number Tutorial
OXUS 20
 
Object Oriented Concept Static vs. Non Static
Object Oriented Concept Static vs. Non StaticObject Oriented Concept Static vs. Non Static
Object Oriented Concept Static vs. Non Static
OXUS 20
 
Structure programming – Java Programming – Theory
Structure programming – Java Programming – TheoryStructure programming – Java Programming – Theory
Structure programming – Java Programming – Theory
OXUS 20
 
Web Design and Development Life Cycle and Technologies
Web Design and Development Life Cycle and TechnologiesWeb Design and Development Life Cycle and Technologies
Web Design and Development Life Cycle and Technologies
OXUS 20
 
Create Splash Screen with Java Step by Step
Create Splash Screen with Java Step by StepCreate Splash Screen with Java Step by Step
Create Splash Screen with Java Step by Step
OXUS 20
 
Note - Java Remote Debug
Note - Java Remote DebugNote - Java Remote Debug
Note - Java Remote Debugboyw165
 
Everything about Database JOINS and Relationships
Everything about Database JOINS and RelationshipsEverything about Database JOINS and Relationships
Everything about Database JOINS and Relationships
OXUS 20
 
Core java notes with examples
Core java notes with examplesCore java notes with examples
Core java notes with examples
bindur87
 
Java Unicode with Live GUI Examples
Java Unicode with Live GUI ExamplesJava Unicode with Live GUI Examples
Java Unicode with Live GUI Examples
Abdul Rahman Sherzad
 
Jdbc Complete Notes by Java Training Center (Som Sir)
Jdbc Complete Notes by Java Training Center (Som Sir)Jdbc Complete Notes by Java Training Center (Som Sir)
Jdbc Complete Notes by Java Training Center (Som Sir)
Som Prakash Rai
 

Viewers also liked (20)

Java Regular Expression PART II
Java Regular Expression PART IIJava Regular Expression PART II
Java Regular Expression PART II
 
Java Applet and Graphics
Java Applet and GraphicsJava Applet and Graphics
Java Applet and Graphics
 
Java Regular Expression PART I
Java Regular Expression PART IJava Regular Expression PART I
Java Regular Expression PART I
 
PHP Basic and Fundamental Questions and Answers with Detail Explanation
PHP Basic and Fundamental Questions and Answers with Detail ExplanationPHP Basic and Fundamental Questions and Answers with Detail Explanation
PHP Basic and Fundamental Questions and Answers with Detail Explanation
 
Everything about Object Oriented Programming
Everything about Object Oriented ProgrammingEverything about Object Oriented Programming
Everything about Object Oriented Programming
 
TKP Java Notes for Teaching Kids Programming
TKP Java Notes for Teaching Kids ProgrammingTKP Java Notes for Teaching Kids Programming
TKP Java Notes for Teaching Kids Programming
 
Java Unicode with Cool GUI Examples
Java Unicode with Cool GUI ExamplesJava Unicode with Cool GUI Examples
Java Unicode with Cool GUI Examples
 
Conditional Statement
Conditional Statement Conditional Statement
Conditional Statement
 
Fal-e-Hafez (Omens of Hafez) Cards in Persian using Java
Fal-e-Hafez (Omens of Hafez) Cards in Persian using JavaFal-e-Hafez (Omens of Hafez) Cards in Persian using Java
Fal-e-Hafez (Omens of Hafez) Cards in Persian using Java
 
Java Guessing Game Number Tutorial
Java Guessing Game Number TutorialJava Guessing Game Number Tutorial
Java Guessing Game Number Tutorial
 
Object Oriented Concept Static vs. Non Static
Object Oriented Concept Static vs. Non StaticObject Oriented Concept Static vs. Non Static
Object Oriented Concept Static vs. Non Static
 
Structure programming – Java Programming – Theory
Structure programming – Java Programming – TheoryStructure programming – Java Programming – Theory
Structure programming – Java Programming – Theory
 
Web Design and Development Life Cycle and Technologies
Web Design and Development Life Cycle and TechnologiesWeb Design and Development Life Cycle and Technologies
Web Design and Development Life Cycle and Technologies
 
Create Splash Screen with Java Step by Step
Create Splash Screen with Java Step by StepCreate Splash Screen with Java Step by Step
Create Splash Screen with Java Step by Step
 
Note - Java Remote Debug
Note - Java Remote DebugNote - Java Remote Debug
Note - Java Remote Debug
 
Everything about Database JOINS and Relationships
Everything about Database JOINS and RelationshipsEverything about Database JOINS and Relationships
Everything about Database JOINS and Relationships
 
Core java notes with examples
Core java notes with examplesCore java notes with examples
Core java notes with examples
 
Java Unicode with Live GUI Examples
Java Unicode with Live GUI ExamplesJava Unicode with Live GUI Examples
Java Unicode with Live GUI Examples
 
Jdbc Complete Notes by Java Training Center (Som Sir)
Jdbc Complete Notes by Java Training Center (Som Sir)Jdbc Complete Notes by Java Training Center (Som Sir)
Jdbc Complete Notes by Java Training Center (Som Sir)
 
Advanced core java
Advanced core javaAdvanced core java
Advanced core java
 

Similar to Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes

SWTBot Tutorial
SWTBot TutorialSWTBot Tutorial
SWTBot Tutorial
Chris Aniszczyk
 
Griffon @ Svwjug
Griffon @ SvwjugGriffon @ Svwjug
Griffon @ Svwjug
Andres Almiray
 
Groovy-er desktop applications with Griffon
Groovy-er desktop applications with GriffonGroovy-er desktop applications with Griffon
Groovy-er desktop applications with Griffon
Eric Wendelin
 
Groovy-er Desktop Applications With Griffon
Groovy-er Desktop Applications With GriffonGroovy-er Desktop Applications With Griffon
Groovy-er Desktop Applications With Griffon
Matthew McCullough
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
Thierry Wasylczenko
 
Making Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMMaking Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVM
Rafael Winterhalter
 
Orsiso
OrsisoOrsiso
Orsisoe27
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
Tomek Kaczanowski
 
JAVA SWITCH STATEMENT
JAVA SWITCH STATEMENTJAVA SWITCH STATEMENT
JAVA SWITCH STATEMENT
Rhythm Suiwal
 
package buttongui; import static com.sun.deploy.config.JREInf.pdf
package buttongui; import static com.sun.deploy.config.JREInf.pdfpackage buttongui; import static com.sun.deploy.config.JREInf.pdf
package buttongui; import static com.sun.deploy.config.JREInf.pdf
arjuntiwari586
 
#JavaFX.forReal() - ElsassJUG
#JavaFX.forReal() - ElsassJUG#JavaFX.forReal() - ElsassJUG
#JavaFX.forReal() - ElsassJUG
Thierry Wasylczenko
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good TestsTomek Kaczanowski
 
Imagine a world without mocks
Imagine a world without mocksImagine a world without mocks
Imagine a world without mocks
kenbot
 
Android testing
Android testingAndroid testing
Android testing
Sean Tsai
 
Day 5
Day 5Day 5
Does testability imply good design - Andrzej Jóźwiak - TomTom Dev Day 2022
Does testability imply good design - Andrzej Jóźwiak - TomTom Dev Day 2022Does testability imply good design - Andrzej Jóźwiak - TomTom Dev Day 2022
Does testability imply good design - Andrzej Jóźwiak - TomTom Dev Day 2022
Andrzej Jóźwiak
 
Mobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhoneMobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhoneMohammad Shaker
 
New microsoft office word document
New microsoft office word documentNew microsoft office word document
New microsoft office word documentnidhileena
 
meet.js - QooXDoo
meet.js - QooXDoomeet.js - QooXDoo
meet.js - QooXDoo
Radek Benkel
 

Similar to Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes (20)

SWTBot Tutorial
SWTBot TutorialSWTBot Tutorial
SWTBot Tutorial
 
Griffon @ Svwjug
Griffon @ SvwjugGriffon @ Svwjug
Griffon @ Svwjug
 
Groovy-er desktop applications with Griffon
Groovy-er desktop applications with GriffonGroovy-er desktop applications with Griffon
Groovy-er desktop applications with Griffon
 
Groovy-er Desktop Applications With Griffon
Groovy-er Desktop Applications With GriffonGroovy-er Desktop Applications With Griffon
Groovy-er Desktop Applications With Griffon
 
Google Web Toolkit
Google Web ToolkitGoogle Web Toolkit
Google Web Toolkit
 
Construire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradleConstruire une application JavaFX 8 avec gradle
Construire une application JavaFX 8 avec gradle
 
Making Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVMMaking Java more dynamic: runtime code generation for the JVM
Making Java more dynamic: runtime code generation for the JVM
 
Orsiso
OrsisoOrsiso
Orsiso
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
 
JAVA SWITCH STATEMENT
JAVA SWITCH STATEMENTJAVA SWITCH STATEMENT
JAVA SWITCH STATEMENT
 
package buttongui; import static com.sun.deploy.config.JREInf.pdf
package buttongui; import static com.sun.deploy.config.JREInf.pdfpackage buttongui; import static com.sun.deploy.config.JREInf.pdf
package buttongui; import static com.sun.deploy.config.JREInf.pdf
 
#JavaFX.forReal() - ElsassJUG
#JavaFX.forReal() - ElsassJUG#JavaFX.forReal() - ElsassJUG
#JavaFX.forReal() - ElsassJUG
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests
 
Imagine a world without mocks
Imagine a world without mocksImagine a world without mocks
Imagine a world without mocks
 
Android testing
Android testingAndroid testing
Android testing
 
Day 5
Day 5Day 5
Day 5
 
Does testability imply good design - Andrzej Jóźwiak - TomTom Dev Day 2022
Does testability imply good design - Andrzej Jóźwiak - TomTom Dev Day 2022Does testability imply good design - Andrzej Jóźwiak - TomTom Dev Day 2022
Does testability imply good design - Andrzej Jóźwiak - TomTom Dev Day 2022
 
Mobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhoneMobile Software Engineering Crash Course - C06 WindowsPhone
Mobile Software Engineering Crash Course - C06 WindowsPhone
 
New microsoft office word document
New microsoft office word documentNew microsoft office word document
New microsoft office word document
 
meet.js - QooXDoo
meet.js - QooXDoomeet.js - QooXDoo
meet.js - QooXDoo
 

More from OXUS 20

Java Arrays
Java ArraysJava Arrays
Java Arrays
OXUS 20
 
Java Methods
Java MethodsJava Methods
Java MethodsOXUS 20
 
Fundamentals of Database Systems Questions and Answers
Fundamentals of Database Systems Questions and AnswersFundamentals of Database Systems Questions and Answers
Fundamentals of Database Systems Questions and Answers
OXUS 20
 
JAVA GUI PART III
JAVA GUI PART IIIJAVA GUI PART III
JAVA GUI PART III
OXUS 20
 
Java GUI PART II
Java GUI PART IIJava GUI PART II
Java GUI PART II
OXUS 20
 
JAVA GUI PART I
JAVA GUI PART IJAVA GUI PART I
JAVA GUI PART I
OXUS 20
 
JAVA Programming Questions and Answers PART III
JAVA Programming Questions and Answers PART IIIJAVA Programming Questions and Answers PART III
JAVA Programming Questions and Answers PART IIIOXUS 20
 
Object Oriented Programming with Real World Examples
Object Oriented Programming with Real World ExamplesObject Oriented Programming with Real World Examples
Object Oriented Programming with Real World Examples
OXUS 20
 

More from OXUS 20 (8)

Java Arrays
Java ArraysJava Arrays
Java Arrays
 
Java Methods
Java MethodsJava Methods
Java Methods
 
Fundamentals of Database Systems Questions and Answers
Fundamentals of Database Systems Questions and AnswersFundamentals of Database Systems Questions and Answers
Fundamentals of Database Systems Questions and Answers
 
JAVA GUI PART III
JAVA GUI PART IIIJAVA GUI PART III
JAVA GUI PART III
 
Java GUI PART II
Java GUI PART IIJava GUI PART II
Java GUI PART II
 
JAVA GUI PART I
JAVA GUI PART IJAVA GUI PART I
JAVA GUI PART I
 
JAVA Programming Questions and Answers PART III
JAVA Programming Questions and Answers PART IIIJAVA Programming Questions and Answers PART III
JAVA Programming Questions and Answers PART III
 
Object Oriented Programming with Real World Examples
Object Oriented Programming with Real World ExamplesObject Oriented Programming with Real World Examples
Object Oriented Programming with Real World Examples
 

Recently uploaded

How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
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.
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
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
 
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
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 

Recently uploaded (20)

How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
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
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.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
 
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
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 

Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes

  • 1. https://www.facebook.com/Oxus20 oxus20@gmail.com JAVA Virtual Keyboard »Exception Handling »JToggleButton Class »Robot Class »Toolkit Class Prepared By: Nahid Ahmadi Edited By: Abdul Rahman Sherzad
  • 2. Agenda »Virtual Keyboard »Exception Handling »JToggleButton Class »Robot Class »Toolkit Class »Virtual Keyboard Implementation 2 https://www.facebook.com/Oxus20
  • 4. Virtual Keyboard Using JAVA 4 https://www.facebook.com/Oxus20
  • 5. Introduction to Virtual Keyboard »A virtual keyboard is considered to be a component to use on computers without a real keyboard e.g. ˃touch screen computer »A mouse can utilize the keyboard functionalities and features. 5 https://www.facebook.com/Oxus20
  • 6. Virtual Keyboard Usage »It is possible to obtain keyboards for the following specific purposes: ˃Keyboards to fill specific forms on sites ˃Special key arrangements ˃Keyboards for dedicated commercial sites ˃etc. »In addition, Virtual Keyboard used for the following subjects: ˃Foreign Character Sets ˃Touchscreens ˃Bypass key loggers 6 https://www.facebook.com/Oxus20
  • 8. Exception Handling »A program can be written assuming that nothing unusual or incorrect will happen. ˃The user will always enter an integer when prompted to do so. ˃There will always be a nonempty list for a program that takes an entry from the list. ˃The file containing the needed information will always exist. »Unfortunately, it isn't always so. »Once the core program is written for the usual, expected case(s), Java's exception-handling facilities should be added to accommodate the unusual, unexpected case(s). 8
  • 9. Exception Hierarchy 9 https://www.facebook.com/Oxus20
  • 10. Exception Handling Demo Source code public class ExceptionHandlingDemo { public static void main(String args[]) { try { int scores[] = { 90, 85, 75, 100 }; System.out.println("Access element nine:" + scores[9]); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("Exception thrown:" + e); } System.out.println("nWithout Exception Handling I was not able to execute and print!"); } } 10 https://www.facebook.com/Oxus20
  • 11. Exception Handling Demo OUTPUT Exception thrown:java.lang.ArrayIndexOutOfBoundsException: 9 Without Exception Handling I was not able to execute and print! 11 https://www.facebook.com/Oxus20
  • 13. JToggleButton Class »JToggleButton is an implementation of a two-state button and is used to represent buttons that can be toggled ON and OFF »The JRadioButton and JCheckBox classes are subclasses of this class. »The events fired by JToggleButtons are slightly different than those fired by JButton. 13 https://www.facebook.com/Oxus20
  • 14. JToggleButton Demo »The following example on next slide demonstrates a toggle button. Each time the toggle button is pressed, its state is displayed in a label. »Creating JToggleButton involves these steps: 1.Create an instance of JToggleButton. 2.Register an ItemListener to handle item events generated by the button. 3.To determine if the button is on or off, call isSelected(). 14 https://www.facebook.com/Oxus20
  • 15. JToggleButton Demo Source Code import java.awt.FlowLayout; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JToggleButton; class JToggleButtonDemo { JLabel lblOutput; JToggleButton btnOnOff; JFrame win; JToggleButtonDemo() { // JFrame Customization win = new JFrame("Using JToggleButton"); win.setLayout(new FlowLayout()); win.setSize(300, 80); win.setLocationRelativeTo(null); win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 15 https://www.facebook.com/Oxus20
  • 16. // JToggleButton and JLabel Customization lblOutput = new JLabel("State : OFF"); btnOnOff = new JToggleButton("On / Off", false); // Add item listener for JToggleButton. btnOnOff.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent ie) { if (btnOnOff.isSelected()) { lblOutput.setText("State : ON"); } else { lblOutput.setText("State : OFF"); } } }); // Add toggle button and label to the content pane. win.add(btnOnOff); win.add(lblOutput); win.setVisible(true); } public static void main(String args[]) { new JToggleButtonDemo(); } } 16 https://www.facebook.com/Oxus20
  • 17. JToggleButton Demo OUTPUT 17 https://www.facebook.com/Oxus20
  • 19. Java Robot Class »This class is used to generate native system input events for the purposes of ˃test automation ˃self-running demos ˃and other applications where control of the mouse and keyboard is needed. »This class has three main functionalities: ˃mouse control ˃keyboard control ˃and screen capture. https://www.facebook.com/Oxus20 19
  • 20. Robot Class Demo »Perform keyboard operation with help of java Robot class. »The following example on next slide will demonstrate the Robot class usage to handle the keyboard events. »The program will write the word "OXUS20" inside the TextArea automatically after running the program. »The word "OXUS20" will be written character by character with one second delay between each on of the characters. 20 https://www.facebook.com/Oxus20
  • 21. Robot Class Demo Source Code import java.awt.AWTException; import java.awt.BorderLayout; import java.awt.Robot; import java.awt.event.KeyEvent; import javax.swing.JFrame; import javax.swing.JTextArea; public class RobotDemo extends JFrame { public RobotDemo() { // JFrame with TextArea Settings setTitle("OXUS20 Robot Demo"); setSize(400, 200); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationRelativeTo(null); JTextArea txtOXUS = new JTextArea(); add(txtOXUS, BorderLayout.CENTER); setVisible(true); } 21 https://www.facebook.com/Oxus20
  • 22. public static void main(String[] args) { new RobotDemo(); // Store Keystrokes "OXUS20" in an array int keyInput[] = { KeyEvent.VK_O, KeyEvent.VK_X, KeyEvent.VK_U, KeyEvent.VK_S, KeyEvent.VK_2, KeyEvent.VK_0 }; try { Robot robot = new Robot(); // press the shift key robot.keyPress(KeyEvent.VK_SHIFT); // This types the word 'OXUS20' in the TextArea for (int i = 0; i < keyInput.length; i++) { if (i > 0) { robot.keyRelease(KeyEvent.VK_SHIFT); } robot.keyPress(keyInput[i]); // pause typing for one second robot.delay(1000); } } catch (AWTException e) { System.err.println("Exception is happening!"); } } // end of main() } // end of RobotDemo class 22 https://www.facebook.com/Oxus20
  • 24. Toolkit class »Toolkit is an AWT class acting as a base class for all implementations of AWT. »This class offers a static method getDefaultToolkit() to return a Toolkit object representing the default implementation of AWT. »You can use this default toolkit object to get information of the default graphics device, the local screen, and other purposes. »Next slide demonstrate an example finding out the actual size and resolution of your screen. 24 https://www.facebook.com/Oxus20
  • 25. Toolkit Class Demo Source Code import java.awt.Dimension; import java.awt.Toolkit; public class ToolkitDemo { public static void main(String[] a) { Toolkit tk = Toolkit.getDefaultToolkit(); Dimension d = tk.getScreenSize(); System.out.println("Screen size: " + d.width + "x" + d.height); System.out.println("nScreen Resolution: " + tk.getScreenResolution()); } } 25 https://www.facebook.com/Oxus20
  • 26. Toolkit Class Demo OUTPUT Screen Size: 1366x768 Screen Resolution: 96 26 https://www.facebook.com/Oxus20
  • 27. Another Toolkit Example »Change the state of the Caps Lock key ˃If Caps Lock key is ON turn it OFF ˃Otherwise, if Caps Lock key is OFF turn it ON »Toolkit.getDefaultToolkit().setLockingKeyState( KeyEvent.VK_CAPS_LOCK, false); ˃This line of code will change the state of the Caps Lock key OFF. »Toolkit.getDefaultToolkit().setLockingKeyState( KeyEvent.VK_CAPS_LOCK, true); ˃This line of code will change the state of the Caps Lock key ON. »Accordingly the keyboard LEDs flash will become ON or OFF. 27 https://www.facebook.com/Oxus20
  • 28. Another Toolkit Class Demo Source Code import java.awt.FlowLayout; import java.awt.Toolkit; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.KeyEvent; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JToggleButton; class ChangeCapsLockStateDemo { JLabel lblOutput; JToggleButton btnOnOff; JFrame win; ChangeCapsLockStateDemo() { // JFrame Customization win = new JFrame("Using JToggleButton"); win.setLayout(new FlowLayout()); win.setSize(300, 80); win.setLocationRelativeTo(null); win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 28 https://www.facebook.com/Oxus20
  • 29. // JToggleButton and JLabel Customization lblOutput = new JLabel("CapsLock : OFF"); Toolkit.getDefaultToolkit().setLockingKeyState(KeyEvent.VK_CAPS_LOCK, false); btnOnOff = new JToggleButton("On / Off", false); // Add item listener for JToggleButton. btnOnOff.addItemListener(new ItemListener() { public void itemStateChanged(ItemEvent ie) { if (btnOnOff.isSelected()) { lblOutput.setText("CapsLock : ON"); Toolkit.getDefaultToolkit().setLockingKeyState(KeyEvent.VK_CAPS_LOCK, true); } else { lblOutput.setText("CapsLock : OFF"); Toolkit.getDefaultToolkit().setLockingKeyState(KeyEvent.VK_CAPS_LOCK, false); } } }); // Add toggle button and label to the content pane. win.add(btnOnOff); win.add(lblOutput); win.setVisible(true); } public static void main(String args[]) { new ChangeCapsLockStateDemo(); } } 29 https://www.facebook.com/Oxus20
  • 30. Another Toolkit Class Demo OUPUT 30 https://www.facebook.com/Oxus20
  • 32. Java Virtual Keyboard Source Code import java.awt.AWTException; import java.awt.Color; import java.awt.Robot; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; import java.awt.event.KeyEvent; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JToggleButton; public class JavaVirtualKeyboard implements ActionListener, ItemListener { 32 https://www.facebook.com/Oxus20
  • 33. Java Virtual Keyboard OUTPUT 33 https://www.facebook.com/Oxus20
  • 34. Complete Source Code will be published very soon Check Our Facebook Page (https://www.facebook.com/Oxus20) 34 https://www.facebook.com/Oxus20