Ok, Im a rookie when it comes to java and applets so please bear with me.
Ive been experimenting a bit with object and events but have run into a small problem that I was hoping some here could help me with.
In my applet file I create an object (from class file), given it the correct coordinates and then finally draw it. Pretty simple stuff, and it works (wow).
I have also implemented a mouse listener that seems to work. Now my question, I'd like to use the mouseClick event to run a method thats I've create in my class file. How is this done ?
I've added some of my code, here is the applet file (part of it anyway) :
public class Yatzy1 extends Applet
{
public Dice T1;
public void init ()
{
DotsMouseListener listener = new DotsMouseListener(this);
addMouseListener(listener);
T1= new Dice (10,10,50,50);
T1.eyes();
}
public void paint (Graphics page)
{
T1.draw (page);
}
}
Here is my mouseListener file :
class DotsMouseListener implements MouseListener
{
private Yatzy1 applet;
public DotsMouseListener (Yatzy1 theApplet)
{
applet = theApplet;
}
public void mouseClicked (MouseEvent event)
{
// here I'd like to run mark method thats stored in object file
}
}
Here is my class file :
public class Dice
{
int value;
int width;
int height;
int baseX;
int baseY;
public Dice (int x, int y, int z, int y)
{
baseX = x;
baseY = y;
width =z;
height = y;
}
public void markit (Graphics page)
{
// some code stuff
}
public void eyes ()
{
value = (int) ((Math.random() * 6)+1);
}
Just as an example, how can I run the code thats located in public void markit in class file when mouseClick ?
I really hope I explained myself good enough, hoping for an answer.
Regards,
Lars
Ive been experimenting a bit with object and events but have run into a small problem that I was hoping some here could help me with.
In my applet file I create an object (from class file), given it the correct coordinates and then finally draw it. Pretty simple stuff, and it works (wow).
I have also implemented a mouse listener that seems to work. Now my question, I'd like to use the mouseClick event to run a method thats I've create in my class file. How is this done ?
I've added some of my code, here is the applet file (part of it anyway) :
public class Yatzy1 extends Applet
{
public Dice T1;
public void init ()
{
DotsMouseListener listener = new DotsMouseListener(this);
addMouseListener(listener);
T1= new Dice (10,10,50,50);
T1.eyes();
}
public void paint (Graphics page)
{
T1.draw (page);
}
}
Here is my mouseListener file :
class DotsMouseListener implements MouseListener
{
private Yatzy1 applet;
public DotsMouseListener (Yatzy1 theApplet)
{
applet = theApplet;
}
public void mouseClicked (MouseEvent event)
{
// here I'd like to run mark method thats stored in object file
}
}
Here is my class file :
public class Dice
{
int value;
int width;
int height;
int baseX;
int baseY;
public Dice (int x, int y, int z, int y)
{
baseX = x;
baseY = y;
width =z;
height = y;
}
public void markit (Graphics page)
{
// some code stuff
}
public void eyes ()
{
value = (int) ((Math.random() * 6)+1);
}
Just as an example, how can I run the code thats located in public void markit in class file when mouseClick ?
I really hope I explained myself good enough, hoping for an answer.
Regards,
Lars