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]


Messages In This Thread
Mouselistener help - by jorgenRe - 05-19-2013, 04:38 AM
Re: Mouselistener help - by andrei.xd23 - 05-19-2013, 09:30 AM
Re: Mouselistener help - by jorgenRe - 05-20-2013, 12:41 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)