Here is my DescriptivePanel class
import javax.swing.*;
import java.awt.*;
public class DescriptionPanel extends JPanel
{
//Label for displaying an image icon and info
private JLabel jlblImageTitle = new JLabel();
//Test area for displaying text
private JTextArea jtaDescription = new JTextArea();
//Label properties
public DescriptionPanel()
{
//Center the icon/text and place the text under the icon
jlblImageTitle.setHorizontalAlignment(JLabel.CENTER);
jlblImageTitle.setHorizontalTextPosition(JLabel.CENTER);
jlblImageTitle.setVerticalTextPosition(JLabel.BOTTOM);
//Set the font in the label/text field
jlblImageTitle.setFont(new Font("SansSerif", Font.BOLD, 16));
jtaDescription.setFont(new Font("Serif", Font.PLAIN, 14));
//Set linewrap/wrapStyleWord true for the text area
//Wrapping Line
jtaDescription.setLineWrap(true);
//Wrapping Word
jtaDescription.setWrapStyleWord(true);
//Read only
jtaDescription.setEditable(false);
//Create a scroll pane to hold the text
JScrollPane scrollPane = new JScrollPane(jtaDescription);
//Set BorderLayout for the panel/add label and scrollpane
setLayout(new BorderLayout(5, 5));
add(scrollPane, BorderLayout.CENTER);
add(jlblImageTitle, BorderLayout.WEST);
}
//The title
public void setTitle(String title)
{
jlblImageTitle.setText(title);
}
//The Image Icon
public void setImageIcon(ImageIcon icon)
{
jlblImageTitle.setIcon(icon);
}
//The description section
public void setDescription(String text)
{
jtaDescription.setText(text);
}
}
And here is my national flag program.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class NationalFlag extends JApplet implements ActionListener
{
//Description panel to display all information
private DescriptionPanel infoPanel = new DescriptionPanel();
//Declarations
private int totalCountries = 0;
private ImageIcon[] imageIcon;
private String[] text;
private String[] name;
int current = 0;
private Timer timer = new Timer(15000, this);
//Initializing the applet
public void init()
{
//Get the total countries parameter from the HTML page
totalCountries = Integer.valueOf(getParameter("Countries")).intValue();
System.out.println("Students " + totalCountries);
//Create arrays for imageIcon, text and name
imageIcon = new ImageIcon[totalCountries];
text = new String[totalCountries];
name = new String[totalCountries];
//Initialize text, name and imageIcon
for (int i = 0; i < totalCountries; i++)
{
text[i] = getParameter("Description" + i);
name[i] = getParameter("Name" + i);
imageIcon[i] = new ImageIcon(getClass().getResource("C:\\Users\\Christopher\\Desktop\\CIS111\\evennumberedexercise\\evennumberedexercise\\image\\flag" + i + ".gif"));
}
//Set applet layout and add text area and panel
getContentPane().add(infoPanel, BorderLayout.CENTER);
show(current % totalCountries);
//Starting the program
timer.start();
}
//Start Timer
public void start()
{
timer.start();
}
//Stop Timer
public void stop()
{
timer.stop();
}
//Run a slide show
public void actionPerformed(ActionEvent e) {
current = current + 1;
//Showing current slide
show(current % totalCountries);
}
//Display information
private void show(int current)
{
//Show text
infoPanel.setDescription(text[current]);
//Show name
infoPanel.setTitle(name[current]);
//Show imageIcon
infoPanel.setImageIcon(imageIcon[current]);
}
}
When I run it, the applet viewer pops up, but at the bottom, it says "Start: applet not initialized", and "Applet" at the top in the white. This is what my run i/o has in it when I run it,
----jGRASP exec: appletviewer jgrasphta.htm
java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Integer.java:415)
at java.lang.Integer.valueOf(Integer.java:553)
at NationalFlag.init(NationalFlag.java:28)
at sun.applet.AppletPanel.run(AppletPanel.java:417)
at java.lang.Thread.run(Thread.java:619)
----jGRASP: operation complete.
Any ideas???

New Topic/Question
Reply



MultiQuote








|