I am receiving the following error when trying to load an applet.
IllegalAccessException: Class sun.applet.AppletPanel can not access a member
of class TempConvert with modifiers ""
I have SDK/JRE 1.4.0 installed, and I am using Windows XP Professional.
Thanks for any help!
The source code follows:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.text.DecimalFormat;
public class TempConvert extends JApplet {
public JFormattedTextField low;
public JFormattedTextField high;
public JFormattedTextField incr;
public TempConvert() {
getContentPane().setLayout(new BorderLayout());
createGrid();
}
private void createGrid() {
JPanel panel = new JPanel(new BorderLayout());
// add selection panel
low = new JFormattedTextField(new DecimalFormat("####"));
high = new JFormattedTextField(new DecimalFormat("####"));
incr = new JFormattedTextField(new DecimalFormat("###"));
JPanel select = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.NONE;
addgbc(select, new JLabel("Low Temperature Range . . ."),gbc,0,0);
addgbc(select, low,gbc,1,0);
addgbc(select, new JLabel("High Temperature Range . ."),gbc,0,1);
addgbc(select, high,gbc,1,1);
addgbc(select, new JLabel("Increment Degrees . . . . ."),gbc,0,2);
addgbc(select, incr,gbc,1,2);
panel.add(select, BorderLayout.NORTH);
// add temperature list
final JList list = new JList();
JScrollPane scroller = new JScrollPane();
scroller.getViewport().add(list);
panel.add(scroller, BorderLayout.CENTER);
// add buttons
JPanel buttons = new JPanel(new FlowLayout(FlowLayout.CENTER,5,5));
JButton ok = new JButton("OK");
JButton cancel = new JButton("Cancel");
panel.add(buttons, BorderLayout.SOUTH);
getContentPane().add(panel);
// register action listeners for the buttons
ok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (verifyData())
{
list.setListData(calculateTemps());
list.revalidate();
list.repaint();
}
}
});
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
}
private int getIntValue(JFormattedTextField field)
{
return ((Number)field.getValue()).intValue();
}
private boolean verifyData()
{
int lowTemp = getIntValue(low);
int highTemp = getIntValue(high);
int incrTemp = getIntValue(incr);
if (lowTemp < 0)
{
JOptionPane.showMessageDialog(this, "If low temperature is entered, must
be greater than zero");
return false;
}
if (highTemp == 0)
{
JOptionPane.showMessageDialog(this, "High temperature must be entered");
return false;
}
if (highTemp <= lowTemp)
{
JOptionPane.showMessageDialog(this, "High temperature must be greater
than low temperature");
return false;
}
if (incrTemp == 0)
{
JOptionPane.showMessageDialog(this, "Increment degrees must be
entered.");
return false;
}
return true;
}
private void addgbc(Container cont, JComponent comp, GridBagConstraints
gbc, int x, int y) {
gbc.gridx=x; gbc.gridy=y;
cont.add(comp,gbc);
}
private TempData[] calculateTemps() {
int lowTemp = getIntValue(low);
int highTemp = getIntValue(high);
int incrTemp = getIntValue(incr);
int range = highTemp-lowTemp;
TempData[] tempdata = new TempData[range/incrTemp +1];
int j=0;
for (int i=lowTemp; i<=highTemp; i+=incrTemp) {
tempdata[j] = new TempData(i);
j++;
}
return tempdata;
}
public class TempData {
int fahrenheit;
int celsius;
public TempData(int fahrenheit) {
this.fahrenheit = fahrenheit;
calculateTemp();
}
private void calculateTemp() {
celsius = ( 5/9 ) * ( fahrenheit-32);
}
public String toString() {
return fahrenheit + "\t" + celsius;
}
}
}
Roedy Green - 29 May 2004 03:14 GMT
>I am receiving the following error when trying to load an applet.
>IllegalAccessException: Class sun.applet.AppletPanel can not access a member
>of class TempConvert with modifiers ""
That is similar to
http://mindprod.com/jgloss/errormessages.html/ILLEGALACCESSERROR
except using reflection.
It likely has similar causes.

Signature
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.