SlideShare a Scribd company logo
Class Applet
• applications live and run inside the Web
browser’s window.
• How to run JavaApplet
– Create File: A.java
– Compile: A.java=> A.class
– Create and Open A.html
• there are two varieties of applets:
– applets use the Abstract Window Toolkit (AWT)
– Swing class Japplet
A.Java
import java.applet.*;
import java.awt.*;
public class A extends Applet{
private int w, h;
public void init( )
{
w = 45;
h = 50;
}
public void paint(Graphics g){
g.drawRect(w, h, 20, 80);
}
}
A.html
<html>
<applet code="A.class" height=200 width=320>
</applet>
</html>
public class JappletTest1 extends Applet
{
// Called first.
public void init() {
// initialization
}
/* Called second, after init(). Also called whenever the applet is restarted. */
public void start() {
// start or resume execution
}
// Called when the applet is stopped.
public void stop() {
// suspends execution
}
/* Called when applet is terminated. This is the last method executed. */
public void destroy() {
// perform shutdown activities
}
// Called when an applet's window must be restored.
public void paint(Graphics g) {
// redisplay contents of window
}
}
import java.awt.*;
import java.applet.*;
public class Japplet1 extends Applet{
String msg;
public void init() {
setBackground(Color.cyan);
setForeground(Color.red);
msg = "Inside init( ) --";
}
public void start(){
msg += " Inside start( ) --";
}
public void paint(Graphics g) {
msg += " Inside paint( ).";
g.drawString(msg, 10, 30);
}
}
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class AppletFrame extends Applet implements ActionListener {
String msg = "";
Button yes, no, maybe;
public void init() {
yes = new Button("Yes");
no = new Button("No");
maybe = new Button("Undecided");
add(yes);
add(no);
add(maybe);
yes.addActionListener(this);
no.addActionListener(this);
maybe.addActionListener(this);
}
public void actionPerformed(ActionEvent ae) {
String str = ae.getActionCommand();
if(str.equals("Yes")) {
msg = "You pressed Yes.";
}
else if(str.equals("No")) {
msg = "You pressed No.";
}
else {
msg = "You pressed Undecided.";
}
repaint();
}
public void paint(Graphics g) {
g.drawString(msg, 6, 100);
}
}
<html>
<applet code = "Applet1.class" width = "300" height = "45"></applet>
</html>
Chapter vi(class applet)
Chapter vi(class applet)
Chapter vi(class applet)

More Related Content

Viewers also liked (16)

PPTX
Schede informati per informare sett2011
Acidflame
 
PDF
Mi aplicación web
nelsonmelo06
 
PDF
Triptico evelyn cisternas
Evelyn Cisternas
 
PDF
Cm fnum 247 la sociedad andaluza valora en el parlamento el decreto de la vi~
Lidia Milena
 
PDF
Berenice Camacho Portfolio (Lr)
Berenice Camacho
 
PPTX
RBC Shield: The Dangers, The Patent, The Markets
RBC Shield, LLC
 
PPTX
Ef core
patyura
 
PDF
Paul Bocuse Institute Certificate
Mohamed Youssef
 
PDF
Bhakti vedanta darshana JUNE 2016
ISKCON Bangalore
 
PDF
C users antinerodocumentstmra_2008_dblp_2.txt
just some testing
 
DOCX
10 15 lesson-02
ISKCON Chowpatty
 
PDF
Reporte final - Unreasonable Labs Colomba 2016
Tanita Preston Bertie
 
PDF
Tabla frecuencias3
tortolas
 
PDF
Tiramisú
tartasypostres
 
PDF
La calle fuente de imagenes
Jan Puerta
 
PPTX
8. chapter viii
Chhom Karath
 
Schede informati per informare sett2011
Acidflame
 
Mi aplicación web
nelsonmelo06
 
Triptico evelyn cisternas
Evelyn Cisternas
 
Cm fnum 247 la sociedad andaluza valora en el parlamento el decreto de la vi~
Lidia Milena
 
Berenice Camacho Portfolio (Lr)
Berenice Camacho
 
RBC Shield: The Dangers, The Patent, The Markets
RBC Shield, LLC
 
Ef core
patyura
 
Paul Bocuse Institute Certificate
Mohamed Youssef
 
Bhakti vedanta darshana JUNE 2016
ISKCON Bangalore
 
C users antinerodocumentstmra_2008_dblp_2.txt
just some testing
 
10 15 lesson-02
ISKCON Chowpatty
 
Reporte final - Unreasonable Labs Colomba 2016
Tanita Preston Bertie
 
Tabla frecuencias3
tortolas
 
Tiramisú
tartasypostres
 
La calle fuente de imagenes
Jan Puerta
 
8. chapter viii
Chhom Karath
 

Similar to Chapter vi(class applet) (20)

PDF
27 applet programming
Ravindra Rathore
 
PPTX
Applet.pptx
LakachewYezihalem
 
PPT
Advanced Programming, Java Programming, Applets.ppt
miki304759
 
PPTX
oops with java modules iii & iv.pptx
rani marri
 
PPT
Slide8appletv2 091028110313-phpapp01
Abhishek Khune
 
PPT
java applets
Waheed Warraich
 
PPTX
3. applets
AnusAhmad
 
PPT
JAVA APPLET BASICS
Shanid Malayil
 
PPT
Jsp applet
Sanoj Kumar
 
PDF
Java applet basics
Sunil Pandey
 
PPTX
MSBTE Computer Engineering Java applet.pptx
kunalgaikwad1705
 
PPT
Java: Java Applets
Tareq Hasan
 
PPTX
Applets in Java. Learn java program with applets
halaplay385
 
PPTX
Introduction To Applets methods and simple examples
MsPariyalNituLaxman
 
PPTX
Applets
Nuha Noor
 
PPTX
Java applet
GaneshKumarKanthiah
 
PPTX
Java Applets
Danial Mirza
 
PPTX
Applet1 (1).pptx
FahanaAbdulVahab
 
PPTX
applet.pptx
SachinBhosale73
 
PPTX
Java applets
Pihu Goel
 
27 applet programming
Ravindra Rathore
 
Applet.pptx
LakachewYezihalem
 
Advanced Programming, Java Programming, Applets.ppt
miki304759
 
oops with java modules iii & iv.pptx
rani marri
 
Slide8appletv2 091028110313-phpapp01
Abhishek Khune
 
java applets
Waheed Warraich
 
3. applets
AnusAhmad
 
JAVA APPLET BASICS
Shanid Malayil
 
Jsp applet
Sanoj Kumar
 
Java applet basics
Sunil Pandey
 
MSBTE Computer Engineering Java applet.pptx
kunalgaikwad1705
 
Java: Java Applets
Tareq Hasan
 
Applets in Java. Learn java program with applets
halaplay385
 
Introduction To Applets methods and simple examples
MsPariyalNituLaxman
 
Applets
Nuha Noor
 
Java applet
GaneshKumarKanthiah
 
Java Applets
Danial Mirza
 
Applet1 (1).pptx
FahanaAbdulVahab
 
applet.pptx
SachinBhosale73
 
Java applets
Pihu Goel
 
Ad

More from Chhom Karath (20)

PDF
set1.pdf
Chhom Karath
 
PPTX
Set1.pptx
Chhom Karath
 
PDF
orthodontic patient education.pdf
Chhom Karath
 
PDF
New ton 3.pdf
Chhom Karath
 
PPTX
ច្បាប់ញូតុនទី៣.pptx
Chhom Karath
 
PPTX
Control tipping.pptx
Chhom Karath
 
PPTX
Bulbous loop.pptx
Chhom Karath
 
PPTX
brush teeth.pptx
Chhom Karath
 
PPTX
bracket size.pptx
Chhom Karath
 
PPTX
arch form KORI copy.pptx
Chhom Karath
 
PPTX
Bracket size
Chhom Karath
 
PPTX
Couple
Chhom Karath
 
PPTX
ច្បាប់ញូតុនទី៣
Chhom Karath
 
PPTX
Game1
Chhom Karath
 
PPTX
Shoe horn loop
Chhom Karath
 
PPTX
Opus loop
Chhom Karath
 
PPTX
V bend
Chhom Karath
 
PPTX
Closing loop
Chhom Karath
 
PPTX
Maxillary arch form
Chhom Karath
 
PPTX
Front face analysis
Chhom Karath
 
set1.pdf
Chhom Karath
 
Set1.pptx
Chhom Karath
 
orthodontic patient education.pdf
Chhom Karath
 
New ton 3.pdf
Chhom Karath
 
ច្បាប់ញូតុនទី៣.pptx
Chhom Karath
 
Control tipping.pptx
Chhom Karath
 
Bulbous loop.pptx
Chhom Karath
 
brush teeth.pptx
Chhom Karath
 
bracket size.pptx
Chhom Karath
 
arch form KORI copy.pptx
Chhom Karath
 
Bracket size
Chhom Karath
 
Couple
Chhom Karath
 
ច្បាប់ញូតុនទី៣
Chhom Karath
 
Shoe horn loop
Chhom Karath
 
Opus loop
Chhom Karath
 
V bend
Chhom Karath
 
Closing loop
Chhom Karath
 
Maxillary arch form
Chhom Karath
 
Front face analysis
Chhom Karath
 
Ad

Recently uploaded (20)

PPTX
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
PPTX
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
PPT
DRUGS USED IN THERAPY OF SHOCK, Shock Therapy, Treatment or management of shock
Rajshri Ghogare
 
PPTX
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PPTX
Unlock the Power of Cursor AI: MuleSoft Integrations
Veera Pallapu
 
PPTX
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
PPTX
YSPH VMOC Special Report - Measles Outbreak Southwest US 7-20-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
PPTX
Virus sequence retrieval from NCBI database
yamunaK13
 
PPTX
Rules and Regulations of Madhya Pradesh Library Part-I
SantoshKumarKori2
 
PPTX
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
PPTX
I INCLUDED THIS TOPIC IS INTELLIGENCE DEFINITION, MEANING, INDIVIDUAL DIFFERE...
parmarjuli1412
 
PPTX
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
PPTX
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
PDF
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
PDF
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
PPTX
Electrophysiology_of_Heart. Electrophysiology studies in Cardiovascular syste...
Rajshri Ghogare
 
PDF
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
PDF
My Thoughts On Q&A- A Novel By Vikas Swarup
Niharika
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
DRUGS USED IN THERAPY OF SHOCK, Shock Therapy, Treatment or management of shock
Rajshri Ghogare
 
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
Unlock the Power of Cursor AI: MuleSoft Integrations
Veera Pallapu
 
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 7-20-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Virus sequence retrieval from NCBI database
yamunaK13
 
Rules and Regulations of Madhya Pradesh Library Part-I
SantoshKumarKori2
 
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
I INCLUDED THIS TOPIC IS INTELLIGENCE DEFINITION, MEANING, INDIVIDUAL DIFFERE...
parmarjuli1412
 
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
BÀI TẬP TEST BỔ TRỢ THEO TỪNG CHỦ ĐỀ CỦA TỪNG UNIT KÈM BÀI TẬP NGHE - TIẾNG A...
Nguyen Thanh Tu Collection
 
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
Electrophysiology_of_Heart. Electrophysiology studies in Cardiovascular syste...
Rajshri Ghogare
 
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
My Thoughts On Q&A- A Novel By Vikas Swarup
Niharika
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 

Chapter vi(class applet)

  • 2. • applications live and run inside the Web browser’s window. • How to run JavaApplet – Create File: A.java – Compile: A.java=> A.class – Create and Open A.html • there are two varieties of applets: – applets use the Abstract Window Toolkit (AWT) – Swing class Japplet
  • 3. A.Java import java.applet.*; import java.awt.*; public class A extends Applet{ private int w, h; public void init( ) { w = 45; h = 50; } public void paint(Graphics g){ g.drawRect(w, h, 20, 80); } } A.html <html> <applet code="A.class" height=200 width=320> </applet> </html>
  • 4. public class JappletTest1 extends Applet { // Called first. public void init() { // initialization } /* Called second, after init(). Also called whenever the applet is restarted. */ public void start() { // start or resume execution } // Called when the applet is stopped. public void stop() { // suspends execution } /* Called when applet is terminated. This is the last method executed. */ public void destroy() { // perform shutdown activities } // Called when an applet's window must be restored. public void paint(Graphics g) { // redisplay contents of window } }
  • 5. import java.awt.*; import java.applet.*; public class Japplet1 extends Applet{ String msg; public void init() { setBackground(Color.cyan); setForeground(Color.red); msg = "Inside init( ) --"; } public void start(){ msg += " Inside start( ) --"; } public void paint(Graphics g) { msg += " Inside paint( )."; g.drawString(msg, 10, 30); } }
  • 6. import java.awt.*; import java.awt.event.*; import java.applet.*; public class AppletFrame extends Applet implements ActionListener { String msg = ""; Button yes, no, maybe; public void init() { yes = new Button("Yes"); no = new Button("No"); maybe = new Button("Undecided"); add(yes); add(no); add(maybe); yes.addActionListener(this); no.addActionListener(this); maybe.addActionListener(this); } public void actionPerformed(ActionEvent ae) { String str = ae.getActionCommand(); if(str.equals("Yes")) { msg = "You pressed Yes."; } else if(str.equals("No")) { msg = "You pressed No."; } else { msg = "You pressed Undecided."; } repaint(); } public void paint(Graphics g) { g.drawString(msg, 6, 100); } }
  • 7. <html> <applet code = "Applet1.class" width = "300" height = "45"></applet> </html>

Editor's Notes

  • #8: import java.awt.Graphics; // program uses class Graphics import javax.swing.JApplet; // program uses class JApplet public class Applet1 extends JApplet { // draw text on applet's background public void paint( Graphics g ) { // call superclass version of method paint super.paint( g ); // draw a String at x-coordinate 25 and y-coordinate 25 g.drawString( "Welcome to Computer Backanot!", 25, 25 ); } // end method paint } // end class WelcomeApplet
  • #9: import java.awt.Graphics; // program uses class Graphics import javax.swing.JApplet; // program uses class JApplet import javax.swing.JOptionPane; // program uses class JOptionPane public class Applet1 extends JApplet { private double sum; // sum of values entered by user // initialize applet by obtaining values from user public void init () { String firstNumber; // first string entered by user String secondNumber; // second string entered by user double number1; // first number to add double number2; // second number to add // obtain first number from user firstNumber = JOptionPane.showInputDialog("Enter first floating-point value" ); // obtain second number from user secondNumber = JOptionPane.showInputDialog( "Enter second floating-point value" ); // convert numbers from type String to type double number1 = Double.parseDouble( firstNumber ); number2 = Double.parseDouble( secondNumber ); sum = number1 + number2; // add numbers } // end method init // draw results in a rectangle on applet's background public void paint( Graphics g ) { super.paint( g ); // call superclass version of method paint // draw rectangle starting from (15, 10) that is 270 // pixels wide and 20 pixels tall g.drawRect( 15, 10, 270, 20 ); // draw results as a String at (25, 25) g.drawString( "The sum is " + sum, 25, 25 ); } // end method paint } // end class AdditionApplet
  • #10: import javax.swing.JApplet; // program uses class JApplet import java.awt.*; import java.awt.event.*; public class Applet1 extends JApplet { Button btSum,btMin,btDiv,btMult; TextField tfVal1,tfVal2,tfResult; public void init () { Frame frm = new Frame("Calculation"); Panel P1=new Panel(); P1.setLayout(new GridLayout(3,2)); P1.add(new Label("Value 1:"));P1.add(tfVal1=new TextField(20)); P1.add(new Label("Value 2:"));P1.add(tfVal2=new TextField(20)); P1.add(new Label("Result:"));P1.add(tfResult=new TextField(20)); Panel P2=new Panel(); P2.add(btSum=new Button(" + "));P2.add(btMin=new Button(" - ")); P2.add(btDiv=new Button(" / "));P2.add(btMult=new Button(" * ")); Button btEx; P2.add(btEx=new Button("Exit")); Panel P=new Panel(); P.setLayout(new BorderLayout()); P.add(new Label(" Arithmatics Operation"),BorderLayout.NORTH); P.add(P1,BorderLayout.CENTER); P.add(P2,BorderLayout.SOUTH); frm.setSize(200,100); add(P); btSum.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e) { tfResult.setText((Float.parseFloat(tfVal1.getText())+Float.parseFloat(tfVal2.getText()))+ ""); } }); btMult.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e) { tfResult.setText((Float.parseFloat(tfVal1.getText())*Float.parseFloat(tfVal2.getText()))+ ""); } }); btDiv.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e) { tfResult.setText((Float.parseFloat(tfVal1.getText())/Float.parseFloat(tfVal2.getText()))+ ""); } }); btMin.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e) { tfResult.setText((Float.parseFloat(tfVal1.getText())-Float.parseFloat(tfVal2.getText()))+ ""); } }); btEx.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e) { System.exit(0); } }); } // end method init } // end class AdditionApplet
  • #11: import javax.swing.*; import javax.swing.JOptionPane; // program uses class JOptionPane import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class Applet1 extends JApplet { JTextField jTfEn,jTfKh; JButton jBapply,jBexit,jBclear; public void init () { setSize(300, 200); JPanel jp1=new JPanel(); jp1.setLayout(new GridLayout(3,3)); JLabel jlEn=new JLabel("Enlish:");jp1.add(jlEn);jTfEn=new JTextField(20);jp1.add(jTfEn); Font font = new Font("Limon S1", Font.PLAIN, 30); JLabel jlKh=new JLabel("Khmer:");jp1.add(jlKh);jTfKh=new JTextField(20);jp1.add(jTfKh); jTfKh.setFont(font); JPanel jp2=new JPanel(); jp2.setLayout(new FlowLayout()); jBapply=new JButton("Apply");jp2.add(jBapply);jBexit=new JButton("Exit");jp2.add(jBexit); jBclear=new JButton("Clear");jp2.add(jBclear); JPanel jp=new JPanel(); jp.setLayout(new BorderLayout()); jp.add(jp1,BorderLayout.NORTH); jp.add(jp2,BorderLayout.CENTER); jBapply.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { if(jTfEn.getText().equals("")) { JOptionPane.showMessageDialog(null,"Please, Enter English word bat!"); } else jTfKh.setText(jTfEn.getText()); } }); jBexit.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { System.exit(0); } }); jBclear.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { jTfKh.setText(""); jTfEn.setText(""); } }); add(jp); } // end method init } // end class AdditionApplet