• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need to add a getclickCount()

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);
}
}
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic