Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Image problems

  Asked By: Jose    Date: Mar 30    Category: Java    Views: 381
  

Im developing a little 8-ball program in Java, and i've got a problem
loading an image onto a panel; heres the code:

import java.io.*;
import java.net.*;
import javax.imageio.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Magic8Ball {

public static void main(String[] args) {
Magic8BallFrame frame = new Magic8BallFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
} //Fin de Main


} //Final de Clase Magic8Ball


class Magic8BallFrame extends JFrame {

public static final int DEFAULT_WIDTH = 300;
public static final int DEFAULT_HEIGHT = 200;

//Constructor
public Magic8BallFrame()
{
setTitle("Geeky Magic 8-Ball"); //Pon el título que quieras
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);

//Instanciamos el panel
Magic8BallPanel panel = new Magic8BallPanel();

//Agregamos el Panel al frame
Container contentPane = getContentPane();
contentPane.add(panel);
}

} //Final DrawFrame


class Magic8BallPanel extends JPanel {

private int mensajeX;
private int mensajeY;
private Image image;

public void paintComponent(Graphics g)
{
mensajeX = 75;
mensajeY = 100;

//Como siempre, inicia con la llamada al padre de JPanel
super.paintComponent(g);

//Busquemos y dibujemos la imagen, arroja IOException
Toolkit toolkit = Toolkit.getDefaultToolkit();
image = toolkit.getImage("8-ball.jpg");
g.drawImage(image, 0, 0, null);


} //Fin de paintComponent
} //Fin de clase Magic8BallPanel


When i run it i dont get any problems, nevertheless i cant see
anything in the panel :S. I'm running a JSDK 1.4 under Suse linux 9.0
and the program has complete privileges over the folder... what am i
doing wrong? why cant Java find my little image?

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on Image problems Or get search suggestion and latest updates.




Tagged: