import javax.swing.*;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.Robot;
import java.awt.event.InputEvent;
import java.awt.AWTException;
public class Turing_drawing extends Applet implements MouseListener, MouseMotionListener
{
int maxx=getSize().width;
int maxy=getSize().height;
int mx = maxx/2;
int my = maxy/2;
boolean isButtonPressed = false;
public void init()
{
addMouseListener(this);
addMouseMotionListener(this);
}
public void paint(Graphics g)
{
//Check turing_drawing.txt for help
for(int xx=0;xx<1000;xx++)
{
drawfilloval(g,mx,my,10,10,Color.black);
drawtext(g,"Your mouse co-ordinates are ( "+mx+" , "+my+" )",10,10);
cls(g);
}
}
public void drawoval(Graphics g,int x,int y,int x2,int y2,Color clr)
{
g.setColor(clr);
g.drawOval(x-x2,y-y2,2*x2,2*y2);
}
public void drawfilloval(Graphics g,int x,int y,int x2,int y2,Color clr)
{
g.setColor(clr);
g.fillOval(x-x2,y-y2,2*x2,2*y2);
}
public void drawbox(Graphics g,int x,int y,int x2,int y2,Color clr)
{
g.setColor(clr);
g.drawRect(x,y,x2,y2);
}
public void drawfillbox(Graphics g,int x,int y,int x2,int y2,Color clr)
{
g.setColor(clr);
g.fillRect(x,y,x2,y2);
}
public void drawarc(Graphics g,int x,int y,int x2,int y2,int rad1,int rad2,Color clr)
{
g.setColor(clr);
g.drawArc(x-x2,y-y2,2*x2,2*y2,rad1,rad2);
}
public void drawfillarc(Graphics g,int x,int y,int x2,int y2,int rad1,int rad2,Color clr)
{
g.setColor(clr);
g.fillArc(x-x2,y-y2,2*x2,2*y2,rad1,rad2);
}
public void drawline(Graphics g,int x,int y,int x2,int y2,Color clr)
{
g.setColor(clr);
g.drawLine(x,y,x2,y2);
}
public void drawdot(Graphics g,int x,int y,Color clr)
{
g.setColor(clr);
g.drawLine(x,y,x,y);
}
public void delay(int x)
{
try
{
Thread.sleep(x);
}
catch(InterruptedException e)
{
}
}
public void cls(Graphics g)
{
repaint();
}
public void drawtext (Graphics g,String text,int x,int y)
{
g.drawString(text,x,y);
}
public void MouseWhere(MouseEvent e)
{
}
public void mouseEntered( MouseEvent e ) {
// called when the pointer enters the applet's rectangular area
}
public void mouseExited( MouseEvent e ) {
// called when the pointer leaves the applet's rectangular area
}
public void mouseClicked( MouseEvent e ) {
// called after a press and release of a mouse button
// with no motion in between
// (If the user presses, drags, and then releases, there will be
// no click event generated.)
}
public void mousePressed( MouseEvent e ) { // called after a button is pressed down
isButtonPressed = true;
e.consume();
}
public void mouseReleased( MouseEvent e ) { // called after a button is released
isButtonPressed = false;
}
public void mouseMoved( MouseEvent e ) { // called during motion when no buttons are down
mx = e.getX();
my = e.getY();
e.consume();
}
public void mouseDragged( MouseEvent e ) { // called during motion with buttons down
mx = e.getX();
my = e.getY();
e.consume();
}
public void RobotMouse(int x,int y,int btn)
{
try
{
Robot robot = new Robot(); // Create a new robot
robot.mouseMove(x,y); // Move the mouse
if (btn==1)
{
robot.mousePress(InputEvent.BUTTON1_MASK); // Press mouse button
robot.mouseRelease(InputEvent.BUTTON1_MASK); // Release mouse button
}
robot.delay(60000); // 1 minute = 60000 ms
}
catch (AWTException e)
{
e.printStackTrace();
}
}
}
|