Win a copy of Terraform in Action this week in the Cloud forum!

David Record

Greenhorn
+ Follow
since Jun 14, 2001
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 David Record

maybe someone here can help me. I keep getting an instantiation error (runtime) in my applet code. I'm trying to get an applet to display an image wherever I click the mouse. here's the code:
//< applet code="AppletApp.class" width=200 height=300>< /applet>
import java.awt.*; //<-- added code
import java.applet.*; //<-- added code
import java.awt.event.*; //<-- added code
abstract class AppletApp extends Applet implements MouseListener{

private Image duke;
private int xPos,yPos;

public void init() {

duke = getImage(getDocumentBase(),"duke.gif");
addMouseListener(this);

}
public void paint(Graphics g) {

setBackground(Color.white);
g.drawImage(duke, xPos, yPos, this);
}
public void mousePressed(MouseEvent e) {
xPos = e.getX();
yPos = e.getY();
repaint();
}

}
thanks to anyone who can help
Dave
[This message has been edited by Jim Yingst (edited July 07, 2001).]
20 years ago
please help me. I keep getting an instantiation error in my code. it compiles fine, but doesn't work. I'm trying to place an image wherever I click the mouse in the applet.
here's the code
//<applet code="AppletApp.class" width=200 height=300></applet>
import java.awt.*; //<-- added code
import java.applet.*; //<-- added code
import java.awt.event.*; //<-- added code
abstract class AppletApp extends Applet implements MouseListener{

private Image duke;
private int xPos,yPos;

public void init() {

duke = getImage(getDocumentBase(),"duke.gif");
addMouseListener(this);

}
public void paint(Graphics g) {

setBackground(Color.white);
g.drawImage(duke, xPos, yPos, this);
}
public void mousePressed(MouseEvent e) {
xPos = e.getX();
yPos = e.getY();
repaint();
}

}
20 years ago
THis is what I have so far, and I'm getting an instantiation error.
//<applet code="AppletApp.class" width=200 height=300></applet>
import java.awt.*; //<-- added code
import java.applet.*; //<-- added code
import java.awt.event.*; //<-- added code
abstract class AppletApp extends Applet implements MouseListener{

private Image duke;
private int xPos,yPos;

public void init() {

duke = getImage(getDocumentBase(),"duke.gif");

addMouseListener( this );

}
public void paint(Graphics g) {

setBackground(Color.white);
g.drawImage(duke, xPos, yPos, this);
}

public void mousePressed(MouseEvent e) {
xPos = e.getX();
yPos = e.getY();
repaint();
}

}
20 years ago
hey thanks I'll give it a shot and get back to you.
20 years ago
how do I place an image in an applet like a jpeg or gif, and have the applet place the image where I click the mouse?
thanks guys
20 years ago
hey thanks a lot,
that fixed my problem
Dave
20 years ago
I'm having a problem with this code. The counters in the "if" statements are not working. Can anyone help me? I've included both files here.


[This message has been edited by Cindy Glass (edited June 14, 2001).]
20 years ago