Can someone help me to find how I cannot see the pictures in my
applet. I found that the paint is not working in the Canvas, even I have repainted it in the actionlistener.
Thx in advance
//======================================
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
public class Images extends JApplet
{
private int curr = 0;
private final int SIZE = 8;
private final int WIDTH = 640;
private final int LENGTH = 480;
private Image[] imgs = new Image[SIZE];
private Panel northPanel = new Panel();
private Panel southPanel = new Panel();
private Panel centerPanel = new Panel();
private JButton previousButton = new JButton("PREVIOUS");
private JButton nextButton = new JButton("NEXT");
private ShowPicture currPic;
public class ShowPicture extends Canvas
{
public void paint(Graphics g)
{
g.drawImage(imgs[curr], 0, 0, this);
}
public ShowPicture()
{
}
}
public void init()
{
for (int i = 0; i < SIZE ;i++ )
{
imgs[i] = getImage(getDocumentBase(),
"image00" + (i + 1) + ".jpg").getScaledInstance(
WIDTH,LENGTH,Image.SCALE_SMOOTH);
}
curr = 0;
getContentPane().setLayout(new BorderLayout());
currPic = new ShowPicture();
centerPanel.setBackground(Color.lightGray);
centerPanel.add(currPic);
nextButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
curr = curr + 1;
curr = curr % SIZE;
showStatus("Current image is " + "image00" + (curr + 1) + ".jpg");
currPic.repaint();
}
});
previousButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
curr = curr - 1;
if (curr < 0)
{
curr += SIZE;
}
curr = curr % SIZE;
showStatus("Current image is " + "image00" + (curr + 1) + ".jpg");
currPic.repaint();
}
});
southPanel.add(previousButton);
southPanel.add(nextButton);
getContentPane().add(southPanel, "South");
getContentPane().add(centerPanel, "Center");
setVisible(true);
}
}