aspose file tools*
The moose likes Applets and the fly likes Need to add a getclickCount() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Need to add a getclickCount()" Watch "Need to add a getclickCount()" New topic
Author

Need to add a getclickCount()

Cameron Mitchell
Greenhorn

Joined: Apr 09, 2004
Posts: 2
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);
}
}
Noah Carroll
Ranch Hand

Joined: Sep 20, 2000
Posts: 96
I believe that the .getClickCount() method that you are trying to use is used to determine whether or not a person did a single or double click. In your case you might try adding some code to your mouseClicke(MouseEvent e) method that you have left empty. You could set up a seperate integer and every time that method is entered you could just add one to the integer. The method is entered every time the mouse is pressed and released. In other words, as soon as you let go, it enters that method, and in your program it does nothing inside.
[ March 31, 2008: Message edited by: Noah Carroll ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need to add a getclickCount()