Cameron Mitchell

Greenhorn
+ Follow
since Apr 09, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Cameron Mitchell

Hiya,
I am trying to add a click counter to this code so that each time a disk is moved the number of moves is displayed on the screen. It is only one counter for all the disks, and if possible I'd like to display the number of clicks on screen.
I think that it is something like
saySomething("Mouse released; # of clicks: " + e.getClickCount(), e);
but cant get it to work.
Thanks for your help in advance.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Geese extends Applet implements MouseListener,
MouseMotionListener {
private Point goose1, goose2, goose3, fox4, fox5, fox6, mouse;
private int select;
// declare two instance variables at the head of the program
private Image dbImage;
private Graphics dbg;
public void init(){
this.addMouseMotionListener(this);
this.addMouseListener(this);
select = 0;
goose1 = new Point (11,11);
goose2 = new Point (141,11);
goose3 = new Point (271,11);
fox4 = new Point (11,156);
fox5 = new Point (141,156);
fox6 = new Point (272,156);
mouse = new Point();
}

public void paint( Graphics g ){

g.setColor (Color.red);
g.fillOval(goose1.x, goose1.y, 30,30);
g.fillOval(goose2.x, goose2.y, 30,30);
g.fillOval(goose3.x, goose3.y, 30,30);
g.setColor (Color.yellow);
g.fillOval(fox4.x, fox4.y, 30,30);
g.fillOval(fox5.x, fox5.y, 30,30);
g.fillOval(fox6.x, fox6.y, 30,30);
}

public void mouseDragged(MouseEvent e){
mouse = e.getPoint();
if (select==1) goose1 = mouse;
if (select==2) goose2 = mouse;
if (select==3) goose3 = mouse;
if (select==4) fox4 = mouse;
if (select==5) fox5 = mouse;
if (select==6) fox6 = mouse;
repaint();
}

public void mouseMoved (MouseEvent e){}

//select a counter using the mouse
public void mousePressed (MouseEvent e){
mouse = e.getPoint();
if (mouse.x > goose1.x && mouse.x < goose1.x + 30 &&
mouse.y > goose1.y && mouse.y < goose1.y + 30) select = 1;
if (mouse.x > goose2.x && mouse.x < goose2.x + 30 &&
mouse.y > goose2.y && mouse.y < goose2.y + 30) select = 2;
if (mouse.x > goose3.x && mouse.x < goose3.x + 30 &&
mouse.y > goose3.y && mouse.y < goose3.y + 30) select = 3;
if (mouse.x > fox4.x && mouse.x < fox4.x + 30 &&
mouse.y > fox4.y && mouse.y < fox4.y + 30) select = 4;
if (mouse.x > fox5.x && mouse.x < fox5.x + 30 &&
mouse.y > fox5.y && mouse.y < fox5.y + 30) select = 5;
if (mouse.x > fox6.x && mouse.x < fox6.x + 30 &&
mouse.y > fox6.y && mouse.y < fox6.y + 30) select = 6;
}
public void mouseReleased(MouseEvent e){

}
// required for the interface
public void mouseClicked(MouseEvent event){}
public void mouseEntered(MouseEvent event){}
public void mouseExited(MouseEvent event){}

//** Update - Method, implements double buffering */
public void update (Graphics g)
{
// initialize buffer
if (dbImage == null)
{
dbImage = createImage (this.getSize().width, this.getSize().height);
dbg = dbImage.getGraphics ();
}
// clear screen in background
dbg.setColor (getBackground ());
dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);
// draw elements in background
dbg.setColor (getForeground());
paint (dbg);
// draw image on the screen
g.drawImage (dbImage, 0, 0, this);
}
}
19 years ago
I'm trying to write some code that will allow me to move a counter on a chessboard. Got the board and counter, but the counter won't move. Thanks in advance for any help.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class Romeo extends Applet implements MouseListener,
MouseMotionListener {

private Point snail1, mouse;
private int select;
public void init() {
this.addMouseMotionListener(this);
this.addMouseListener(this);
select = 0;
snail1 = new Point (25,25);
mouse = new Point();
}

public void paint(Graphics g)
{
drawRect(g);
g.setColor (Color.red);
g.fillOval (snail1.x, snail1.y, 30,30);
}
public void mouseDragged(MouseEvent e) {
mouse = e.getPoint();
// continuously change the coordinates of the selected counter
if (select == 1) snail1 = mouse;
repaint();
}
public void mousePressed(MouseEvent e) {
//select a counter using the mouse
mouse = e.getPoint();
if (mouse.x > snail1.x - 5 && mouse.x < snail1.x + 5 &&
mouse.y > snail1.y - 5 && mouse.y < snail1.y + 5) select = 1;
}

// required for the interface
public void mouseClicked(MouseEvent event){}
public void mouseReleased(MouseEvent event){}
public void mouseEntered(MouseEvent event){}
public void mouseExited(MouseEvent event){}
public void mouseMoved(MouseEvent event){}

public void drawRect(Graphics g) {
g.setColor (Color.black);
g.fillRect (0,0,50,50);
g.drawRect (50,0,50,50);
g.fillRect (100,0,50,50);
g.drawRect (150,0,50,50);
g.fillRect (200,0,50,50);
g.drawRect (250,0,50,50);
g.fillRect (300,0,50,50);
g.drawRect (350,0,50,50);
g.drawRect (0,50,50,50);
g.fillRect (50,50,50,50);
g.drawRect (100,50,50,50);
g.fillRect (150,50,50,50);
g.drawRect (200,50,50,50);
g.fillRect (250,50,50,50);
g.drawRect (300,50,50,50);
g.fillRect (350,50,50,50);

g.fillRect (0,100,50,50);
g.drawRect (50,100,50,50);
g.fillRect (100,100,50,50);
g.drawRect (150,100,50,50);
g.fillRect (200,100,50,50);
g.drawRect (250,100,50,50);
g.fillRect (300,100,50,50);
g.drawRect (350,100,50,50);
g.drawRect (0,150,50,50);
g.fillRect (50,150,50,50);
g.drawRect (100,150,50,50);
g.fillRect (150,150,50,50);
g.drawRect (200,150,50,50);
g.fillRect (250,150,50,50);
g.drawRect (300,150,50,50);
g.fillRect (350,150,50,50);
g.fillRect (0,200,50,50);
g.drawRect(50,200,50,50);
g.fillRect(100,200,50,50);
g.drawRect (150,200,50,50);
g.fillRect (200,200,50,50);
g.drawRect (250,200,50,50);
g.fillRect (300,200,50,50);
g.drawRect (350,200,50,50);
g.drawRect (0,250,50,50);
g.fillRect (50,250,50,50);
g.drawRect (100,250,50,50);
g.fillRect (150,250,50,50);
g.drawRect (200,250,50,50);
g.fillRect (250,250,50,50);
g.drawRect (300,250,50,50);
g.fillRect (350,250,50,50);
g.fillRect (0,300,50,50);
g.drawRect (50,300,50,50);
g.fillRect (100,300,50,50);
g.drawRect (150,300,50,50);
g.fillRect (200,300,50,50);
g.drawRect (250,300,50,50);
g.fillRect (300,300,50,50);
g.drawRect (350,300,50,50);
g.drawRect (0,350,50,50);
g.fillRect (50,350,50,50);
g.drawRect (100,350,50,50);
g.fillRect (150,350,50,50);
g.drawRect (200,350,50,50);
g.fillRect (250,350,50,50);
g.drawRect (300,350,50,50);
g.fillRect (350,350,50,50);
}
}
19 years ago