BP Forums
Mouselistener help - Printable Version

+- BP Forums (https://bpforums.info)
+-- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=55)
+--- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=56)
+---- Forum: Java (https://bpforums.info/forumdisplay.php?fid=19)
+---- Thread: Mouselistener help (/showthread.php?tid=786)



Mouselistener help - jorgenRe - 05-19-2013

I'm trying to learn java from your video tutorials and i'm on part 19 now when executing your program it does not find any mouse so nothing happens when the mouse is pressed.
[code2=java]import java.applet.Applet;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class mouselistener
extends Applet
implements MouseListener{

private Graphics globalGraphics = null;

public void inint()
{
this.addMouseListener(this);
}

public void paint(Graphics g)
{
this.setSize(new Dimension(800, 600));

globalGraphics = g.create();
}

public void drawDot(int x, int y)
{
//define r, g, b color randomizer
int r = (int) (Math.random() * 255);
int g = (int) (Math.random() * 255);
int b = (int) (Math.random() * 255);

System.out.println("test");

Color randomColor = new Color(r,g,b);
globalGraphics.setColor(randomColor);
globalGraphics.fillRect(x, y, 10, 10);
}

@Override
public void mouseClicked(MouseEvent e) {

}

@Override
public void mouseEntered(MouseEvent arg0) {
System.out.println("Mouse have entered!");

}

@Override
public void mouseExited(MouseEvent arg0) {
System.out.println("Mouse have gone");
}

@Override
public void mousePressed(MouseEvent e) {
System.out.println("Click");
int mouseX = e.getX();
int mouseY = e.getY();

drawDot(mouseX, mouseY);

}

@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub

}
}[/code2]


Re: Mouselistener help - andrei.xd23 - 05-19-2013

[code2=java]public void inint()
{
this.addMouseListener(this);
}[/code2]
here is the problem... it's init not inint


Re: Mouselistener help - brandonio21 - 05-19-2013

I'm glad you were able to find the solution! Thanks for posting!


Re: Mouselistener help - jorgenRe - 05-20-2013

andrei.xd23 Wrote:[code2=java]public void inint()
{
this.addMouseListener(this);
}[/code2]
here is the problem... it's init not inint

Thanks alot!