Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

applet

Status
Not open for further replies.

zxc

Technical User
Nov 12, 2000
1
NO
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top