Matthew Gaunt

Greenhorn
+ Follow
since Mar 12, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Matthew Gaunt

In my applet, I have two components. One of them goes in the centre and the other is a Label component being placed at the NORTH edge of the applet.
I know that the applet has a BorderLayout, so the width of the label is determined by the width of the applet.
The question is, can I set the height of the label, or will it only ever be displayed within the applet at the label's preferred height. If I can set it, then how, since everything I have tried does not seem to work.
Best Regards
Matt Gaunt
22 years ago
This piece of code is further complicated by the need to integrate it with an application known as SameTime.
Although I didn't consider a list of labels, when I think about it, I probably still would have gone with the list, as it integrates more easily with SameTime. Also, people will enter and exit the applet as the page is loaded, so I feel that the regular creation and destroying of new Label objects as people come and go would end up using too much processing time.
Thank you very much for your suggestion though, and you are quite correct in that I should have thought about this as an option in the very beginning.
Best Regards
Matt Gaunt
22 years ago
Unfortunately, the client really does want it on the mouseover.
But not to worry, as sorted it out by putting the list of things in a list box big enough to contain all of the names without a scrollbar, and then adding that list to a scrollpane. The list box had a mousemotionlistener added to it, and the index of the name the mouse was scrolling over was determined by dividing the y position by the font height.
Not the most efficient way, but effective none the less.
Best Regards
Matt Gaunt
22 years ago
Hi There,
What I am trying to do is create an applet which has a list box holding a list of names which is obtained from a database. That is the easy bit.
When this is being displayed on the screen, as the mouse pointer moves over the names in the list, a Javascript popup box detailing more information is displayed. This is a little more difficult, but it is working for the most part.
The way the program knows what name the pointer is over is by finding out the x,y co-ordinates of the mouse position inside the List box, and determining which name it would be over at that position. (determining font heights and so on)
However, if the number of names in the list is more than the area allowed for it, a scrollbar is automatically added (as would be expected).
The problem is that after the scrollbar has been adjusted, I cannot work out how to determine which name the pointer is hanging over in the list. This is made even more difficult by the lack of an addAdjustmentListener() method for the List object.
Does anyone have any ideas.
Thanks
Matt
23 years ago
Hi There,
Am using a MS Access database to hold data, and want to add to one of the tables using JDBC.
Under most circustances, this is not a problem.
The question is, how do I add data to a table which has an AutoNumber field as the primary key??
Best Regards
Matt Gaunt
So simple,
Yet I was making it so difficult. Thanks Nate for showing me the light. I didn't even consider using a while loop in the run() method. But looking at it, it makes a hell of a lot more sense than creating new threads.
And Rahul, you were right. I did start having Thread execution problems, as in executing in the right order.
Thank you both for all your help. You have both taught me heaps.
Best Regards
Matt Gaunt
23 years ago
Thanks Rahul,
Have sorted it by creating a new Thread in the mouseMove() method and then calling the imageMove() method. Seems to be working better than before.
Then sychronized the code inside the mouseMove() method, so as the imageMove() method is only being called once at any time (since imangeMove() is only called from mouseMove()), so all seems to be fine now.
Thank you so much for your help.
Best Regards
Matt Gaunt
23 years ago
Do you mean change that each button changes a certain region of the border layout (ie-North South East West Center).
It is a little difficult to understand what section of the panel is supposed to change when you press the buttons. And where are the buttons positioned?
Best Regards
Matt
23 years ago
Thank you Rahul,
It sounds pretty much right to me, what you have said. I have posted my code as requested by Nate. I think this will just verify what Rahul has explained.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
/**
* Insert the type's description here.
* Creation date: (09/03/01 16:11:33)
* @author:
*/
public class Neko extends Applet implements MouseListener, MouseMotionListener, Runnable {
Thread thread;
public java.awt.Image[] catPics = new java.awt.Image[9];
private java.lang.String[] cat = {"awake.gif","right1.gif","right2.gif","scratch1.gif","scratch2.gif","sleep1.gif","sleep2.gif","stop.gif","yawn.gif"};
public java.awt.Image currentImage;
private int x = 0;
public int endX;
public int currentX = 0;
private int y = 20;
public int currentY = 20;
/**
* Initializes the applet.
*/
public void init() {
addMouseListener(this);
addMouseMotionListener(this);
for (int i=0; i<catPics.length;i++)
catPics[i] = getImage(getDocumentBase(),"images/"+cat[i]);
currentImage=catPics[0];
}
public void mouseMoved(MouseEvent e) {
endX=e.getX();
System.out.println("Am at horizontal position "+endX+" and current position is "+currentX);
if (endX>currentX){
System.out.println("Am about to run to the right");
runRight(endX);
}
else{
System.out.println("Am about to run to the left");
runLeft(endX);
}
}
public void paint(Graphics g) {
System.out.println("Am in the paint method now");
if (currentImage!=null){
System.out.println(currentX+"\t"+currentY);
g.drawImage(currentImage,currentX,currentY,this);
}
// insert code to paint the applet here
}
/**
* Insert the method's description here.
* Creation date: (12/03/01 09:17:10)
* @param time long
*/
public void pause(long time) {
try{
Thread.sleep(time);
}
catch (InterruptedException e){}
}
/**
* Insert the method's description here.
* Creation date: (12/03/01 14:02:20)
* @param numZs int
*/
public void rest(int numZs) {
currentImage=catPics[8];
repaint();
pause(400);
for (int i=0; i<numZs; i++){
if (currentImage!=catPics[5])
currentImage=catPics[5];
else
currentImage=catPics[6];
repaint();
pause(800);
}
currentImage=catPics[0];
repaint();
pause(600);
}
/**
* Contains the thread execution loop.
*/
public void run() {
repaint();
double x=getSize().width;
runRight((int)x/2);
rest(4);
scratch(6);
runLeft(0);
}
/**
* Insert the method's description here.
* Creation date: (12/03/01 12:43:00)
* @param endPos int
*/
public void runLeft(int endPos) {
System.out.println("Am about to run from "+currentX+" to "+endPos);
while (currentX>endPos){
if (currentImage!=catPics[2]){
currentImage=catPics[2];
repaint();}
else{
currentImage=catPics[1];
repaint();}
currentX-=5;
pause(200);
}
currentX=endPos;
currentImage=catPics[7];
repaint();
pause(400);
}
/**
* Insert the method's description here.
* Creation date: (09/03/01 16:54:33)
*/
public void runRight(int endPos) {
System.out.println("Am about to run from "+currentX+" to "+endPos);
while (currentX<endPos){
if (currentImage!=catPics[2])
currentImage=catPics[2];
else
currentImage=catPics[1];
currentX+=5;
System.out.println("currentX = "+currentX);
if (currentX>=endPos) System.out.println("last iteration");
repaint();
pause(250);
}
currentX=endPos;
currentImage=catPics[7];
repaint();
pause(700);
}
/**
* Insert the method's description here.
* Creation date: (12/03/01 14:08:03)
* @param numScratch int
*/
public void scratch(int numScratch) {
for (int i=0; i<numScratch; ++i){
if (currentImage!=catPics[3])
currentImage=catPics[3];
else
currentImage=catPics[4];
repaint();
pause(350);
}
currentImage=catPics[7];
repaint();
pause(600);
}
/**
* Starts up the thread.
*/
public void start() {
if (thread == null){
thread = new Thread(this);
thread.start();
}
}
/**
* Terminates the thread and leaves it for garbage collection.
*/
public void stop() {
if (thread != null){
thread.stop();
thread = null;
}
}
}

Best Regards
Matt Gaunt
23 years ago
Thanks Nate,
That is pretty much what I have now. At the moment, after the thread is started, if I call the imageMove() method from the run() method, then the imageMove() method works perfectly. Repainting the image as required. But, when I call the same imageMove() method from the mouseMoved() method (or any of the other mouse listener methods), it performs the whole imageMove() method EXCEPT for the repaint() calls. For some reason, it doesn't do any of them, other than the last one.
Very frustrating.
Any suggestions?!
Best Regards
Matt Gaunt
23 years ago
I have created a thread to run the animated object (ie: Thread t=new Thread(this) ). As usual, the thread is started using thread.start(). Implicitly invoking the run() method which is required in the code as I am implementing the Runnable interface.
Now, this applet object also implements the MouseMotionListener. What I want to happen is:
when the mouse pointer positions itself over the applet, the mouseMoved() method will call another method (lets call it imageMove() ) which will cause the applet to repaint() through a loop to make it appear as though the image is moving towards the pointer. Sounds simple enough. But for some reason, when the imageMove() method is called from the mouseMoved() method, it does everything in the loop except the actual repaint() of the image. Yet, if I call the imageMove() method from the run() method, it works fine.
Hope this sounds a little clearer.
Best Regards
Matt
23 years ago
Am trying to make my animated object chase after the mouse pointer in my applet. The applet implements the MouseMotionListener, and when the mouseMoved() method is invoked, then another method is called which controls how much the animated image should move on its way to the pointer's position. This is done in a while loop and the call repaint() made on each iteration. But for some reason, the animated object is not repainted until the final iteration.
If I call this same method from the run() method (as it is in an applet), the animation works perfectly. Does anyone have any ideas.
Best Regards
Matt Gaunt
23 years ago