Re: Essentially skinning my app..
- From: IchBin <weconsul@xxxxxxx>
- Date: Wed, 25 Jan 2006 00:48:59 -0500
jackroofman@xxxxxxxxx wrote:
How do I make this ImageViewer work? I can't get it to so much as call its paint command. Trying to set a JComponent to an ImageViewer only results in throwing a NullPointerException.
It's clearly doing something, because a System.out.println() of the ImageViewer does return a slew of:
sun.awt.image.ToolkitImage@1a33d48 sun.awt.image.ToolkitImage@b2002f sun.awt.image.ToolkitImage@406199 sun.awt.image.ToolkitImage@1f6f296 sun.awt.image.ToolkitImage@1df5a8f sun.awt.image.ToolkitImage@1e13d52 sun.awt.image.ToolkitImage@1b9ce4b sun.awt.image.ToolkitImage@1292d26 sun.awt.image.ToolkitImage@1db699b
but I can't actually get anything to come of it.
How about some thing like this... using a canvas. Use a special Canvas to preload 2 GIFs, and using a MouseListener simply toggle the image.
[JDK1.1]
import java.awt.*; import java.awt.event.*; import java.net.*;
public class ToggleGifCanvas extends Canvas
implements MouseListener {
Image img1, img2;
int index = 0;
MediaTracker tracker; public ToggleGifCanvas(URL n1, URL n2) {
tracker = new MediaTracker(this);
try {
img1 = Toolkit.getDefaultToolkit().getImage(n1);
img2 = Toolkit.getDefaultToolkit().getImage(n2);
tracker.addImage(img1,0);
tracker.addImage(img2,1);
tracker.waitForAll();
addMouseListener(this);
}
catch (Exception e) {
e.printStackTrace();
}
} public void paint(Graphics g) {
if (img1 != null) {
if (index == 0) {
g.drawImage(img1,0,0,this);
index++;
}
else {
g.drawImage(img2,0,0,this);
index--;
}
}
} public Dimension getPreferredSize (){
return new Dimension
(img1.getHeight(this), img2.getWidth(this));
} public void mouseClicked(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
public void mouseEntered(MouseEvent e) {
index = 1; repaint();
}
public void mouseExited(MouseEvent e) {
index = 0; repaint();
}
}To use such Canvas, try something like this. This example needs our Gumby GIFs ( and ).
import java.applet.*; import java.awt.*; import java.net.*;
public class tcanvas extends Applet {
ToggleGifCanvas tgc; public void init() {
try {
tgc = new ToggleGifCanvas
(new URL(getDocumentBase(),"gumby.gif"),
new URL(getDocumentBase(),"gumby2.gif"));
add(tgc);
}
catch (Exception e) {
e.printStackTrace();
}
}
}
--
Thanks in Advance...
IchBin, Pocono Lake, Pa, USA http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________
'If there is one, Knowledge is the "Fountain of Youth"' -William E. Taylor, Regular Guy (1952-) .
- References:
- Essentially skinning my app..
- From: jackroofman
- Re: Essentially skinning my app..
- From: Roedy Green
- Re: Essentially skinning my app..
- From: jackroofman
- Essentially skinning my app..
- Prev by Date: Re: Essentially skinning my app..
- Next by Date: Re: Essentially skinning my app..
- Previous by thread: Re: Essentially skinning my app..
- Next by thread: Re: Essentially skinning my app..
- Index(es):
Relevant Pages
|
|