Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
CLASSPATH and MouseClicked()
- From: a-nemeth at freemail.c3.hu (BAN)
- Subject: CLASSPATH and MouseClicked()
- Date: Sat Nov 12 19:31:59 2005
Hi,
I have some problems with this program.
First of all, I could start this applet on my home PC, but when I
loaded it at my workplace, I got this message:
load: class IColor not found
Something wrong with CLASSPATH? But,I use JDK1.2 (on WINNT) and there
is no CLASSPATH (default).
Secondly,I enchanced IColor with M1L MouseAdapter, but it is not work.
May I use canvas or get the canvas of the applet?
Any other comments are welcome.
Thank all of you.
BAN
IColor.html:
<HTML>
<HEAD>
<applet
CODE=IColor
width=200
height=200>
</applet>
</HEAD>
<BODY>
This is the body of this wondeful page!
</BODY>
</HTML>
IColor.java:
import java.awt.*;
import java.applet.*;
import java.lang.Math;
import java.net.URL;
import java.net.MalformedURLException;
import java.awt.event.*;
import java.awt.image.*;
import ImageProcessor;
public class IColor extends Applet implements Runnable{
Integer height, width;
Image picture;
Thread t;
int appletWidth, appletHeight;
Graphics offScreen;
Image offScreenImage;
boolean runningThread;
int xdirection, ydirection;
ImageProcessor ip;
public void init(){
String temp;
height = new Integer(getParameter("height"));
width = new Integer(getParameter("width"));
appletWidth = getSize().width;
appletHeight = getSize().height;
try {
offScreenImage = createImage (appletWidth, appletHeight);
offScreen = offScreenImage.getGraphics ();
} catch (Exception e) {
offScreen = null;
}
picture = getImage(getDocumentBase(),"images/city.gif");
ip = new ImageProcessor(picture);
}
public void start(){
t = new Thread(this);
runningThread = true;
t.start();
xdirection = direction();
ydirection = direction();
addMouseListener(new M1L());
}
public void stop() {
stopRun();
runningThread = false;
}
public void paint(Graphics g){
update(g);
// repaint();
}
public synchronized void update (Graphics g){
if (offScreen != null) {
paintApplet(offScreen);
g.drawImage(offScreenImage,0,0,this);
} else {
paintApplet(g);
}
}
private int direction(){
double rnum;
rnum = Math.random();
if(rnum < 0.33d) {
return -1;
} else {
if (rnum < 0.66d) {
return 0;
} else {
return 1;
}
}
}
public void paintApplet(Graphics g){
g.fillRect(0,0,appletWidth,appletHeight);
// handlePixels(picture, 0, 0, appletWidth, appletHeight);
picture = createImage(new MemoryImageSource(getSize().width,
getSize().height,ip.pixels,0,getSize().height));
g.drawImage(picture,0,0, appletWidth, appletHeight, this);
g.setColor(Color.white);
}
public void run(){
while (runningThread){
repaint();
try
{
Thread.currentThread().sleep(25);
// t.sleep(50);
} catch (InterruptedException e) {
//This thread was interrupted
//by another thread
}
}
}
public void handlesinglepixel(int x, int y, int pixel) {
int alpha = (pixel >> 24) & 0xff;
int red = (pixel >> 16) & 0xff;
int green = (pixel >> 8) & 0xff;
int blue = (pixel ) & 0xff;
red += 1;
pixel = 256*red+16*green+blue;
// Deal with the pixel as necessary...
}
public void handlePixels(Image img, int x, int y, int w, int h) {
int[] pixels = new int[w * h];
PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
try {
pg.grabPixels();
} catch (InterruptedException e) {
System.err.println("interrupted waiting for pixels!");
return;
}
if ((pg.getStatus() & ImageObserver.ABORT) != 0) {
System.err.println("image fetch aborted or errored");
return;
}
for (int j = 0; j < h; j++) {
for (int i = 0; i < w; i++) {
handlesinglepixel(x+i, y+j, pixels[j * w + i]);
}
}
}
public void stopRun(){
// i = 0;
}
public class M1L extends MouseAdapter{
public void mouseClicked(MouseEvent e){
System.out.println("Mouse clicked!");
ip.invert();
}
}
}
------------------------------------------------------
nickname: BAN
e-mail: a-nemeth@xxxxxxxxxxxxxx
Born to be digital.
------------------------------------------------------
---
To unsubscribe, mail advanced-java-unsubscribe@xxxxxxxxxxxxxxxx
To get help, mail advanced-java-help@xxxxxxxxxxxxxxxx
- Prev by Date: Security in passing contents of a text field through an applet
- Next by Date: [no subject]
- Previous by thread: Security in passing contents of a text field through an applet
- Next by thread: [no subject]
- Index(es):