Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Is WinXPs JVM Bogus or just IE6?

GeoHoffmanGeoHoffman Member Posts: 176
Hi. I just started learning java about a month ago. I am having many problems getting things to work correctly and I think it has to do with my JVM or web browser. I am running windowsXP and IE6 and have the Java 2 (v1.4.2_03) virtual machine. I am mostly trying to program applets for my web site. Here is some code. I got this out of "Java 2 fifth edition" published by Osborne so it should be accurate:


//BEGIN CODE: (file is named test.java)////////////////////
import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class test extends Applet implements MouseListener, MouseMotionListener
{
String msg = "";
int mouseY = 0;
int mouseX = 0;

public void init()
{
addMouseListener(this);
addMouseMotionListener(this);
}
public void mouseClicked(MouseEvent me)
{
mouseX = 0;
mouseY = 10;
msg = "Mouse Clicked";
repaint();
}
public void mouseEntered(MouseEvent me)
{
mouseX = 0;
mouseY = 10;
msg = "Mouse Entered";
repaint();
}
public void mouseExited(MouseEvent me)
{
mouseX = 0;
mouseY = 10;
msg = "Mouse Exited";
repaint();
}
public void mousePressed(MouseEvent me)
{
mouseX = me.getX();
mouseY = me.getY();
msg = "Down";
repaint();
}
public void mouseReleased(MouseEvent me)
{
mouseX = me.getX();
mouseY = me.getY();
msg = "Up";
repaint();
}
public void mouseDragged(MouseEvent me)
{
mouseX = me.getX();
mouseY = me.getY();
msg = "*";

showStatus("Dragging mouse at " + me.getX() + ", " + me.getY());
repaint();
}

public void mouseMoved(MouseEvent me)
{
showStatus("Moving mouse at " + me.getX() + ", " + me.getY());
}



public void paint(Graphics G)
{
G.drawString(msg,mouseX,mouseY);
}
}

//END CODE://///////////////////////////

I compile with this comand:

javac test.java



Then I execute the applet by using a web page like this:



This all compiles fine but does not work like intended. I can't seem to get messages to display correctly in the status bar and the drawString() method does not display anything either. Basically, all I can see is the empty grey applet in my browser window, no matter what I do (mouseClick, mouseMove, mousePress, mouseRelease, mouseEnter, mouseExit). I have seen this problem before. In an earlier applet I was working on I had a call to showStatus() in init(). I could see it for a split second when the applet loaded but then it disappeared. Is this the intended use of this method? Are you supposed to continuously refres the status bar?

Comments

  • beancounterbeancounter Member Posts: 88
    Hello,

    Had the same problem with my applets. Assuming your code is correct there is a couple of things you might try...

    1). Make sure you have the latest JVM from Sun installed. as a test go to my web site [email protected] and click the calculator button and see if you can get my applet to open. If It doesn't open I have a button you can click to get the latest JVM from sun.

    2). IE has to have the java plug-in to run applets. I had to run my HTML page through Sun's HTML converter which tells IE to use the plug-in.

    3). To test your code, try running your applet through Netscape. Even though my applets wouldn't work in IE they did run in netscape.

    Hope this helps.

    Ken

    Ken
    : Hi. I just started learning java about a month ago. I am having many problems getting things to work correctly and I think it has to do with my JVM or web browser. I am running windowsXP and IE6 and have the Java 2 (v1.4.2_03) virtual machine. I am mostly trying to program applets for my web site. Here is some code. I got this out of "Java 2 fifth edition" published by Osborne so it should be accurate:
    :
    :
    : //BEGIN CODE: (file is named test.java)////////////////////
    : import java.awt.*;
    : import java.applet.*;
    : import java.awt.event.*;
    :
    : public class test extends Applet implements MouseListener, MouseMotionListener
    : {
    : String msg = "";
    : int mouseY = 0;
    : int mouseX = 0;
    :
    : public void init()
    : {
    : addMouseListener(this);
    : addMouseMotionListener(this);
    : }
    : public void mouseClicked(MouseEvent me)
    : {
    : mouseX = 0;
    : mouseY = 10;
    : msg = "Mouse Clicked";
    : repaint();
    : }
    : public void mouseEntered(MouseEvent me)
    : {
    : mouseX = 0;
    : mouseY = 10;
    : msg = "Mouse Entered";
    : repaint();
    : }
    : public void mouseExited(MouseEvent me)
    : {
    : mouseX = 0;
    : mouseY = 10;
    : msg = "Mouse Exited";
    : repaint();
    : }
    : public void mousePressed(MouseEvent me)
    : {
    : mouseX = me.getX();
    : mouseY = me.getY();
    : msg = "Down";
    : repaint();
    : }
    : public void mouseReleased(MouseEvent me)
    : {
    : mouseX = me.getX();
    : mouseY = me.getY();
    : msg = "Up";
    : repaint();
    : }
    : public void mouseDragged(MouseEvent me)
    : {
    : mouseX = me.getX();
    : mouseY = me.getY();
    : msg = "*";
    :
    : showStatus("Dragging mouse at " + me.getX() + ", " + me.getY());
    : repaint();
    : }
    :
    : public void mouseMoved(MouseEvent me)
    : {
    : showStatus("Moving mouse at " + me.getX() + ", " + me.getY());
    : }
    :
    :
    :
    : public void paint(Graphics G)
    : {
    : G.drawString(msg,mouseX,mouseY);
    : }
    : }
    :
    : //END CODE://///////////////////////////
    :
    : I compile with this comand:
    :
    : javac test.java
    :
    :
    :
    : Then I execute the applet by using a web page like this:
    :
    :
    :
    : This all compiles fine but does not work like intended. I can't seem to get messages to display correctly in the status bar and the drawString() method does not display anything either. Basically, all I can see is the empty grey applet in my browser window, no matter what I do (mouseClick, mouseMove, mousePress, mouseRelease, mouseEnter, mouseExit). I have seen this problem before. In an earlier applet I was working on I had a call to showStatus() in init(). I could see it for a split second when the applet loaded but then it disappeared. Is this the intended use of this method? Are you supposed to continuously refres the status bar?
    :

  • GeoHoffmanGeoHoffman Member Posts: 176
    Everything seems to be working now. I installed Suns One studio 5 which comes with a version of their JVM. I think that is what did it because when I went to Suns web site it said I already had the latest version. Thanks for the help.
Sign In or Register to comment.