import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class sticky_oval extends Applet implements MouseMotionListener {
int x,y;
public void init() {
addMouseMotionListener(this);
}
public void mouseMoved(MouseEvent me) {
x=me.getX();
y=me.getY();
repaint();
}
public void mouseDragged(MouseEvent me) {
}
public void paint(Graphics g) {
try {
g.drawOval(x,y,x,y);
if(x==y) {
g.setColor(Color.blue);
g.fillOval(x,y,x,y);
showStatus("THIS IS PERFECT CIRCLE.");
Thread.sleep(4000);
} else showStatus("");
} catch(InterruptedException e) {
}
}
}
Showing posts with label run. Show all posts
Showing posts with label run. Show all posts
Thursday, 22 March 2012
Sticky Oval in JAVA
Saturday, 25 February 2012
Moving Circle in JAVA
An applet program to move circle in JAVA
import java.applet.*;
import java.awt.*;
/*
<applet code="moving_circle" width=300 height=100>
</applet>
*/
public class moving_circle extends Applet implements Runnable
{
int x=0;
Thread t;
Image buffer;
Graphics bufferg;
public void init()
{
t=new Thread(this);
t.start();
Dimension d=getSize();
buffer=createImage(d.width,d.height);
}
public void run()
{
try
{
while(true)
{
repaint();
Thread.sleep(500);
}
}
catch(Exception e)
{
}
}
public void update(Graphics g)
{
paint(g);
}
public void paint(Graphics g)
{
if(bufferg==null)
bufferg=buffer.getGraphics();
Dimension d=getSize();
bufferg.setColor(Color.black);
bufferg.fillRect(0,0,d.width,d.height);
bufferg.setColor(Color.white);
bufferg.fillOval(x,d.height/4,50,50);
g.drawImage(buffer,0,0,this);
x+=5;
if(x+50>d.width)
x=0;
}
}
import java.applet.*;
import java.awt.*;
/*
<applet code="moving_circle" width=300 height=100>
</applet>
*/
public class moving_circle extends Applet implements Runnable
{
int x=0;
Thread t;
Image buffer;
Graphics bufferg;
public void init()
{
t=new Thread(this);
t.start();
Dimension d=getSize();
buffer=createImage(d.width,d.height);
}
public void run()
{
try
{
while(true)
{
repaint();
Thread.sleep(500);
}
}
catch(Exception e)
{
}
}
public void update(Graphics g)
{
paint(g);
}
public void paint(Graphics g)
{
if(bufferg==null)
bufferg=buffer.getGraphics();
Dimension d=getSize();
bufferg.setColor(Color.black);
bufferg.fillRect(0,0,d.width,d.height);
bufferg.setColor(Color.white);
bufferg.fillOval(x,d.height/4,50,50);
g.drawImage(buffer,0,0,this);
x+=5;
if(x+50>d.width)
x=0;
}
}
Subscribe to:
Posts (Atom)