Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Mouselistener help
#1
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]
#2
[code2=java]public void inint()
{
this.addMouseListener(this);
}[/code2]
here is the problem... it's init not inint
#3
I'm glad you were able to find the solution! Thanks for posting!
My Blog | My Setup | My Videos | Have a wonderful day.
#4
andrei.xd23 Wrote:[code2=java]public void inint()
{
this.addMouseListener(this);
}[/code2]
here is the problem... it's init not inint

Thanks alot!


Forum Jump:


Users browsing this thread: 1 Guest(s)