Hi All,
I have two major problems and they may or may not be linked. My main problem is with an application that I am creating. So far, I have only created the GUI using Netbeans 6.8. When I run the app through Netbeans then everything works fine. However, when I run the jar file through the command line I have problems. The initial image, in the main menu, flickers once and then disappears. If I press the "next image" button, however, the following images stabilize. But if I open up a new window, again, the image flickers, in that new window, and then disappears. The images in the main menu below, however, are still stable. So, it seems to be just an initial reaction. The other strange thing is that the program reacts differently on different machines. On my desktop this is what happens (Windows XP OS). On the university desktop the image in the main menu flickers once and then disappears but the images in the other windows are stable (Windows XP OS). On a laptop with Vista OS all the images are stable but the menus seem to overlap one another. On a laptop with Ubuntu the whole application works fine.
If I add a wait, on my machine, then the image stays there for the duration of the wait. However, I cannot use a wait as the GUI is interactive and the user needs to be able to do things when they want to and not be locked out of the GUI whilst waiting. I also added a -Dsun.java2d.noddraw=true flag, on my machine, which stabilized the images but caused the main menu to minimize to the taskbar when a button, which opened a new window, was pressed. After the new window was disposed of you have to manually restore the main menu window to its position from the taskbar. Which is, of course, totally useless. I struggled to find any posts addressing this issue though I did see posts that said that you should override paintComponent for swing and not paint. I tried doing this however, Netbeans 6.8 gives me the error message "Cannot find symbol: super.paintComponent(java.awt.Graphics) Location:javax.swing.JFrame" And yes, I have imported all the correct packages. So my questions are:
1. Do you have an answer for why the images flicker once and then disappear- and a solution
2. If you think that the problem does lie with paintComponent not being used then how do I get Netbeans to recognize the super.paintComponent(g) command?
I am posting some code to illustrate what I have done:
public void source(Graphics g)
{
imageSrc = null;
try {
Name(); // Gets the String for the URL
imageSrc = ((new File(getName())).toURI()).toURL();
bi = ImageIO.read(imageSrc);
len = bi.getWidth();
if (len > 1800.5) temp = 0.08; // works out ratio for scaling image down
else temp = 0.2; // to - images are too large for JPanel
g = PhotoPanel.getGraphics();
Graphics2D g2 = (Graphics2D) g;
g2.drawImage(bi, AffineTransform.getScaleInstance(temp,temp), null);
}
catch (MalformedURLException e) {
}
catch (IOException e){}
}
@Override
public void paint(Graphics g)
{
super.paint(g);
source(g);
}
This is really urgent and any help would be greatly appreciated.
Thanks in advance. :)