Hi all,
I was wondering whether anyone else has come across this problem. It's driving me crazy and I have googled till I've developed callouses, with no luck.
Basically, I am creating a java application. I started out initially coding in Netbeans but then discovered that it was difficult to integrate custom code into Netbeans. So, I switched to using JGrasp, which allows for custom coding, however, I copied the grouplayout framework that I constructed in Netbeans, into JGrasp. So far so good. My program works perfectly on two home desktop computers, running XP Professional Service Pack 2, and on a laptop running Vista. I am using jre and jdk version 6u20.
However, when I run the program on the computers at University, where it needs to work, the program runs with a glitch. The computers there have XP Professional Service Pack 3.
The GUI displays an initial random image, taken from a MS Access 2007 database, and displays it in a JPanel. The button "next button" needs to be pressed in order for the next image to appear in the JPanel. Like I said, this works except at University. On the University computers, the initial image appears and then is immediately overpainted by the next random image, which should only happen when the "next image" button is pressed. The rest of the program is stable. It is only the initial loading of the image that causes a problem.
I have made the main JFrame undecorated. If I let the JFrame be decorated then I have the same glitch occurring on my desktop computer at home.
I am inserting the relevant code:
This is the class that is responsible for painting the image:
public class PhotoPanel extends JPanel
{
private BufferedImage bi;
private URL imageSrc;
private String name;
private int count = 0;
private double len;
private double temp;
private int check = 0;
MainMenu parent = null;
public PhotoPanel()
{
}
public PhotoPanel(MainMenu m)
{
parent = m;
}
public BufferedImage source()
{
imageSrc = null;
try {
Image i = new Image();
String name = i.image(); // getting name of image from
// database
final ClassLoader loader = this.getClass().getClassLoader();
imageSrc = loader.getResource(name);
bi = ImageIO.read(imageSrc);
len = bi.getWidth();
if (len > 1800.5) temp = 0.08;
else temp = 0.2;
}
catch (MalformedURLException e) {
}
catch (IOException e){}
return(bi);
}
@Override
public void paintComponent(Graphics g)
{
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.drawImage(source(), AffineTransform.getScaleInstance(temp,temp), null);
}
}
This is how I call this class from my main menu class:
private JPanel photo = new PhotoPanel(this);
And this is the code for my repaint in my main menu class:
public void actionPerformed(ActionEvent e)
{
String buttonString = e.getActionCommand();
if (buttonString.equals("Next Face"))
{
photo.revalidate();
photo.repaint();
}
Sorry for the long post. Please help. Thanks