My program complies fine but whenever I run it the applet loads but its blank and at the bottom it gives me Applet Not Initialized. I have no idea whats causing this if someone could help me out would be greatly appreciated.
The Errors im getting are:
at javax.swing.ImageIcon.(init)(ImageIcon.java:167)
at TourPanel.(init)(tour.java:52)
at Tour.init(tour.java:12)
at sun.applet.AppletPanel.run(AppletPanel.java:424)
at java.lang.Thread.run(Thread.java:619)
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.net.*;
public class Tour extends JApplet
{
public void init()
{
add(new TourPanel());
}
}
class TourPanel extends JPanel
{
private JPanel panel, buttonPanel, centerPanel;
private JButton next, prev;
private int numImages = 5;
private int currentImage = 0;
private ImageIcon[] pics = new ImageIcon[numImages];;
public TourPanel()
{
panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.setBackground(Color.blue);
add(panel);
buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(1,2,15,15));
buttonPanel.setBackground(Color.red);
ButtonHandler bHandler = new ButtonHandler();
prev = new JButton("<< Previous Image");
prev.addActionListener(bHandler);
buttonPanel.add(prev);
next = new JButton("Next Image >>");
next.addActionListener(bHandler);
buttonPanel.add(next);
panel.add(buttonPanel, BorderLayout.SOUTH);
for(int x = 0; x < numImages; x++)
{
URL url = this.getClass().getResource("image/pic" + x + ".jpg");
pics[x] = new ImageIcon(url);
}
}
private class ButtonHandler implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String cmd = e.getActionCommand();
if (cmd.equals("<< Previous Image") && currentImage > 0)
{
currentImage--;
}
else if (cmd.equals("Next Image >>") && currentImage < numImages -1)
{
currentImage++;
}
repaint();
}
}
public void paintComponent(Graphics g)
{
Dimension d = getSize();
g.drawImage(pics[currentImage].getImage(), 50, 70, d.width/2, d.height/2, this);
repaint();
}
}
My HTML file is:
<html>
<! NOTE - html code for Tour.java>
<head>
<title>Tour</title>
</head>
<body>
<applet code=Tour.class width=800 height=800>
</applet>
</body>
</html>