Display .gif In Applet Problem
I have been making a game. Very simply, the game has a main class and another truely important class that extends JFrame, it is the map. In it i need to upload .gif files and display them. It worked up until recently because i needed to make a sepperate class. I know how to use the getImage() for Images and the the way for ImageIcons, but for some reason, they never display (they display just whiteness). My Code is as follows
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import java.io.*;
// when this puppy reads from a file, it'll be able to have 55 15 x 15 terrains per row
// 35 15 x 15 terrains per column
// arrows by everythign that u would need to consider in finding the problem
// this is not the main class
public class GameMap extends JPanel implements MouseListener, MouseMotionListener, KeyListener{
public static final int MAX_BULLETS = 200;
public static final int MAX_PLAYERS = 50;
public static final int SPLAT_SIZE = 15;
public static final int PLAYER_SIZE = 15;
public static final int MAX_MESSAGES = 10;
public static final int ROBOT_SIZE = 15;
private static final int rowTerrains = 35;
private static final int columnTerrains = 55;
private static int currentBullets = 0;
private static int currentPlayers = 0;
private static int bulletRotation = 0;
private static int aimX, aimY;
private boolean mapLoaded;
private boolean writingMessage;
private boolean imagesLoaded;
private int messageRotation;
private int tileCoord;
private String messageText = "";
private String currentMap;
private Bullet bullet[] = new Bullet[MAX_BULLETS];
private Player player[] = new Player[MAX_PLAYERS];
private Message message[] = new Message[MAX_MESSAGES];
private Color backgroundColor = new Color(81, 141, 23);
private Image offscreenMap; // offscreen image of map
private Graphics mapGraphics;
private ImageIcon yellowSplat1, yellowSplat2, yellowSplat3, yellowSplat4, yellowSplat5, bluePlayerBack, bluePlayerFront, bluePlayerRight, bluePlayerLeft, grass, tree, mountain, robot1;
private Terrain terrain[] = new Terrain[(rowTerrains * columnTerrains)];
public GameMap(){
this(800, 450);
public GameMap(int width, int height){
addMouseListener(this);
addMouseMotionListener(this);
addKeyListener(this); // use method requestFocusInWindow() for this to work
setPreferredSize(new Dimension(width, height));
setBackground(backgroundColor);
for (int x = 0; x < bullet.length; x++){
bullet[x] = new Bullet();
for (int x = 0; x < player.length; x++){
player[x] = new Player();
for (int x = 0; x < message.length; x++){
message[x] = new Message();
for (int x = 0, currentX = 0, currentY = 0; x < (rowTerrains * columnTerrains); x++){
terrain[x] = new Terrain();
terrain[x].setX(currentX);
terrain[x].setY(currentY);
currentX += 15;
if (currentX > columnTerrains * 15){
currentX = 0;
currentY += 15;
player[0].drawPlayer(0, 0);
//loadMap("Map1.txt"); // this is called to load the map right when this object is initialized
public void paintComponent(Graphics g){
super.paintComponent(g);
Graphics2D g2d = (Graphics2D)g;
Composite originalComposite = g2d.getComposite();
if (imagesLoaded == false){
yellowSplat1 = new ImageIcon("yellow1.gif");
yellowSplat2 = new ImageIcon("yellow2.gif");
yellowSplat3 = new ImageIcon("yellow3.gif");
yellowSplat4 = new ImageIcon("yellow4.gif");
yellowSplat5 = new ImageIcon("yellow5.gif");
bluePlayerBack = new ImageIcon("BlueBack.gif");
bluePlayerFront = new ImageIcon("BlueFront.gif");
bluePlayerLeft = new ImageIcon("BlueLeft.gif");
bluePlayerRight = new ImageIcon("BlueRight.gif");
grass = new ImageIcon("Grass.gif");
tree = new ImageIcon("Tree.gif");
mountain = new ImageIcon("Mountain.gif");
robot1 = new ImageIcon("Robot1.gif");
if (mapLoaded == false){ // so a map is loaded when game is started
loadMap("Map1.txt");
mapLoaded = true;
g.drawImage(offscreenMap, 0, 0, this);
for (int x = 0; x < bullet[0].totalBullets; x++){
if (bullet[x].getArrived()){
//find splat type and display it
g2d.setComposite(makeComposite(0.5f));
switch (bullet[x].getSplatType()){
case 0:
yellowSplat1.paintIcon(this, g2d, bullet[x].getDestX() - SPLAT_SIZE / 2, bullet[x].getDestY() - SPLAT_SIZE / 2);
break;
case 1:
yellowSplat2.paintIcon(this, g2d, bullet[x].getDestX() - SPLAT_SIZE / 2, bullet[x].getDestY() - SPLAT_SIZE / 2);
break;
case 2:
yellowSplat3.paintIcon(this, g2d, bullet[x].getDestX() - SPLAT_SIZE / 2, bullet[x].getDestY() - SPLAT_SIZE / 2);
break;
case 3:
yellowSplat4.paintIcon(this, g2d, bullet[x].getDestX() - SPLAT_SIZE / 2, bullet[x].getDestY() - SPLAT_SIZE / 2);
break;
case 4:
yellowSplat5.paintIcon(this, g2d, bullet[x].getDestX() - SPLAT_SIZE / 2, bullet[x].getDestY() - SPLAT_SIZE / 2);
break;
else{
g2d.setComposite(originalComposite);
g2d.setColor(Color.yellow);
g2d.fillOval(bullet[x].getX(), bullet[x].getY(), 3, 3);
g2d.setComposite(originalComposite);
g.setColor(Color.yellow);
for (int x = 0; x < player[0].totalPlayers; x++){
if (player[x].getPlayerPosition().equals("Back")){
bluePlayerBack.paintIcon(this, g2d, player[x].getX(), player[x].getY());
else if (player[x].getPlayerPosition().equals("Right")){
bluePlayerRight.paintIcon(this, g2d, player[x].getX(), player[x].getY());
else if (player[x].getPlayerPosition().equals("Left")){
bluePlayerLeft.paintIcon(this, g2d, player[x].getX(), player[x].getY());
else if (player[x].getPlayerPosition().equals("Front")){
bluePlayerFront.paintIcon(this, g2d, player[x].getX(), player[x].getY());
else{
g2d.fillOval(player[x].getX(), player[x].getY(), 15, 15);
if (writingMessage){
g2d.setColor(new Color(0, 0, 130));
g2d.setComposite(makeComposite(0.5f));
g2d.draw3DRect(8, 7, 800, 17, true);
g2d.setComposite(originalComposite);
g2d.setColor(Color.yellow);
g2d.drawString(messageText, message[0].getX(), 20);
for (int x = 0; x < MAX_MESSAGES; x++){
if (message[x].isDisplayed()){
g2d.drawString(message[x].getMessage(), message[x].getX(), message[x].getY());
private AlphaComposite makeComposite(float alpha) {
int type = AlphaComposite.SRC_OVER;
return(AlphaComposite.getInstance(type, alpha));
public void drawBullet(int aimX, int aimY){
bullet[bulletRotation].drawBullet(player[0].getX() + PLAYER_SIZE / 2, player[0].getY() + PLAYER_SIZE / 2, aimX, aimY);
player[0].setPlayerPosition(bullet[bulletRotation].getPlayerPosition());
bulletRotation++;
if (bulletRotation >= MAX_BULLETS){
bulletRotation = 0;
public void loadMap(String map){
mapLoaded = false;
currentMap = map;
try{
BufferedReader in = new BufferedReader(new FileReader(map));
String input, string1, string2;
for (int x = 0; x < terrain.length; x++){
terrain[x].setFilled(false);
for (int x = 0, currentArray; x < terrain.length; x++){
if ((input = in.readLine()) != null) {
StringTokenizer st = new StringTokenizer(input);
currentArray = Integer.parseInt(st.nextToken());
terrain[currentArray].setTerrainType(st.nextToken());
terrain[currentArray].setFilled(true);
else{
break;
in.close();
offscreenMap = createImage(size().width, size().height);
mapGraphics = offscreenMap.getGraphics();
//mapGraphics.clearRect(0, 0, size().width, size().height);
// everything from here down is to be painted to mapGraphics... but it doesn't get this far cuz of an error
for (int x = 0; x < terrain.length; x++){
if (terrain[x].getTerrainType().equals("Grass")){
grass.paintIcon(this, mapGraphics, terrain[x].getX(), terrain[x].getY());
System.out.println("terrain(" + x + ") is Grass");
else if (terrain[x].getTerrainType().equals("Tree")){
tree.paintIcon(this, mapGraphics, terrain[x].getX(), terrain[x].getY());
System.out.println("terrain(" + x + ") is Tree");
else if (terrain[x].getTerrainType().equals("Mountain")){
mountain.paintIcon(this, mapGraphics, terrain[x].getX(), terrain[x].getY());
System.out.println("terrain(" + x + ") is Mountain");
catch (FileNotFoundException e){
System.out.println("Map not found");
catch (IOException e){
System.out.println("IOException Error!");
// **** mouse Listener ****//
public void mouseClicked(MouseEvent e){}
public void mousePressed(MouseEvent e){}
public void mouseReleased(MouseEvent e){
if (e.getButton() == 1){
//System.out.println("player[0].movePlayer(" + e.getX() + ", " + e.getY() + ")");
aimX = e.getX();
aimY = e.getY();
movePlayer(aimX, aimY);
else if (e.getButton() == 3){
aimX = e.getX();
aimY = e.getY();
drawBullet(aimX, aimY);
public void mouseEntered(MouseEvent e){
if (isFocusOwner() != true){
requestFocusInWindow();
public void mouseExited(MouseEvent e){}
// **** end mouse listener ****//
// **** mouse motion listener ****//
public void mouseDragged(MouseEvent e){}
public void mouseMoved(MouseEvent e){}
// **** end mouse motion listener ****/
public void keyPressed(KeyEvent e){}
public void keyReleased(KeyEvent e){}
public void keyTyped(KeyEvent e){}
}I removed a few unnecessary methods from this code to make it easier to view. EVERYTHING works except for the images displaying. The reason i'm having this problem now is i just redid my workspace and copied the code and i think some glitch stopped it from compiling correctly all along so now i experience this problem in the applet viewer. Though, even before, i couldn't get anything to display in an applet.
And yes, everything is in the same place as the html file.
Thanks for your help!
Here's a way to keep track of and paint images with a simple Rectangle array. And also a way to remove lengthy initialization code blocks from paintComponent. Move the images by moving the rectangles.
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import javax.imageio.ImageIO;
import javax.swing.*;
public class GameMapRx
public static void main(String[] args)
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(new GameMapPanel());
f.setSize(400,400);
f.setLocation(200,200);
f.setVisible(true);
class GameMapPanel extends JPanel
Image[] images;
Rectangle[] rects;
boolean firstTime;
final int PAD;
public GameMapPanel()
loadImages();
firstTime = true;
PAD = 20;
protected void paintComponent(Graphics g)
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
int w = getWidth();
int h = getHeight();
if(firstTime)
initializeGameMap(w, h);
for(int i = 0; i < rects.length; i++)
Rectangle r = rects;
g.drawImage(images[i], r.x, r.y, this);
g2.draw(r);
private void loadImages()
String path = "images/duke/";
String ext = ".gif";
images = new Image[10];
for(int i = 0; i < images.length; i++)
try
URL url = getClass().getResource(path + "T" + (i + 1) + ext);
images[i] = ImageIO.read(url);
catch(MalformedURLException mue)
System.out.println("Bad URL: " + mue.getMessage());
catch(IOException ioe)
System.out.println("Unable to read: " + ioe.getMessage());
private void initializeGameMap(int w, int h)
rects = new Rectangle[images.length];
int imageWidth = images[0].getWidth(this);
int imageHeight = images[0].getHeight(this);
int cols = (w - 2*PAD) / imageWidth;
int xInc = imageWidth + (w - cols * imageWidth) / (cols + 1);
int x0 = (w - cols * imageWidth -
(cols - 1) * ((w - cols * imageWidth) / (cols + 1))) / 2;
for(int i = 0; i < images.length; i++)
int x = x0 + xInc * (i % cols);
int rows = i / cols;
int y = PAD + (imageHeight + PAD) * rows;
rects[i] = new Rectangle(x, y, imageWidth, imageHeight);
firstTime = false;
Similar Messages
-
Using getter/setter for returing a string variable to display on an Applet
have two classes called, class A and class testA.
class A contains an instance variable called title and one getter & setter method. class A as follow.
public class A extends Applet implements Runnable, KeyListener
//Use setter and getter of the instance variable
private String title;
public void init()
ASpriteFactory spriteFactory = ASpriteFactory.getSingleton();
// Find the size of the screen .
Dimension theDimension = getSize();
width = theDimension.width;
height = theDimension.height;
//Create new ship
ship = spriteFactory.createNewShip();
fwdThruster = spriteFactory.createForwardThruster();
revThruster = spriteFactory.createReverseThruster();
ufo = spriteFactory.createUfo();
missile = spriteFactory.createMissile();
generateStars();
generatePhotons();
generateAsteroids();
generateExplosions();
initializeFonts();
initializeGameData();
//Example from Instructor
//setMyControlPanel( new MyControlPanel(this) );
// new for JDK 1.2.2
addKeyListener(this);
requestFocus();
public void update(Graphics theGraphics)
// Create the offscreen graphics context, if no good one exists.
if (offGraphics == null || width != offDimension.width || height != offDimension.height)
// This better be the same as when the game was started
offDimension = getSize();
offImage = createImage(offDimension.width, offDimension.height);
offGraphics = offImage.getGraphics();
offGraphics.setFont(font);
displayStars();
displayPhotons();
displayMissile();
displayAsteroids();
displayUfo();
//displayShip();
//Load the game with different color of the space ship
displayNewShip();
displayExplosions();
displayStatus();
displayInfoScreen();
// Copy the off screen buffer to the screen.
theGraphics.drawImage(offImage, 0, 0, this);
private void displayInfoScreen()
String message;
if (!playing)
offGraphics.setColor(Color.white);
offGraphics.drawString("\'A\' to Change Font Attribute", 25, 35);
offGraphics.drawString(getTitle(), (width - fontMetrics.stringWidth(message)) / 2, height / 2
- fontHeight);
message = "The Training Mission";
offGraphics.drawString(message, (width - fontMetrics.stringWidth(message)) / 2, height / 2);
message = "Name of Author";
offGraphics.drawString(message, (width - fontMetrics.stringWidth(message)) / 2, height / 2
+ fontHeight);
message = "Original Copyright 1998-1999 by Mike Hall";
offGraphics.drawString(message, (width - fontMetrics.stringWidth(message)) / 2, height / 2
+ (fontHeight * 2));
if (!loaded)
message = "Loading sounds...";
int barWidth = 4 * fontWidth + fontMetrics.stringWidth(message);
int barHeight = fontHeight;
int startX = (width - barWidth) / 2;
int startY = 3 * height / 4 - fontMetrics.getMaxAscent();
offGraphics.setColor(Color.black);
offGraphics.fillRect(startX, startY, barWidth, barHeight);
offGraphics.setColor(Color.gray);
if (clipTotal > 0)
offGraphics.fillRect(startX, startY, (barWidth * clipsLoaded / clipTotal), barHeight);
offGraphics.setColor(Color.white);
offGraphics.drawRect(startX, startY, barWidth, barHeight);
offGraphics
.drawString(message, startX + 2 * fontWidth, startY + fontMetrics.getMaxAscent());
else
message = "Game Over";
offGraphics.drawString(message, (width - fontMetrics.stringWidth(message)) / 2, height / 4);
message = "'S' to Start";
offGraphics.drawString(message, (width - fontMetrics.stringWidth(message)) / 2, height / 4
+ fontHeight);
else if (paused)
offGraphics.setColor(Color.white);
message = "Game Paused";
offGraphics.drawString(message, (width - fontMetrics.stringWidth(message)) / 2, height / 4);
public String getTitle() {
System.out.print(title);
return title;
public void setTitle(String title) {
this.title = title;
}displayInfoScreen method in class A calls out for getTitle( ) to be displayed on an applet as an initial display string for the application.
The instance variable title is set by setTitle method which is called out in class testA as follow,
public class testA extends TestCase
* testASprite constructor comment.
* @param name
* java.lang.String
public testA(String name)
super(name);
* Insert the method's description here.
* @param args
* java.lang.String[]
public static void main(String[] args)
junit.textui.TestRunner.run(suite());
// need to figure out how to get rid of the frame in this test
System.exit(0);
public static Test suite()
return new TestSuite(testA.class);
* Basic create and simple checks
public void testCreate()
A theGame = new A();
assertNotNull("game was null!", theGame);
* Basic create and simple checks
public void testInit()
A theGame = new A();
Frame gameFrame = new Frame("THE GAME");
gameFrame.add(theGame);
int width = 640;
int height = 480;
gameFrame.setSize(width, height);
// must pack to get graphics peer
gameFrame.pack();
theGame.resize(width, height);
theGame.setTitle("TEST THE GAME");
theGame.init();
assertEquals("ASprite width not set", A.width, width);
gameFrame.dispose();
gameFrame.remove(theGame);
}Basically, class testA invokes the init( ) method in class A and start the applet application. However, it displays a white blank display. If I change the getTitle( ) in the displayInfoScreen method to a fixed string, it works fine. Did I forget anything as far as using getter & setter method? Do I have to specify some type of handle to sync between setter and getter between two classes? Any feedback will be greatly appreciated.
Thanks.Your class A extends runnable which leads me to believe that this is a multi-threaded application. In that case, title may or may not be a shared variable. Who knows? It's impossible to tell from what you posted.
Anyway, what is happening is that your applet is being painted by the JFrame before setTitle is called. After that, who knows what's happening. It's a complicated application. I suspect that if you called setTitle before you added the applet to the frame, it would work. -
How to display FileDialog in applet?
Hi all,
I looked FileDialog constructors but only Frame can be the owner of the dialog? Is there a way to do display it in applet?
Thank you.Try:
JOptionPane.getFrameForComponent(this);
Remember:
Applets need to be signed to access the file system. -
Why java only can display GIF file not jpeg and BMP ??
Did anyone know why java only can display GIF file not in jpeg and BMP ?? This is because the quality of GIS is not as good as Jpeg and BMP
any code to load the display process ??
thx guys !!!you can do jpegs but im not sure about bmps.
The only thing ive noticed is that java cant support transparent jpegs, only transparent gifs
Jim -
My 3gs won't flip into landscape display anymore. No problems with the portroit view.
My IOS is update.
ThanksSettings > General > Lock Rotation..
Or...
Double-press the home button...
Swipe to the right until you get to the Portrait Orientation Button...
If no joy...
Close All Open Apps... Perform a Reset... Try again...
Reset ( No Data will be Lost )
Press and hold the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears. Release the Buttons.
http://support.apple.com/kb/ht1430 -
Why display hanging and software problem when upgraded to ios 8
Why display hanging and software problem when upgraded to ios 8
Hi Redhazel,
Thank you for using Apple Support Communities.
To troubleshoot this issue where you're experiencing a poor image quality with your iPhone's camera, please follow the troubleshooting below.
Camera isn't functioning or has undesired image quality
If the screen shows a closed lens or black image, force quit the Camera app.
If you do not see the Camera app on the Home screen, try searching for it in Spotlight. If the camera does not show up in the search, check to make sure that Restrictions are not turned on by tappingSettings > General > Restrictions.
Ensure the camera lens is clean and free from any obstructions. Use a microfiber polishing cloth to clean the lens.
Cases can interfere with the camera and the flash. Try gently cleaning the lens with a clean dry cloth or removing the case if you see image or color-quality issues with photos.
Try turning iPhone off and then back on.
Tap to focus the camera on the subject. The image may pulse or briefly go in and out of focus as it adjusts.
Try to remain steady while focusing:
Still images: Remain steady while taking the picture. If you move too far in any direction, the camera automatically refocuses to the center.
Note: If you take a picture with iPhone turned sideways, it is automatically saved in landscape orientation.
Video: Adjust focus before you begin recording. You can also tap to readjust focus while recording. Exiting the Camera application while recording will stop recording and will save the video to the Camera Roll.
Note: Video-recording features are not available on original iPhone or iPhone 3G.
If your iPhone has a front and rear camera, try switching between them to verify if the issue persists on both.
iPhone: Hardware troubleshooting
Cheers,
Alex H. -
Mail and Safari dont display GIF images
After about a weeks worth of use, I realized that Safari and Mail dont display GIF images unless I download them and open them in Preview. Even then, I have to manually click each image to see the pictures motion. Sometimes in stead of the question mark, I will get the first picture of the sequence, but none more. Does anyone know how to fix this?
i dont have a solution, i just said it because i was tired of seeing it unanswered. Sorry, STILL haven't fixed this
-
InitialContext - Applet Problem
Hi,
When i try to get InitialContext from Applet ( running from appletviewer),
i'm hitting this error. Please help me to solve this problem
Exactly this line gives the error
InitialContext ic = new InitalContext ( hEnv )
Error:
javax.naming.NoInitialContextException: Cannot Instantiate class:
weblogic.jndi.WLInitialContextFactory
-regards
Abdul Malikyou can use applet to pull data periodically from the servlet.
mj
"Anthony A." wrote:
What if you want to perform some type of 'realtime' push from the server?
Anthony
"minjiang" <[email protected]> wrote in message
news:[email protected]...
why do you have to call your ejbs in applet directly? Why not use aservlet in
between?
The overhead of downloading so many so big jar files to the client machinewill
kill/time out any broswer http session.
mj
Abdul Malik wrote:
Dear Friends,
After 5 days of struggle, somehow i was managed to access the EJB from
Applet. But very slow coz of Big Jar files ( can make it bit small by
identitfying required classes ). I dont know this is correct approach
or
not, but works ( damn slow )
What i did was
1) Installed the Latest Plugin 1.3.1
2) Downloaded HTMLConverter tool from java.sun.com and converted my
html file to use plugin.
3) inlcuded few jar files in archive tag.
The files i added in archive tag is
1) myapplet.jar ( applet classes )
2) weblogicaux.jar ( !!!!!!!!!!!! quite big jar file )
3) weblogicclass.jar ( jarred all the classes from classes\weblogicfolder
(!!!!!!!!!! so big jar file !!!!!! )
4) myejb.jar ( suppose to work with home and remote class, but notworking
( looking for container generated files). so i added my EJB.jar file.dont
know why ?????????? )
then it works.
well, i am not happy with this kind of approach. if any body haveefficient
one, please kindly post it.
Note: i tried in 1.2.2 plugin ( works )
Environment: Windows 2000 / Windows 98, Weblogic 5.1 Service pack 7
-regards
Abdul Malik
"Daniel Hoppe" <[email protected]> wrote in message
news:[email protected]...
Anthony,
why should he place j2ee.jar in the applet classpath? Shouldn't be there
actually. Your problem seems to be related to a class which is not
serializable.
Daniel
-----Ursprüngliche Nachricht-----
Von: Anthony A. [mailto:[email protected]]
Bereitgestellt: Freitag, 22. Juni 2001 18:10
Bereitgestellt in: jndi
Unterhaltung: InitialContext - Applet Problem
Betreff: Re: InitialContext - Applet Problem
As a test, try to place the j2ee.jar and weblogic.jar in your
<archive tag>.
I have this code in my applet's init() method and it fails
due to a JMS
Exception.
I'm using BEA's web server, jndi server, and app server on
the same box as
the client.
Thanks,
Anthony
code:
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
ht.put(Context.PROVIDER_URL, "t3://anthony01:7001");
System.out.println("creating context");
InitialContext ctx = new InitialContext(ht);
error:
JMSException: weblogic.jms.common.JMSException:
java.rmi.MarshalException:
failed to marshal public abstract weblogic.jms.client.JMSConnection
weblogic.jms.frontend.FEConnectionFactoryRemote.createConnecti
on(weblogic.rj
vm.JVMID,weblogic.jms.client.JMSCallbackRemote) throws
javax.jms.JMSException,java.rmi.RemoteException; nested exception is:
java.io.NotSerializableException: weblogic.jms.client.JMSCallback -
Problem in displaying gif image on to the JFrame
i added gif image in to the jframe but when i run that image the image get distorted very much.
public class MyFrame extends JFrame
private static final String sIMAGE_PATH = "My\\Path\\To\\Image\\fileName.gif";
public MyFrame()
super("Frame with image on it");
init();
private void init()
JPanel panel = new JPanel(new BorderLayout());
ImageIcon image = new ImageIcon(sIMAGE_PATH);
JLabel label = new JLabel(image);
panel.add(label, BorderLayout.CENTER);
this.setContentPane(panel);
}Hope this helps.. -
Hello all!
I'll get right into my problem. I'm using netbeans 5.0 to do some Java at home along with my course at college. I'm currently working on an applet but am having some problems getting images to display, can anyone explain why I get the error:
"symbol : variable mygif1
location: class applet.SimpleApplet
g.drawImage(mygif1,20,20,this);
1 error"
When I compile the following:
import java.awt.Graphics;
import java.awt.Color;
import java.net.*;
import java.awt.*;
import java.applet.*;
import java.net.URL.*;
public class SimpleApplet extends Applet{
public void init() {
URL base;
Image mygif1;
setBackground(Color.white);
mygif1 = getImage(base,"Bumpo.gif");
public void paint(Graphics g){
g.drawImage(mygif1,20,20,this);
}Can anyone suggest why? I'm sure I have the file i refer to in the correct directory. Thanks in advance.
Message was edited by:
GlompThe problem isn't with the reference to the gif file. It's that mygif1 is a local variable in your init method, which means that it's not accessible in your paint method.
The solution is pretty simple. Make mygif1 a field of the class. Set its value in init, but don't declare it there.
It's usually a bad thing to use fields to pass values between methods, but in a case like this the image really is part of the state of the object. -
Ive tried to display an animated gif in an applet and it only shows the first frame. What is the code to do this and it be animated?
IIRC, every time you repaint the applet that contains the gif, the correct frame of the (multi-frame, animated) gif will be rendered.
So if you create a thread that just calls repaint() every half-second or so, you should see the gif move.
Usually it isn't necessary to do this explicitly, because there's already a thread updating state and repainting, for some other purpose. -
Safari on iPad does not display GIF image anymore after upgrade to iOS 4.3
1) Could anybody (especially those in Apple iOS or Safari teams) advise me why the Safari on my iPad cannot display some images (probably in GIF formats) on some webpages anymore, after I upgrade my iPad to iOS 4.3? These images on the webpages can be properly displayed on when my IPad runs with iOS 4.2.1. There should be no problem with these embedded image files because they can still be properly display in Safari running on my Macbook air.
2) Is there any solution to this problem?
3) Is it possible to downgrade my iPad back to iOS 4.2.1?I am having the same issue with two different ipads (one Wifi and one Wifi-3g) running on our home network (Verizon FIOS). The website in question is www.tvwc.com and the main logo in the upper left corner, a .gif, does not display, only a "?". Other images on the site, in .jpg format, display correctly.
I was running 4.2.1 and am now just upgrading to 4.3. -
hi every body.
I want to display images in an applet when i invoke it from the jsp page . it is not working. the code is as follows.
<html>
<body>
<jsp:plugin type = "applet"
code ="Welcome.class"
width="475" height = "350" >
</jsp:plugin>
</body>
</html>
while the code of "Welcome.java" is as follows.
ImageIcon image = new ImageIcon("aa.gif");
JButton button = new JButton(image);
i have placed the aa.gif file in the same directory where i placed the Welcome.class and the jsp file.
when i run this program the i recieve the message that the applet is not loaded.
can some body help me how to place images in applets.
thanks.You should be able to test that applet on you hard drive first. If it works check the case of the image file.
Web servers look for case. If you are asking for ImageIcon img = new ImageIcon("abc.gif") and what is loaded on your web server is "abc.GIF" it won't find it. Same goes for basic HTML tags like
<Img src=abc.gif>. But it will find it on you hard drive when you run the applet there. -
Canvas doesn't display in my applet
Hi all,
I have an program with different classes. One creates a Canvas component which is displayed in a container. It's working pretty well.
But when i execute my program using an applet this canvas is here but empty (without my drawing).
I'm using InternetExplorer 5.5 and the JRE1.1
Does somebody know why?
How could i solve my problem?
Thanks in advance.
ChrisDoes somebody can help me?
Hi all,
I have an program with different classes. One creates a Canvas component which is displayed in a >container. It's working pretty well.
But when i execute my program using an applet this canvas is here but empty (without my >drawing).
I'm using InternetExplorer 5.5 and the JRE1.1
Does somebody know why?
How could i solve my problem?
Thanks in advance.
Chris/////////////////////////// -
Hi all,
I am developing a web application in which I am drawing hundreds of applets, which will paint according to status, different colors (based on data feed), my problem is with JRE 1.4.04 the applet will change the color and display the string value without any hickup. But if I change the JRE to 1.4.5 or greater, it changes the color, the string may not draw on the applet!
Second issue is
Because some times the number applete on a browser may go beyond 500, while scrolling the browser it takes loong time to scroll.
Can some one tell me what I am doing wrong?\
Thanks
OnappingSorry, you have the wrong forum. This forum is focused on the Web Application Framework (JATO) and the Sun Java Studio Enterprise Tools module used to create WAF apps.
Although someone on this forum maybe able to help, you might have better success on a forum that is focused on applets and Java in general.
Maybe you are looking for
-
Hi All, I have 3 fields in my source file Id,Category (Key Mapping) ,Name. In Import Manager I have mapped Remote Key field with ID . Name with Name category with Category Qualified Range (A 1-10) I have source file like this Id name category 11 10
-
I have iTunes version 11.3.1.2 and a Windows 7 Professional aith Service Pack 1. When I try to print a CD cover from a disc I burned, I get an error message that stops the printing task and shuts down iTunes and tells me once the problem is found th
-
Installation Server Corruption when applying a Patch
I have setup a installation server with 7.10 gui. I have twice tried to apply a patch, the first time bw350gui710_1 patch, the second time was the gui710_4 patch. Both times my installation server was corrupted to the point where I had to delete it
-
Hi, I need a fm whic will read the sub-equipments currnetly dismanteled for a superior equipment. I am using tcode ieo2 and enhancement IEQM0003 Plz help
-
Removing specific element from a list
Hello, I'm very new to java, and to programming in general. I'm trying to write a secret santa app for my family for christmas. Essentially the idea is that 7 names are put into a list, and each time a name is "pulled" (i.e. randomly assigned to a na