SlideShare a Scribd company logo
https://www.facebook.com/Oxus20 
oxus20@gmail.com 
Java Applet & Graphics 
Java Applet 
Java Graphics 
Analog Clock 
Prepared By: Khosrow Kian 
Edited By: Abdul Rahman Sherzad
Table of Contents 
»Java Applet 
˃Introduction and Concept 
˃Demos 
»Graphics 
˃Introduction and Concept 
»Java Applet Code 
2 
https://www.facebook.com/Oxus20
Java Applet 
»An applet is a subclass of Panel 
˃It is a container which can hold GUI components 
˃It has a graphics context which can be used to draw images 
»An applet embedded within an HTML page 
˃Applets are defined using the <applet> tag 
˃Its size and location are defined within the tag 
»Java Virtual Machine is required for the browsers to execute the applet 
3 
https://www.facebook.com/Oxus20
Java Applets vs. Applications 
»Applets - Java programs that can run over the Internet using a browser. 
˃The browser either contains a JVM (Java Virtual Machine) or loads the Java plugin 
˃Applets do not require a main(), but in general will have a paint(). 
˃An Applet also requires an HTML file before it can be executed. 
˃Java Applets are also compiled using the javac command, but are run either with a browser or with the applet viewer command. 
»Applications - Java programs that run directly on your machine. 
˃Applications must have a main(). 
˃Java applications are compiled using the javac command and run using the java command. 
4 
https://www.facebook.com/Oxus20
Java Applets vs. Applications 
Feature 
Application 
Applet 
main() method 
Present 
Not present 
Execution 
Requires JRE 
Requires a browser like Chrome, Firefox, IE, Safari, Opera, etc. 
Nature 
Called as stand-alone application as application can be executed from command prompt 
Requires some third party tool help like a browser to execute 
Restrictions 
Can access any data or software available on the system 
cannot access any thing on the system except browser’s services 
Security 
Does not require any security 
Requires highest security for the system as they are untrusted 
5 
https://www.facebook.com/Oxus20
Java Applet Advantages 
»Execution of applets is easy in a Web browser and does not require any installation or deployment procedure in real-time programming. 
»Writing and displaying (just opening in a browser) graphics and animations is easier than applications. 
»In GUI development, constructor, size of frame, window closing code etc. are not required. 
6 
https://www.facebook.com/Oxus20
Java Applet Methods 
»init() 
˃Called when applet is loaded onto user’s machine. 
»start() 
˃Called when applet becomes visible (page called up). 
»stop() 
˃Called when applet becomes hidden (page loses focus). 
»destroy() 
˃Guaranteed to be called when browser shuts down. 
7 
https://www.facebook.com/Oxus20
Introduction to Java Graphics 
»Java contains support for graphics that enable programmers to visually enhance applications 
»Java contains many more sophisticated drawing capabilities as part of the Java 2D API 
˃Color 
˃Font and FontMetrics 
˃Graphics2D 
˃Polygon 
˃BasicStroke 
˃GradientPaint and TexturePaint 
˃Java 2D shape classes 
8 
https://www.facebook.com/Oxus20
9 
https://www.facebook.com/Oxus20
Java Coordinate System 
»Upper-Left Corner of a GUI component has the coordinates (0, 0) 
»X-Coordinate (horizontal coordinate) 
˃horizontal distance moving right from the left of the screen 
»Y-Coordinate (vertical coordinate) 
˃vertical distance moving down from the top of the screen 
»Coordinate units are measured in pixels. 
˃A pixel is a display monitor’s smallest unit of resolution. 
https://www.facebook.com/Oxus20 
10
All Roads Lead to JComponent 
»Every Swing object inherits from JComponent 
» JComponent has a few methods that can be overridden in order to draw special things 
˃public void paint(Graphics g) 
˃public void paintComponent(Graphics g) 
˃public void repaint() 
»So if we want custom drawing, we take any JComponent and extend it... 
˃JPanel is a good choice 
11 
https://www.facebook.com/Oxus20
Draw Line Example 
import java.awt.Graphics; 
import javax.swing.JApplet; 
public class DrawLine extends JApplet { 
@Override 
public void init() { 
} 
public void paint(Graphics g){ 
g.drawLine(20,20, 100,100); 
} 
} 
https://www.facebook.com/Oxus20 
12
Draw Rectangles Example 
import java.awt.Graphics; 
import javax.swing.JApplet; 
public class DrawRect extends JApplet { 
@Override 
public void init() { 
super.init(); 
} 
public void paint(Graphics g) { 
g.drawRect(20, 20, 100, 100); 
g.fillRect(130, 20, 100, 100); 
g.drawRoundRect(240, 20, 100, 100, 10, 10); 
} 
} 
https://www.facebook.com/Oxus20 
13
Draw Ovals Example 
import java.awt.Graphics; 
import javax.swing.JApplet; 
public class DrawOval extends JApplet { 
@Override 
public void init() { 
} 
public void paint(Graphics g) { 
g.drawOval(20, 20, 100, 100); 
g.fillOval(130, 20, 100, 100); 
} 
} 
https://www.facebook.com/Oxus20 
14
Simple Calculator Example 
import java.applet.Applet; 
import java.awt.BorderLayout; 
import java.awt.Button; 
import java.awt.Font; 
import java.awt.GridLayout; 
import java.awt.Panel; 
import java.awt.TextField; 
import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 
public class Calculator extends Applet implements ActionListener { 
String operators[] = { "+", "-", "*", "/", "=", "C" }; 
String operator = ""; 
int previousValue = 0; 
Button buttons[] = new Button[16]; 
TextField txtResult = new TextField(10); 
15 
https://www.facebook.com/Oxus20
public void init() { 
setLayout(new BorderLayout()); 
add(txtResult, "North"); 
txtResult.setText("0"); 
Panel p = new Panel(); 
p.setLayout(new GridLayout(4, 4)); 
for (int i = 0; i < 16; i++) { 
if (i < 10) { 
buttons[i] = new Button(String.valueOf(i)); 
} else { 
buttons[i] = new Button(operators[i % 10]); 
} 
buttons[i].setFont(new Font("Verdana", Font.BOLD, 18)); 
p.add(buttons[i]); 
add(p, "Center"); 
buttons[i].addActionListener(this); 
} 
} 
16 
https://www.facebook.com/Oxus20
public void actionPerformed(ActionEvent ae) { 
int result = 0; 
String caption = ae.getActionCommand(); 
int currentValue = Integer.parseInt(txtResult.getText()); 
if (caption.equals("C")) { 
txtResult.setText("0"); 
previousValue = 0; 
currentValue = 0; 
result = 0; 
operator = ""; 
} else if (caption.equals("=")) { 
result = 0; 
if (operator == "+") 
result = previousValue + currentValue; 
else if (operator == "-") 
result = previousValue - currentValue; 
else if (operator == "*") 
result = previousValue * currentValue; 
else if (operator == "/") 
result = previousValue / currentValue; 
txtResult.setText(String.valueOf(result)); 
} 
17 
https://www.facebook.com/Oxus20
End - Simple Calculator Example 
else if (caption.equals("+") || caption.equals("-") 
|| caption.equals("*") || caption.equals("/")) { 
previousValue = currentValue; 
operator = caption; 
txtResult.setText("0"); 
} else { 
int value = currentValue * 10 + Integer.parseInt(caption); 
txtResult.setText(String.valueOf(value)); 
} 
} 
} 
18 
https://www.facebook.com/Oxus20
OUTPUT - Simple Calculator Example 
19 
https://www.facebook.com/Oxus20
Example of Graphics and Applet 
20 
https://www.facebook.com/Oxus20
Analog Clock Example 
21 
https://www.facebook.com/Oxus20 
import java.applet.Applet; 
import java.awt.BasicStroke; 
import java.awt.Color; 
import java.awt.Font; 
import java.awt.Graphics; 
import java.awt.Graphics2D; 
import java.util.Calendar; 
public class AnalogClock extends Applet implements Runnable { 
private static final long serialVersionUID = 1L; 
private static final double TWO_PI = 2.0 * Math.PI; 
private Calendar nw = Calendar.getInstance(); 
int width = 200, hight = 200; 
int xcent = width / 2, ycent = hight / 2; 
int minhand, maxhand; 
double rdns; 
int dxmin, dymin, dxmax, dymax; 
double radins, sine, cosine; 
double fminutes; 
Thread t = null; 
Boolean stopFlag;
22 
https://www.facebook.com/Oxus20 
public void start() { 
t = new Thread(this); 
stopFlag = false; 
t.start(); 
} 
public void run() { 
for (;;) { 
try { 
updateTime(); 
repaint(); 
Thread.sleep(1000); 
if (stopFlag) 
break; 
} catch (InterruptedException e) { 
} 
} 
} 
public void stop() { 
stopFlag = true; 
t = null; 
} 
private void updateTime() { 
nw.setTimeInMillis(System.currentTimeMillis()); 
}
23 
https://www.facebook.com/Oxus20 
public void paint(Graphics g) { 
g.setFont(new Font("Gabriola", Font.BOLD + Font.ITALIC, 160)); 
g.setColor(Color.RED); 
g.drawString("XUS", 300, 270); 
g.setFont(new Font("Consolas", Font.BOLD + Font.ITALIC, 100)); 
g.setColor(Color.GREEN); 
g.drawString("20", 550, 270); 
g.setColor(Color.black); 
g.fillOval(100, 100, 200, 200); 
Graphics2D g1 = (Graphics2D) g; 
int hours = nw.get(Calendar.HOUR); 
int minutes = nw.get(Calendar.MINUTE); 
int seconds = nw.get(Calendar.SECOND); 
int millis = nw.get(Calendar.MILLISECOND); 
minhand = width / 8; 
maxhand = width / 2; 
rdns = (seconds + ((double) millis / 1000)) / 60.0; 
drw(g1, rdns, 0, maxhand - 20); 
g1.setColor(Color.BLUE); 
g1.drawString( 
String.format("%02d : %02d :%02d ", hours, minutes, seconds), 
minhand + 150, maxhand + 170);
24 
https://www.facebook.com/Oxus20 
minhand = 0; // Minute hand starts in middle. 
maxhand = width / 3; 
fminutes = (minutes + rdns) / 60.0; 
drw(g1, fminutes, 0, maxhand); 
minhand = 0; // Minute hand starts in middle. 
maxhand = width / 4; 
drw(g1, (hours + fminutes) / 12.0, 0, maxhand); 
g1.setColor(Color.gray); // set b ackground of circle 
g1.drawOval(100, 100, 200, 200); // draw a circle 
g1.setColor(Color.WHITE); 
g1.setFont(new Font("Consulas", Font.BOLD + Font.ITALIC, 15)); 
g1.drawString("12", 190, 120); 
g1.drawString("6", 195, 290); 
g1.drawString("3", 280, 200); 
g1.drawString("6", 110, 200); 
g1.setFont(new Font("Consulas", Font.BOLD + Font.ITALIC, 15)); 
g1.setStroke(new BasicStroke(2, BasicStroke.JOIN_MITER, 
BasicStroke.JOIN_BEVEL)); 
}
End - Analog Clock Example 
public void drw(Graphics2D g, double prct, int minRadius, int maxRadius) { 
radins = (0.5 - prct) * TWO_PI; 
sine = Math.sin(radins); 
cosine = Math.cos(radins); 
dxmin = xcent + (int) (minRadius * sine); 
dymin = ycent + (int) (minRadius * cosine); 
dxmax = xcent + (int) (maxRadius * sine); 
dymax = ycent + (int) (maxRadius * cosine); 
g.setColor(Color.WHITE); 
g.setBackground(Color.cyan); 
g.setFont(new Font("Consulas", Font.BOLD + Font.ITALIC, 12)); 
g.drawLine(dxmin + 100, dymin + 100, dxmax + 100, dymax + 100); 
} 
} 
25 
https://www.facebook.com/Oxus20
OUTPUT - Analog Clock Example 
26 
https://www.facebook.com/Oxus20
END 
https://www.facebook.com/Oxus20 
27
Ad

More Related Content

What's hot (20)

Introduction to ajax
Introduction  to  ajaxIntroduction  to  ajax
Introduction to ajax
Pihu Goel
 
Java keywords
Java keywordsJava keywords
Java keywords
Ravi_Kant_Sahu
 
Java collections concept
Java collections conceptJava collections concept
Java collections concept
kumar gaurav
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycle
Dhruvin Nakrani
 
Wrapper class
Wrapper classWrapper class
Wrapper class
kamal kotecha
 
Strings
StringsStrings
Strings
naslin prestilda
 
Ajax Presentation
Ajax PresentationAjax Presentation
Ajax Presentation
alaa.moustafa
 
Generics
GenericsGenerics
Generics
Ravi_Kant_Sahu
 
Method overloading
Method overloadingMethod overloading
Method overloading
Lovely Professional University
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
Madishetty Prathibha
 
Applets in java
Applets in javaApplets in java
Applets in java
Wani Zahoor
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
Abhilash Nair
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
shanmuga rajan
 
Ajax presentation
Ajax presentationAjax presentation
Ajax presentation
Bharat_Kumawat
 
Javascript functions
Javascript functionsJavascript functions
Javascript functions
Alaref Abushaala
 
Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVA
Ankita Totala
 
Interface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar SinghInterface in java By Dheeraj Kumar Singh
Interface in java By Dheeraj Kumar Singh
dheeraj_cse
 
Java awt (abstract window toolkit)
Java awt (abstract window toolkit)Java awt (abstract window toolkit)
Java awt (abstract window toolkit)
Elizabeth alexander
 
Java &amp; advanced java
Java &amp; advanced javaJava &amp; advanced java
Java &amp; advanced java
BASAVARAJ HUNSHAL
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
Dhrumil Panchal
 

Viewers also liked (20)

27 applet programming
27  applet programming27  applet programming
27 applet programming
Ravindra Rathore
 
Java applets
Java appletsJava applets
Java applets
lopjuan
 
Applet and graphics programming
Applet and graphics programmingApplet and graphics programming
Applet and graphics programming
mcanotes
 
java graphics
java graphicsjava graphics
java graphics
nilaykarade1
 
Graphics programming in Java
Graphics programming in JavaGraphics programming in Java
Graphics programming in Java
Tushar B Kute
 
Java Applet
Java AppletJava Applet
Java Applet
Shree M.L.Kakadiya MCA mahila college, Amreli
 
6.applet programming in java
6.applet programming in java6.applet programming in java
6.applet programming in java
Deepak Sharma
 
Applet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java AppletsApplet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java Applets
amitksaha
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cycle
myrajendra
 
Java applets
Java appletsJava applets
Java applets
Srinath Dhayalamoorthy
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And Multithreading
Shraddha
 
java Unit4 chapter1 applets
java Unit4 chapter1 appletsjava Unit4 chapter1 applets
java Unit4 chapter1 applets
raksharao
 
Client Side Programming with Applet
Client Side Programming with AppletClient Side Programming with Applet
Client Side Programming with Applet
backdoor
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
Adil Mehmoood
 
Satish training ppt
Satish training pptSatish training ppt
Satish training ppt
satish lariya
 
JavaYDL13
JavaYDL13JavaYDL13
JavaYDL13
Terry Yoast
 
Basics of applets.53
Basics of applets.53Basics of applets.53
Basics of applets.53
myrajendra
 
Srgoc java
Srgoc javaSrgoc java
Srgoc java
Gaurav Singh
 
L5 classes, objects, nested and inner class
L5 classes, objects, nested and inner classL5 classes, objects, nested and inner class
L5 classes, objects, nested and inner class
teach4uin
 
exception handling
exception handlingexception handling
exception handling
Manav Dharman
 
Java applets
Java appletsJava applets
Java applets
lopjuan
 
Applet and graphics programming
Applet and graphics programmingApplet and graphics programming
Applet and graphics programming
mcanotes
 
Graphics programming in Java
Graphics programming in JavaGraphics programming in Java
Graphics programming in Java
Tushar B Kute
 
6.applet programming in java
6.applet programming in java6.applet programming in java
6.applet programming in java
Deepak Sharma
 
Applet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java AppletsApplet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java Applets
amitksaha
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cycle
myrajendra
 
Java And Multithreading
Java And MultithreadingJava And Multithreading
Java And Multithreading
Shraddha
 
java Unit4 chapter1 applets
java Unit4 chapter1 appletsjava Unit4 chapter1 applets
java Unit4 chapter1 applets
raksharao
 
Client Side Programming with Applet
Client Side Programming with AppletClient Side Programming with Applet
Client Side Programming with Applet
backdoor
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
Adil Mehmoood
 
Basics of applets.53
Basics of applets.53Basics of applets.53
Basics of applets.53
myrajendra
 
L5 classes, objects, nested and inner class
L5 classes, objects, nested and inner classL5 classes, objects, nested and inner class
L5 classes, objects, nested and inner class
teach4uin
 
Ad

Similar to Java Applet and Graphics (20)

The 2016 Android Developer Toolbox [MOBILIZATION]
The 2016 Android Developer Toolbox [MOBILIZATION]The 2016 Android Developer Toolbox [MOBILIZATION]
The 2016 Android Developer Toolbox [MOBILIZATION]
Nilhcem
 
A More Flash Like Web?
A More Flash Like Web?A More Flash Like Web?
A More Flash Like Web?
Murat Can ALPAY
 
2016 gunma.web games-and-asm.js
2016 gunma.web games-and-asm.js2016 gunma.web games-and-asm.js
2016 gunma.web games-and-asm.js
Noritada Shimizu
 
HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?
Ankara JUG
 
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NCAndroid Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC
Jim Tochterman
 
Introduction To Google Android (Ft Rohan Bomle)
Introduction To Google Android (Ft Rohan Bomle)Introduction To Google Android (Ft Rohan Bomle)
Introduction To Google Android (Ft Rohan Bomle)
Fafadia Tech
 
mobl
moblmobl
mobl
zefhemel
 
Basic of Applet
Basic of AppletBasic of Applet
Basic of Applet
suraj pandey
 
Google Web Toolkit
Google Web ToolkitGoogle Web Toolkit
Google Web Toolkit
Christos Stathis
 
Applet progming
Applet progmingApplet progming
Applet progming
VIKRANTHMALLIKARJUN
 
WebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open webWebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open web
pjcozzi
 
@Ionic native/google-maps
@Ionic native/google-maps@Ionic native/google-maps
@Ionic native/google-maps
Masashi Katsumata
 
Appletsbjhbjiibibibikbibibjibjbibbjb.ppt
Appletsbjhbjiibibibikbibibjibjbibbjb.pptAppletsbjhbjiibibibikbibibjibjbibbjb.ppt
Appletsbjhbjiibibibikbibibjibjbibbjb.ppt
Vijay Bhaskar Thatty
 
Applets(1)cusdhsiohisdhfshihfsihfohf.ppt
Applets(1)cusdhsiohisdhfshihfsihfohf.pptApplets(1)cusdhsiohisdhfshihfsihfohf.ppt
Applets(1)cusdhsiohisdhfshihfsihfohf.ppt
Vijay Bhaskar Thatty
 
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
 
Svcc 2013-d3
Svcc 2013-d3Svcc 2013-d3
Svcc 2013-d3
Oswald Campesato
 
SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)
Oswald Campesato
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cycle
V.V.Vanniapermal College for Women
 
MOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app developmentMOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app development
anistar sung
 
Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?
Patrick Chanezon
 
The 2016 Android Developer Toolbox [MOBILIZATION]
The 2016 Android Developer Toolbox [MOBILIZATION]The 2016 Android Developer Toolbox [MOBILIZATION]
The 2016 Android Developer Toolbox [MOBILIZATION]
Nilhcem
 
2016 gunma.web games-and-asm.js
2016 gunma.web games-and-asm.js2016 gunma.web games-and-asm.js
2016 gunma.web games-and-asm.js
Noritada Shimizu
 
HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?HTML5 - Daha Flash bir web?
HTML5 - Daha Flash bir web?
Ankara JUG
 
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NCAndroid Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC
Android Development w/ ArcGIS Server - Esri Dev Meetup - Charlotte, NC
Jim Tochterman
 
Introduction To Google Android (Ft Rohan Bomle)
Introduction To Google Android (Ft Rohan Bomle)Introduction To Google Android (Ft Rohan Bomle)
Introduction To Google Android (Ft Rohan Bomle)
Fafadia Tech
 
WebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open webWebGL: GPU acceleration for the open web
WebGL: GPU acceleration for the open web
pjcozzi
 
Appletsbjhbjiibibibikbibibjibjbibbjb.ppt
Appletsbjhbjiibibibikbibibjibjbibbjb.pptAppletsbjhbjiibibibikbibibjibjbibbjb.ppt
Appletsbjhbjiibibibikbibibjibjbibbjb.ppt
Vijay Bhaskar Thatty
 
Applets(1)cusdhsiohisdhfshihfsihfohf.ppt
Applets(1)cusdhsiohisdhfshihfsihfohf.pptApplets(1)cusdhsiohisdhfshihfsihfohf.ppt
Applets(1)cusdhsiohisdhfshihfsihfohf.ppt
Vijay Bhaskar Thatty
 
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
 
SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)SVCC 2013 D3.js Presentation (10/05/2013)
SVCC 2013 D3.js Presentation (10/05/2013)
Oswald Campesato
 
MOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app developmentMOPCON 2014 - Best software architecture in app development
MOPCON 2014 - Best software architecture in app development
anistar sung
 
Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?Google's HTML5 Work: what's next?
Google's HTML5 Work: what's next?
Patrick Chanezon
 
Ad

More from Abdul Rahman Sherzad (20)

Data is the Fuel of Organizations: Opportunities and Challenges in Afghanistan
Data is the Fuel of Organizations: Opportunities and Challenges in AfghanistanData is the Fuel of Organizations: Opportunities and Challenges in Afghanistan
Data is the Fuel of Organizations: Opportunities and Challenges in Afghanistan
Abdul Rahman Sherzad
 
PHP Unicode Input Validation Snippets
PHP Unicode Input Validation SnippetsPHP Unicode Input Validation Snippets
PHP Unicode Input Validation Snippets
Abdul Rahman Sherzad
 
Iterations and Recursions
Iterations and RecursionsIterations and Recursions
Iterations and Recursions
Abdul Rahman Sherzad
 
Sorting Alpha Numeric Data in MySQL
Sorting Alpha Numeric Data in MySQLSorting Alpha Numeric Data in MySQL
Sorting Alpha Numeric Data in MySQL
Abdul Rahman Sherzad
 
PHP Variable variables Examples
PHP Variable variables ExamplesPHP Variable variables Examples
PHP Variable variables Examples
Abdul Rahman Sherzad
 
Cross Join Example and Applications
Cross Join Example and ApplicationsCross Join Example and Applications
Cross Join Example and Applications
Abdul Rahman Sherzad
 
Applicability of Educational Data Mining in Afghanistan: Opportunities and Ch...
Applicability of Educational Data Mining in Afghanistan: Opportunities and Ch...Applicability of Educational Data Mining in Afghanistan: Opportunities and Ch...
Applicability of Educational Data Mining in Afghanistan: Opportunities and Ch...
Abdul Rahman Sherzad
 
Web Application Security and Awareness
Web Application Security and AwarenessWeb Application Security and Awareness
Web Application Security and Awareness
Abdul Rahman Sherzad
 
Database Automation with MySQL Triggers and Event Schedulers
Database Automation with MySQL Triggers and Event SchedulersDatabase Automation with MySQL Triggers and Event Schedulers
Database Automation with MySQL Triggers and Event Schedulers
Abdul Rahman Sherzad
 
Mobile Score Notification System
Mobile Score Notification SystemMobile Score Notification System
Mobile Score Notification System
Abdul Rahman Sherzad
 
Herat Innovation Lab 2015
Herat Innovation Lab 2015Herat Innovation Lab 2015
Herat Innovation Lab 2015
Abdul Rahman Sherzad
 
Evaluation of Existing Web Structure of Afghan Universities
Evaluation of Existing Web Structure of Afghan UniversitiesEvaluation of Existing Web Structure of Afghan Universities
Evaluation of Existing Web Structure of Afghan Universities
Abdul Rahman Sherzad
 
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
Abdul Rahman Sherzad
 
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
Abdul Rahman Sherzad
 
Everything about Database JOINS and Relationships
Everything about Database JOINS and RelationshipsEverything about Database JOINS and Relationships
Everything about Database JOINS and Relationships
Abdul Rahman Sherzad
 
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
 
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
Abdul Rahman Sherzad
 
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
Abdul Rahman Sherzad
 
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton ClassesJava Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Abdul Rahman Sherzad
 
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
 
Data is the Fuel of Organizations: Opportunities and Challenges in Afghanistan
Data is the Fuel of Organizations: Opportunities and Challenges in AfghanistanData is the Fuel of Organizations: Opportunities and Challenges in Afghanistan
Data is the Fuel of Organizations: Opportunities and Challenges in Afghanistan
Abdul Rahman Sherzad
 
PHP Unicode Input Validation Snippets
PHP Unicode Input Validation SnippetsPHP Unicode Input Validation Snippets
PHP Unicode Input Validation Snippets
Abdul Rahman Sherzad
 
Sorting Alpha Numeric Data in MySQL
Sorting Alpha Numeric Data in MySQLSorting Alpha Numeric Data in MySQL
Sorting Alpha Numeric Data in MySQL
Abdul Rahman Sherzad
 
Cross Join Example and Applications
Cross Join Example and ApplicationsCross Join Example and Applications
Cross Join Example and Applications
Abdul Rahman Sherzad
 
Applicability of Educational Data Mining in Afghanistan: Opportunities and Ch...
Applicability of Educational Data Mining in Afghanistan: Opportunities and Ch...Applicability of Educational Data Mining in Afghanistan: Opportunities and Ch...
Applicability of Educational Data Mining in Afghanistan: Opportunities and Ch...
Abdul Rahman Sherzad
 
Web Application Security and Awareness
Web Application Security and AwarenessWeb Application Security and Awareness
Web Application Security and Awareness
Abdul Rahman Sherzad
 
Database Automation with MySQL Triggers and Event Schedulers
Database Automation with MySQL Triggers and Event SchedulersDatabase Automation with MySQL Triggers and Event Schedulers
Database Automation with MySQL Triggers and Event Schedulers
Abdul Rahman Sherzad
 
Evaluation of Existing Web Structure of Afghan Universities
Evaluation of Existing Web Structure of Afghan UniversitiesEvaluation of Existing Web Structure of Afghan Universities
Evaluation of Existing Web Structure of Afghan Universities
Abdul Rahman Sherzad
 
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
Abdul Rahman Sherzad
 
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
Abdul Rahman Sherzad
 
Everything about Database JOINS and Relationships
Everything about Database JOINS and RelationshipsEverything about Database JOINS and Relationships
Everything about Database JOINS and Relationships
Abdul Rahman Sherzad
 
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
 
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
Abdul Rahman Sherzad
 
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
Abdul Rahman Sherzad
 
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton ClassesJava Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Java Virtual Keyboard Using Robot, Toolkit and JToggleButton Classes
Abdul Rahman Sherzad
 
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
 

Recently uploaded (20)

spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFAExercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
Lecture 4 INSECT CUTICLE and moulting.pptx
Lecture 4 INSECT CUTICLE and moulting.pptxLecture 4 INSECT CUTICLE and moulting.pptx
Lecture 4 INSECT CUTICLE and moulting.pptx
Arshad Shaikh
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdfRanking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Rafael Villas B
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18
Celine George
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
How to Add Customer Note in Odoo 18 POS - Odoo Slides
How to Add Customer Note in Odoo 18 POS - Odoo SlidesHow to Add Customer Note in Odoo 18 POS - Odoo Slides
How to Add Customer Note in Odoo 18 POS - Odoo Slides
Celine George
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
Dr. Nasir Mustafa
 
Junction Field Effect Transistors (JFET)
Junction Field Effect Transistors (JFET)Junction Field Effect Transistors (JFET)
Junction Field Effect Transistors (JFET)
GS Virdi
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFAExercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
Lecture 4 INSECT CUTICLE and moulting.pptx
Lecture 4 INSECT CUTICLE and moulting.pptxLecture 4 INSECT CUTICLE and moulting.pptx
Lecture 4 INSECT CUTICLE and moulting.pptx
Arshad Shaikh
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdfRanking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Rafael Villas B
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18
Celine George
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
How to Add Customer Note in Odoo 18 POS - Odoo Slides
How to Add Customer Note in Odoo 18 POS - Odoo SlidesHow to Add Customer Note in Odoo 18 POS - Odoo Slides
How to Add Customer Note in Odoo 18 POS - Odoo Slides
Celine George
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
Dr. Nasir Mustafa
 
Junction Field Effect Transistors (JFET)
Junction Field Effect Transistors (JFET)Junction Field Effect Transistors (JFET)
Junction Field Effect Transistors (JFET)
GS Virdi
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 

Java Applet and Graphics

  • 1. https://www.facebook.com/Oxus20 [email protected] Java Applet & Graphics Java Applet Java Graphics Analog Clock Prepared By: Khosrow Kian Edited By: Abdul Rahman Sherzad
  • 2. Table of Contents »Java Applet ˃Introduction and Concept ˃Demos »Graphics ˃Introduction and Concept »Java Applet Code 2 https://www.facebook.com/Oxus20
  • 3. Java Applet »An applet is a subclass of Panel ˃It is a container which can hold GUI components ˃It has a graphics context which can be used to draw images »An applet embedded within an HTML page ˃Applets are defined using the <applet> tag ˃Its size and location are defined within the tag »Java Virtual Machine is required for the browsers to execute the applet 3 https://www.facebook.com/Oxus20
  • 4. Java Applets vs. Applications »Applets - Java programs that can run over the Internet using a browser. ˃The browser either contains a JVM (Java Virtual Machine) or loads the Java plugin ˃Applets do not require a main(), but in general will have a paint(). ˃An Applet also requires an HTML file before it can be executed. ˃Java Applets are also compiled using the javac command, but are run either with a browser or with the applet viewer command. »Applications - Java programs that run directly on your machine. ˃Applications must have a main(). ˃Java applications are compiled using the javac command and run using the java command. 4 https://www.facebook.com/Oxus20
  • 5. Java Applets vs. Applications Feature Application Applet main() method Present Not present Execution Requires JRE Requires a browser like Chrome, Firefox, IE, Safari, Opera, etc. Nature Called as stand-alone application as application can be executed from command prompt Requires some third party tool help like a browser to execute Restrictions Can access any data or software available on the system cannot access any thing on the system except browser’s services Security Does not require any security Requires highest security for the system as they are untrusted 5 https://www.facebook.com/Oxus20
  • 6. Java Applet Advantages »Execution of applets is easy in a Web browser and does not require any installation or deployment procedure in real-time programming. »Writing and displaying (just opening in a browser) graphics and animations is easier than applications. »In GUI development, constructor, size of frame, window closing code etc. are not required. 6 https://www.facebook.com/Oxus20
  • 7. Java Applet Methods »init() ˃Called when applet is loaded onto user’s machine. »start() ˃Called when applet becomes visible (page called up). »stop() ˃Called when applet becomes hidden (page loses focus). »destroy() ˃Guaranteed to be called when browser shuts down. 7 https://www.facebook.com/Oxus20
  • 8. Introduction to Java Graphics »Java contains support for graphics that enable programmers to visually enhance applications »Java contains many more sophisticated drawing capabilities as part of the Java 2D API ˃Color ˃Font and FontMetrics ˃Graphics2D ˃Polygon ˃BasicStroke ˃GradientPaint and TexturePaint ˃Java 2D shape classes 8 https://www.facebook.com/Oxus20
  • 10. Java Coordinate System »Upper-Left Corner of a GUI component has the coordinates (0, 0) »X-Coordinate (horizontal coordinate) ˃horizontal distance moving right from the left of the screen »Y-Coordinate (vertical coordinate) ˃vertical distance moving down from the top of the screen »Coordinate units are measured in pixels. ˃A pixel is a display monitor’s smallest unit of resolution. https://www.facebook.com/Oxus20 10
  • 11. All Roads Lead to JComponent »Every Swing object inherits from JComponent » JComponent has a few methods that can be overridden in order to draw special things ˃public void paint(Graphics g) ˃public void paintComponent(Graphics g) ˃public void repaint() »So if we want custom drawing, we take any JComponent and extend it... ˃JPanel is a good choice 11 https://www.facebook.com/Oxus20
  • 12. Draw Line Example import java.awt.Graphics; import javax.swing.JApplet; public class DrawLine extends JApplet { @Override public void init() { } public void paint(Graphics g){ g.drawLine(20,20, 100,100); } } https://www.facebook.com/Oxus20 12
  • 13. Draw Rectangles Example import java.awt.Graphics; import javax.swing.JApplet; public class DrawRect extends JApplet { @Override public void init() { super.init(); } public void paint(Graphics g) { g.drawRect(20, 20, 100, 100); g.fillRect(130, 20, 100, 100); g.drawRoundRect(240, 20, 100, 100, 10, 10); } } https://www.facebook.com/Oxus20 13
  • 14. Draw Ovals Example import java.awt.Graphics; import javax.swing.JApplet; public class DrawOval extends JApplet { @Override public void init() { } public void paint(Graphics g) { g.drawOval(20, 20, 100, 100); g.fillOval(130, 20, 100, 100); } } https://www.facebook.com/Oxus20 14
  • 15. Simple Calculator Example import java.applet.Applet; import java.awt.BorderLayout; import java.awt.Button; import java.awt.Font; import java.awt.GridLayout; import java.awt.Panel; import java.awt.TextField; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class Calculator extends Applet implements ActionListener { String operators[] = { "+", "-", "*", "/", "=", "C" }; String operator = ""; int previousValue = 0; Button buttons[] = new Button[16]; TextField txtResult = new TextField(10); 15 https://www.facebook.com/Oxus20
  • 16. public void init() { setLayout(new BorderLayout()); add(txtResult, "North"); txtResult.setText("0"); Panel p = new Panel(); p.setLayout(new GridLayout(4, 4)); for (int i = 0; i < 16; i++) { if (i < 10) { buttons[i] = new Button(String.valueOf(i)); } else { buttons[i] = new Button(operators[i % 10]); } buttons[i].setFont(new Font("Verdana", Font.BOLD, 18)); p.add(buttons[i]); add(p, "Center"); buttons[i].addActionListener(this); } } 16 https://www.facebook.com/Oxus20
  • 17. public void actionPerformed(ActionEvent ae) { int result = 0; String caption = ae.getActionCommand(); int currentValue = Integer.parseInt(txtResult.getText()); if (caption.equals("C")) { txtResult.setText("0"); previousValue = 0; currentValue = 0; result = 0; operator = ""; } else if (caption.equals("=")) { result = 0; if (operator == "+") result = previousValue + currentValue; else if (operator == "-") result = previousValue - currentValue; else if (operator == "*") result = previousValue * currentValue; else if (operator == "/") result = previousValue / currentValue; txtResult.setText(String.valueOf(result)); } 17 https://www.facebook.com/Oxus20
  • 18. End - Simple Calculator Example else if (caption.equals("+") || caption.equals("-") || caption.equals("*") || caption.equals("/")) { previousValue = currentValue; operator = caption; txtResult.setText("0"); } else { int value = currentValue * 10 + Integer.parseInt(caption); txtResult.setText(String.valueOf(value)); } } } 18 https://www.facebook.com/Oxus20
  • 19. OUTPUT - Simple Calculator Example 19 https://www.facebook.com/Oxus20
  • 20. Example of Graphics and Applet 20 https://www.facebook.com/Oxus20
  • 21. Analog Clock Example 21 https://www.facebook.com/Oxus20 import java.applet.Applet; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.util.Calendar; public class AnalogClock extends Applet implements Runnable { private static final long serialVersionUID = 1L; private static final double TWO_PI = 2.0 * Math.PI; private Calendar nw = Calendar.getInstance(); int width = 200, hight = 200; int xcent = width / 2, ycent = hight / 2; int minhand, maxhand; double rdns; int dxmin, dymin, dxmax, dymax; double radins, sine, cosine; double fminutes; Thread t = null; Boolean stopFlag;
  • 22. 22 https://www.facebook.com/Oxus20 public void start() { t = new Thread(this); stopFlag = false; t.start(); } public void run() { for (;;) { try { updateTime(); repaint(); Thread.sleep(1000); if (stopFlag) break; } catch (InterruptedException e) { } } } public void stop() { stopFlag = true; t = null; } private void updateTime() { nw.setTimeInMillis(System.currentTimeMillis()); }
  • 23. 23 https://www.facebook.com/Oxus20 public void paint(Graphics g) { g.setFont(new Font("Gabriola", Font.BOLD + Font.ITALIC, 160)); g.setColor(Color.RED); g.drawString("XUS", 300, 270); g.setFont(new Font("Consolas", Font.BOLD + Font.ITALIC, 100)); g.setColor(Color.GREEN); g.drawString("20", 550, 270); g.setColor(Color.black); g.fillOval(100, 100, 200, 200); Graphics2D g1 = (Graphics2D) g; int hours = nw.get(Calendar.HOUR); int minutes = nw.get(Calendar.MINUTE); int seconds = nw.get(Calendar.SECOND); int millis = nw.get(Calendar.MILLISECOND); minhand = width / 8; maxhand = width / 2; rdns = (seconds + ((double) millis / 1000)) / 60.0; drw(g1, rdns, 0, maxhand - 20); g1.setColor(Color.BLUE); g1.drawString( String.format("%02d : %02d :%02d ", hours, minutes, seconds), minhand + 150, maxhand + 170);
  • 24. 24 https://www.facebook.com/Oxus20 minhand = 0; // Minute hand starts in middle. maxhand = width / 3; fminutes = (minutes + rdns) / 60.0; drw(g1, fminutes, 0, maxhand); minhand = 0; // Minute hand starts in middle. maxhand = width / 4; drw(g1, (hours + fminutes) / 12.0, 0, maxhand); g1.setColor(Color.gray); // set b ackground of circle g1.drawOval(100, 100, 200, 200); // draw a circle g1.setColor(Color.WHITE); g1.setFont(new Font("Consulas", Font.BOLD + Font.ITALIC, 15)); g1.drawString("12", 190, 120); g1.drawString("6", 195, 290); g1.drawString("3", 280, 200); g1.drawString("6", 110, 200); g1.setFont(new Font("Consulas", Font.BOLD + Font.ITALIC, 15)); g1.setStroke(new BasicStroke(2, BasicStroke.JOIN_MITER, BasicStroke.JOIN_BEVEL)); }
  • 25. End - Analog Clock Example public void drw(Graphics2D g, double prct, int minRadius, int maxRadius) { radins = (0.5 - prct) * TWO_PI; sine = Math.sin(radins); cosine = Math.cos(radins); dxmin = xcent + (int) (minRadius * sine); dymin = ycent + (int) (minRadius * cosine); dxmax = xcent + (int) (maxRadius * sine); dymax = ycent + (int) (maxRadius * cosine); g.setColor(Color.WHITE); g.setBackground(Color.cyan); g.setFont(new Font("Consulas", Font.BOLD + Font.ITALIC, 12)); g.drawLine(dxmin + 100, dymin + 100, dxmax + 100, dymax + 100); } } 25 https://www.facebook.com/Oxus20
  • 26. OUTPUT - Analog Clock Example 26 https://www.facebook.com/Oxus20