[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Java Compatability

Posted on 2006-04-13
19
Medium Priority
?
221 Views
Last Modified: 2013-11-23
Reference:

http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21808834.html#16444194


This problem is still not fixed, the user is using Mac OS X. I've recompiled the applet as a whole new project and still he has this problem. Here is the HTML code I am using to display the applet.

<HTML>
<HEAD>
   <TITLE>Applet HTML Page</TITLE>
</HEAD>
<BODY>
<P>
<APPLET codebase="classes" code="drMathDesign.class" width=650 height=500></APPLET>
</BODY>
</HTML>



Do I have to include the JAR archive in this line? It works on Windows No Problem: it is compiled with the JDK 1.2 and still does not work on mac....I cant figure this out.
0
Comment
Question by:BrianGEFF719
19 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16449587
>>and still does not work on mac...

What is the error?
0
 
LVL 19

Author Comment

by:BrianGEFF719
ID: 16449640
java.lang.UnsupportedClassVersionError: mathDesign  (Unsupported major.minor version 49.0)
      at java.lang.ClassLoader.defineClass0(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:539)
      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:123)
      at sun.applet.AppletClassLoader.findClass(AppletClassLoader.java:157)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
      at sun.applet.AppletClassLoader.loadClass(AppletClassLoader.java:123)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
      at sun.applet.AppletClassLoader.loadCode(AppletClassLoader.java:561)
      at sun.applet.AppletPanel.createApplet(AppletPanel.java:633)
      at sun.plugin.AppletViewer.createApplet(AppletViewer.java:1970)
      at sun.applet.AppletPanel.runLoader(AppletPanel.java:562)
      at sun.applet.AppletPanel.run(AppletPanel.java:299)
      at java.lang.Thread.run(Thread.java:552)




The same error as before. The applet has been compiled with JDK 1.2
0
 
LVL 19

Author Comment

by:BrianGEFF719
ID: 16449698
Here is the full applet code:

import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.FontMetrics;
import java.awt.Font;

public class drMathDesign extends JApplet implements ActionListener
{
   
 JMenuItem fMenuLoad;
 
  JPanel design_panel;
     JPanel line_panel;
       JButton drawLineButton;
       TextField txtFillChar;
       JComboBox cmbLineType;
     JPanel label_panel;
       JButton insertLabelButton;
       TextField txtStartLabel;
       
  JPanel status_panel; /* not contained in design panel */
     JLabel status_label;
 
  JPanel textarea_panel;
     JTextArea txtCanvas;
     JLabel about_label;
     TextArea txtDebug;
 
     
 /* public variables */  
   
   boolean allowedToDraw = false;
   boolean drawingLine = false;
   boolean drawingLabel = false;
   int drawingObject = 0;
   int drawStartRow = 0;
   int drawStartCol = 0;
   char charLabel = 'A';
   int numRows = 25;
   int numCols = 75;
   int textWidth;
   int textHeight;
   char myCanvas[][] = new char [numRows][numCols];
   char myTmpCanvas[][] = new char [numRows][numCols];
   String lastAction; /* this is used to save the mathDesign tags */
   
  public void init ()
  {
   
    /* create menu system */
        JMenuBar mb = new JMenuBar ();
        JMenu m = new JMenu ("File");
        fMenuLoad =  new JMenuItem ("Load Saved Design");
        m.add (fMenuLoad);
        fMenuLoad.setEnabled(false);
        fMenuLoad.addActionListener (this);
        mb.add (m);
        setJMenuBar (mb);
    /* end create menu system */

    Container content_pane = getContentPane ();
    content_pane.setLayout (new BoxLayout(content_pane,BoxLayout.Y_AXIS));
   
    /* create deisgn panel */
    design_panel = new JPanel();
    /* end design panel */
   
   
   
    /* create panel for lines */
    line_panel = new JPanel ();
    drawLineButton = new JButton("Draw Line");
 
    line_panel.add(drawLineButton);
    JLabel fillLabel = new JLabel ("Fill Charecter: ");
    line_panel.add(fillLabel);
   
    txtFillChar = new TextField(1);
    txtFillChar.setText("*");
    line_panel.add(txtFillChar);
   
    JLabel lineType = new JLabel ("Line Type: ");
    cmbLineType = new JComboBox ();
    cmbLineType.addItem("Thin Line");
    cmbLineType.addItem("Thick Line");
   
    line_panel.add(lineType);
    line_panel.add(cmbLineType);
    //line_panel.setAlignmentX(line_panel.LEFT_ALIGNMENT);
    design_panel.add (line_panel); /* add to design panel */
    /* end panel for lines */
   
    /* create panel for labels */
    label_panel = new JPanel();
    insertLabelButton = new JButton("Insert Label");
    JLabel charLabel = new JLabel ("Start Label: ");
    txtStartLabel = new TextField(1);
    txtStartLabel.setText("A");
    label_panel.add(insertLabelButton);
    label_panel.add(charLabel);
    label_panel.add(txtStartLabel);
    design_panel.add(label_panel); /* add to design panel */
    design_panel.setLayout(new BoxLayout(design_panel, BoxLayout.X_AXIS));
    /* end panel for labels */
   
    /* finally add design panel to content pane */
    content_pane.add(design_panel);
   
    /* now we are going to create a status panel that contains a status Label. */
    status_panel = new JPanel();
    status_label = new JLabel();
    JLabel stat = new JLabel ("Status: ");
    status_panel.add(stat);
    status_panel.add(status_label);
    status_panel.setLayout(new FlowLayout(0,15,0));
    /*add status panel to content pane */
    content_pane.add(status_panel);
   
    /* now create our text area canvas */
    textarea_panel = new JPanel();
    about_label = new JLabel("Ask Dr. Math Graphic Designer. Written by XXXXXX");
    txtCanvas =  new JTextArea("Loading...", numRows+2,  numCols+2 );
    txtDebug = new TextArea("-------DEBUG------\n",20,numCols + 2, TextArea.SCROLLBARS_VERTICAL_ONLY);
    textarea_panel.add(txtCanvas);
    textarea_panel.add(about_label);
    textarea_panel.add(txtDebug);
   
    //set visibility of txtDebug
    txtDebug.setVisible(true);
   
    content_pane.add(textarea_panel);
   
    /* set txtCanvas font and get font metrics */
    txtCanvas.setEditable(false);
    txtCanvas.setFont(Font.decode("Monospaced"));

      /* get font metrics */
      FontMetrics currentMetrics = getFontMetrics(Font.decode("Monospaced"));
      textWidth = currentMetrics.charWidth('A');
      textHeight = currentMetrics.getHeight();
      /* end get font metrics */
   
    /* done with text area canvas */
   
    /* add all our listeners */
      txtCanvas.addMouseListener( new myMouseListner() );
      txtCanvas.addMouseMotionListener(new myMouseMotion() );
      insertLabelButton.addActionListener(new insertLabelListner() );
      drawLineButton.addActionListener(new drawLineListner( ));
     
    //now do all initilization code:
    clearCanvas(myCanvas,numRows,numCols);
    copyCanvas(myTmpCanvas,myCanvas,numRows,numCols);
    displayCanvas(myCanvas,numRows,numCols);
   
    setStatus("Ready to design...");
   
  }

  private void setStatus(String txt)
  {
    status_label.setText(txt);
    status_label.repaint();
  }
 
 
  /** Get the menu events here.  **/
  public void actionPerformed (ActionEvent e) {
    String command = e.getActionCommand ();
    if (command.equals ("Load Saved Design"))
        {
                //do something to load the designs
        }
  } // actionPerformed

   private void displayCanvas(char theCanvas[][],int r,int c)
   {
       StringBuffer tmp = new StringBuffer();
         for (int i = 0; i < (r);++i )
         {
             tmp.append(theCanvas[i]).append("\n"); //took out \n in second append.
          }
     
       txtCanvas.setText(tmp.toString());
   }
   
  private void a(MouseEvent m)
  {
        StringBuffer tmp = new StringBuffer();
         int xpos = m.getX();
         int ypos =m.getY();
         int row = getRow(m);
         int col = getCol(m);
         
         tmp.append(xpos);
         tmp.append(",");
         tmp.append(ypos);
         tmp.append("(");
         tmp.append(row);
         tmp.append(",");
         tmp.append(col);
         tmp.append(")");
     
         setStatus(tmp.toString());
     
  }
 
  private void addDebug(String txt)
  {
      txtDebug.append(txt);
      txtDebug.repaint();
  }
   private void clearCanvas(char theCanvas[][],int r, int c)
   {
          for (int i = 0; i < (r); ++i )
          {
            for (int j = 0; j < (c); ++j )
            {
                    theCanvas[i][j] = ' ';
            }
          }
   }
   
   /* ASSUMES BOTH ARRAYS HAVE THE SAME SIZE!!!!!! */
   private void copyCanvas(char dest[][], char from[][], int r, int c)
   {
         for (int i = 0; i < (r); ++i )
          {
            for (int j = 0; j < (c); ++j )
            {
                dest[i][j] = from[i][j];
            }
          }
             
   }
   
   private int getRow(MouseEvent m)
   {
       int y = m.getY();
       int row = 0;
       if (textHeight!=0)
        row = y/textHeight;
       return row;
   }
   
   private int getCol(MouseEvent m)
   {
       int x = m.getX();
       int col = 0;
       if (textHeight!=0)
        col = x/textWidth;
       return col;
   }
    class myMouseListner implements MouseListener
   {
    public void mouseClicked (MouseEvent me)
    {
        //a(me);
        if (allowedToDraw)
        {
            if (drawingObject == 1)
            {
                if (!drawingLine)
                {
                   drawingLine = true;
                   drawingObject = 1;
                   drawStartRow = getRow(me);
                   drawStartCol = getCol(me);
                   setStatus("When you are satisfied with the line displayed click again.");
                }
                else
                {
                    allowedToDraw = false;
                    drawingObject = 0;
                    drawingLine = false;
                    //copy temp canvas to perm canvas
                    copyCanvas(myCanvas,myTmpCanvas,numRows,numCols);
                    displayCanvas(myCanvas,numRows,numCols);
                    setStatus("Drawing Line Completed!");
                    addDebug(lastAction);
                }
            }
            if (drawingObject == 2)
            {
                drawingObject = 0;
                allowedToDraw= false;
                drawingLabel = false;
                int Row = getRow(me);
                int Col = getCol(me);
                copyCanvas(myCanvas,myTmpCanvas,numRows,numCols);
                displayCanvas(myCanvas,numRows,numCols);
                setStatus("Label was inserted!");
                addDebug("<object type=label coord={" + Row + "," + Col + "} value=" + charLabel + ">\n");
     
            }
       
        }
   
    }
    public void mousePressed (MouseEvent me) {}
    public void mouseReleased (MouseEvent me) {}  
    public void mouseEntered (MouseEvent me) {}
    public void mouseExited (MouseEvent me) {}
   }
 
  private void drawLine(char c[][],int r1, int c1, int r2, int c2, char fillChar[],int lineType)
  {
      if((c1-1)> numCols ||(c2-1) > numCols)
          return;
         
      lastAction = "<object type=line coord={" + r1 + "," + c1 + "," + r2 + "," + c2 + "} fill=" + fillChar[0] + " type=" + lineType + ">";
      float deltaC = (c2 - c1);
      float deltaR = (r2 - r1);
     
        if (deltaC == 0 && deltaR == 0)
        {
          /* single point */
          c[r2][c2] = fillChar[0];  
        }
        else if (deltaC == 0)
        {
          /* vertical line */
          int start = (r2<r1)?r2:r1;
          int end = (r2<r1)?r1:r2;
          for (int i = start; i < (end + 1); ++i)
            if (i < numRows)
                    c[i][c1] = fillChar[0];
        }
        else if (deltaR == 0)
        {
          /* horizontal line */
          int start = (c2<c1)?c2:c1;
        int end = ((c2<c1)?c1:c2);
         for (int i = start; i < (end + 1); ++i)
           {
              if (i < (numCols))
               c[r1][i] = fillChar[0];
           }
        }
        else
        {
          /* non zero slope */
          int type = 2;
          int cCol = 0;
          int cRow = 0;
          int endCol = 0;
          float colInc = 1;
         
          if ( (deltaR < 0) && (deltaC < 0) )      {
            deltaR *= -1; deltaC *= -1;
            cCol = c2;
            cRow = r2;
            endCol = c1;
            colInc = 1;
          }
        else if (deltaR > 0 && deltaC > 0) {
            cCol = c1;
            cRow = r1;
            endCol = c2;
            colInc = 1;
        }
        else if (deltaR < 0 && deltaC > 0) {
            deltaR *= -1;
            cRow = r1;
            cCol = c1;
            endCol = c2;
            colInc = -1;      
        }
          else if (deltaR > 0 && deltaC < 0) {
            deltaC *= -1;
            cRow = r2;
            cCol = c2;
            endCol = c1;
            colInc = -1;
        }      
         
          float cycle = (deltaC/2);
                do
            {
                  cycle+=deltaR;
                  if (lineType==1) //thick
                            c[cRow][cCol] = fillChar[0];
                  else if(lineType==2) //thin
                  {
                        if (cycle>deltaC)
                           c[cRow][cCol] = fillChar[0];                              
                  }
                              
                  cCol++;
                              
                  if (!(cycle<deltaC))
                  {
                        cRow+=colInc;
                        cycle-=deltaC;
                  }
            } while (cCol < endCol);
         
        }
     
  }
 
  class drawLineListner implements ActionListener
   {
      public void actionPerformed(ActionEvent event)
      {
          setStatus("Ready to draw line, click a point to start drawing.");
          allowedToDraw = true;
          drawingObject = 1;
      }                  
   }
     
 class insertLabelListner implements ActionListener
   {
      public void actionPerformed(ActionEvent event)
      {
          setStatus("Ready to draw label, click where you are happy with the label.");
          allowedToDraw = true;
          drawingObject = 2;
          drawingLabel = true;
          charLabel = txtStartLabel.getText().toCharArray()[0];
      }
   }
 
  class myMouseMotion implements MouseMotionListener
  {
      public void mouseMoved(MouseEvent me)
      {
          // a(me);
           
          if (allowedToDraw)
           {
            int row = getRow(me);
            int col = getCol(me);
           
            if (drawingLine == true)
            {
                int typeOfLine = 2; /* default to thin */
                String t = (String)cmbLineType.getSelectedItem();
               
                if (t == "Thin Line")
                    typeOfLine = 2;
                else if (t == "Thick Line")
                    typeOfLine = 1;
               
                //copy canvas and display a preview line.              
                copyCanvas(myTmpCanvas,myCanvas,numRows,numCols);
                drawLine(myTmpCanvas,drawStartRow, drawStartCol, row,col,txtFillChar.getText().toCharArray(), typeOfLine);
                displayCanvas(myTmpCanvas,numRows,numCols);
            }
            if (drawingLabel == true)
            {
                 
                //copy canvas and display preview label            
                copyCanvas(myTmpCanvas,myCanvas,numRows,numCols);
                myTmpCanvas[row][col] = charLabel;
                displayCanvas(myTmpCanvas,numRows,numCols);
               
             }
           
           
           }
      }
      public void mouseDragged(MouseEvent me){}
  }
} // class MathDesign
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 25

Expert Comment

by:InteractiveMind
ID: 16449827
I had the same problem yesterday; it turned out that the class file was not being compiled into a version early enough for the running JRE.

You're compiling into 1.2, right?

Are you sure that Mac user doesn't have an earlier version than that installed ?
0
 
LVL 19

Author Comment

by:BrianGEFF719
ID: 16449929
He is using a version Java Runtime Version 1.4.2_09. I had him check at the java website to determine version number.


I cant figure it out. I've selected VM 1.2.2 Class in NetBeans and it seems to be compiling as 1.2.2, src version is set as 1.2...everything seems right...I'm very new to Java but I dont know what I could be doing wrong.


Brian
0
 
LVL 92

Expert Comment

by:objects
ID: 16450293
> java.lang.UnsupportedClassVersionError: mathDesign  (Unsupported major.minor version 49.0)

Thats telling you they are 1.5 classes being run.
Double check that you have compiled them as 1.2, and that you have uploaded the latest to the server.
Also perhapsget the user to clear their cache in case they are running an old version of your classes that were compiled for 1.5.
.
0
 
LVL 19

Author Comment

by:BrianGEFF719
ID: 16450422
>>Also perhapsget the user to clear their cache in case they are running an old version of your classes that >>were compiled for 1.5.

I created an entirely new project, I even renamed the class so that it would be a new version and java would not use a cached version (this new version was compiled as 1.2).

You can download the compiled classes:
http://www.atchosting.com/classes.zip

Please download and verify infact they are compiled as JDK 1.2


Brian
0
 
LVL 92

Expert Comment

by:objects
ID: 16450432
thats a different class name than what the user is loading on the mac. Did you also change the html to refernce the changed class name?
0
 
LVL 19

Author Comment

by:BrianGEFF719
ID: 16450481
yes, everything was updated of course...the code posted above is from before the class was renamed. and the html provided in the original post is valid.

Brian
0
 
LVL 19

Author Comment

by:BrianGEFF719
ID: 16450483
The error code is the same but ofcourse the class name is changed.

brian
0
 
LVL 92

Expert Comment

by:objects
ID: 16450668
thoses classes look fine, is the url the mac is accessing publically accessible?
0
 
LVL 19

Author Comment

by:BrianGEFF719
ID: 16450787
It is publically accessible. I cant figure it out. Like I said those classes were brand new. And they still did not work.


Brian
0
 
LVL 92

Expert Comment

by:objects
ID: 16451128
> It is publically accessible.

and the url is .....?
I'll try and run it here from one of out macs
0
 
LVL 19

Author Comment

by:BrianGEFF719
ID: 16451293
Objects, I really appricate all your help btw.

http://www.advancedtechconcepts.com/brian/mathForum/drMathDesign.html
0
 
LVL 92

Accepted Solution

by:
objects earned 2000 total points
ID: 16451325
loads fine here using 1.4 on mac and windows

perhaps get them to clear their plugin cache in case they are running old class files
0
 
LVL 19

Author Comment

by:BrianGEFF719
ID: 16451359
But like I said, I recompiled as a completely different class name...and it still failed.
0
 
LVL 19

Author Comment

by:BrianGEFF719
ID: 16453598
Objects: how do you clear the plugin cache on a mac?


Brian
0
 
LVL 92

Expert Comment

by:objects
ID: 16473735
what version macos?
0
 
LVL 19

Author Comment

by:BrianGEFF719
ID: 16474972
Retract my last question, I found an article online. I'm waiting to hear back if he disabled the Java cache. (this would be the best option to prevent this problem in the future).

I will be able to close this q soon.

brian
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
The viewer will learn how to implement Singleton Design Pattern in Java.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month18 days, 18 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question