I am developing a GUI in NetBeans that is for changing the settings.
one setting is a username and password.
once the user has inputed a username and password it needs to show a GIF image which is a loading kinda circle thing that goes around i don't have a problem with knowing when to show the image and start the request it is just the showing the image bit at the moment i have this code:
public ConfigGUI() {
initComponents();
center();
System.out.println("Loading image");
Graphics loginGraphics = loginPane.getGraphics();
LoadImageApp image = new LoadImageApp("resources/strawberry.jpg");
loginGraphics.drawImage(image.img, 1, 1, null);
loginPane.repaint();
loginPane.setVisible(true);
System.out.println("Image loaded");
}
/* image class */
public class LoadImageApp extends Component {
BufferedImage img;
//@Override
public void paint(Graphics g) {
g.drawImage(img, 0, 0, null);
}
public LoadImageApp(String filename) {
try {
img = ImageIO.read(new File(filename));
} catch (IOException e) {
System.out.println("Failed to load image");
}
}
//@Override
public Dimension getPreferredSize() {
if (img == null) {
return new Dimension(100, 100);
} else {
return new Dimension(img.getWidth(null), img.getHeight(null));
}
}
}
but it doesn't work.
am i using the right kind of components or do i need to use something other than a JPane?
and what code should i be using to output the image?
Scott.