Re: program works but wont display in browser



It works right but buttons dont display until I move mouse over them and the
main problem Iam having is when I upload WebApplet.class to server and try
and display in web page I get a

exception: java.lang.nullPointerException error and the applet will not
load. Not sure why this is happening.

Thank You,
Andy

//Web Page
//By: Andrew Titus
//Date 2-26

//import java.applet.Applet;
import javax.swing.JApplet;
import java.awt.Event;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.util.*;
import java.awt.*;
import javax.swing.ImageIcon;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JButton;



public class WebApplet extends JApplet
{

private JButton previous,next;
private JPanel buttonPanel;
Image coolImage[] = new Image[5];
Font title,documentText;
int i = 0;

String[] names = {"StBasials1.jpg", "museum9.jpg", "Red_Square9.jpg",
"StBasials8.jpg",
"Russian_Soilders_in_Formation.jpg" };


public void init()
{
previous = new JButton("Previous");
next = new JButton("Next");

for(int j=0; j<names.length;j++) {
coolImage[j] = getImage(getCodeBase(),names[j] );
}


ButtonListener listener = new ButtonListener();
previous.addActionListener(listener);
next.addActionListener(listener);

buttonPanel = new JPanel();

buttonPanel.add(previous);
buttonPanel.add(next);
add(buttonPanel);
} // end init()

public void paint(Graphics page){


setBackground(Color.black);


title = new Font("Jokerman",Font.BOLD,(int)(getHeight()*0.02) );
documentText = new Font("Courier New",Font.BOLD,(int)(getHeight()*0.02) );

//set color for text
page.setColor(Color.white);
page.setFont(title);


page.setFont(documentText);

page.drawImage(coolImage[i],30,60,this);


} //end paint()

private class ButtonListener implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
if(event.getSource() == next){
i++;
repaint();
}
if(event.getSource() == previous) {
i--;
repaint();
}
}

}


} //end webApplet
.


Quantcast