Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / May 2004

Tip: Looking for answers? Try searching our database.

JApplet problem: IllegalAccessException

Thread view: 
Stuart Leonard - 29 May 2004 03:07 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 ""

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.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.