Sep

18

//Applet with Arc

import java.applet.*;
import java.awt.*;
/*
<Applet code=”Ap6.class” width=”400″ height=”400″></applet>
*/
public class Ap6 extends Applet{
public void init(){
setBackground(Color.red);
setForeground(Color.yellow);
}
public void paint(Graphics g){
g.fillArc(130,110,140,140,0,-180);
}
}

//Applet with Animation-1

import java.applet.*;
import java.awt.*;
/*
<Applet code=”Ap7.class” width=”400″ height=”400″></applet>
*/
public class Ap7 extends Applet{
public void init(){
setBackground(Color.red);
setForeground(Color.yellow);
}
public void paint(Graphics g){
for(int i=0;i<=310;i+=10){
repaint();
g.fillOval(i,20,90,90);
try{
Thread.sleep(1000);
}catch(InterruptedException e){
}
}
}
}

//Applet with Animation-2

import java.applet.*;
import java.awt.*;
/*
<Applet code=”Ap8.class” width=”400″ height=”400″></applet>
*/
public class Ap8 extends Applet{
public void init(){
setBackground(Color.red);
setForeground(Color.yellow);
}
int x=0;
int y=20;
public void paint(Graphics g){
if(x<=310){
x=x+5;
}else{
y=y+5;
}
g.fillOval(x,y,90,90);
try{
Thread.sleep(100);
}catch(InterruptedException e){
}
repaint();
}
}

//Applet with Mouse Event-1

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*
<Applet code=”Ap9.class” width=”400″ height=”400″></applet>
*/
public class Ap9 extends Applet implements MouseListener{
public void init(){
addMouseListener(this);
}
public void mouseExited(MouseEvent e){
System.out.println(“mouseExited”);
}
public void mouseEntered(MouseEvent e){
System.out.println(“mouseEntered”);
}
public void mouseReleased(MouseEvent e){
System.out.println(“mouseReleased”);
}
public void mousePressed(MouseEvent e){
System.out.println(“mousePressed”);
}
public void mouseClicked(MouseEvent e){
System.out.println(“mouseClicked”);
}
public void paint(Graphics g){
}
}

//Applet with Mouse Event-2

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/*
<Applet code=”Ap10.class” width=”400″ height=”400″></applet>
*/
public class Ap10 extends Applet implements MouseListener{
public void init(){
addMouseListener(this);
}
public void mouseExited(MouseEvent e){
}
public void mouseEntered(MouseEvent e){
}
public void mouseReleased(MouseEvent e){
}
int x,y;
public void mousePressed(MouseEvent e){
x=e.getX();
y=e.getY();
showStatus(x+”,”+y);
repaint();
}
public void mouseClicked(MouseEvent e){
}
public void paint(Graphics g){
g.drawString(x+” , “+y,x,y);
}
}


Leave a Reply