运行Java Applet时发生ClassNotFound异常

时间:2018-08-07 13:29:47

标签: java applet noclassdeffounderror

在服务器中运行applet时遇到问题。我的applet脚本为

<?php

echo 'Signature:: <p  align="center"> <applet code="draw1/DrawApplet.class" codebase="draw1/DrawApplet.java"
        width="'.$apWidth.'" height="'.$apHeight.'" id="'.$formID.'">
       <PARAM NAME="BAH" VALUE="10">
       <PARAM NAME="id" VALUE="10">
       <PARAM NAME="type" VALUE="Sig">
       <PARAM NAME="server" VALUE="'.$importantData['SignatureSavingAddress'].'">
       <PARAM NAME="java_arguments" VALUE="-Djnlp.packEnabled=false">
     </applet> </p></form></div>';?>

这是Java代码

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.awt.image.BufferedImage;

import javax.imageio.ImageIO;


import javax.swing.JApplet;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.SwingUtilities;
import java.lang.*;
import java.text.SimpleDateFormat;

import java.util.Calendar;

import java.awt.AWTEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseListener;
import java.awt.*;

import java.awt.MouseInfo;

public class DrawApplet extends JApplet implements ActionListener , MouseListener
{
    public static final String DATE_FORMAT_NOW = "yyyy.MM.dd'_'HH.mm.ss.SSS";
    public static final SimpleDateFormat dataFormat = new SimpleDateFormat(DATE_FORMAT_NOW);

    public String SERVER = "https://www.physicianxpress.net/DOM/draw1/upload.php";
    public static final String CLEAR_STRING = "Clear";
    public static final String SAVE_STRING = "Save";
    public static final String STARTER_STRING = "Start";

    protected DrawPanel drawPanel;
        protected JButton save = new JButton(SAVE_STRING);
    protected JButton clear = new JButton(CLEAR_STRING);
    protected JButton starter = new JButton(STARTER_STRING);

        protected JLabel labeler = new JLabel("Please click the attach button below now.");

        protected JPanel center = new JPanel();


        public int curX, curY;


    //Called when this applet is loaded into the browser.
    public void init()
    {
        String tempServer   = getParameter("server");
        SERVER = tempServer + "/DOM/draw1/upload.php";

            //JButton clear = new JButton(CLEAR_STRING);
        clear.setActionCommand(CLEAR_STRING);
        clear.addActionListener(this);

                starter.setActionCommand(STARTER_STRING);
        starter.addActionListener(this);

        //JButton save = new JButton(SAVE_STRING);
        save.setActionCommand(SAVE_STRING);
        save.addActionListener(this);
        save.setMnemonic('s');

                JPanel mid = new JPanel();

                JPanel east2 = new JPanel();
                east2.setLayout(new BorderLayout());

                JPanel east = new JPanel();
                east.setLayout(new BorderLayout());

        //east.add(BorderLayout.NORTH, starter); //
        east.add(BorderLayout.CENTER, clear); //
        east.add(BorderLayout.SOUTH, save); //

                east2.add(BorderLayout.NORTH, east); //
                east2.add(BorderLayout.CENTER, mid); //

        drawPanel = new DrawPanel();

        //JPanel center = new JPanel();
        center.setLayout(new BoxLayout(center, BoxLayout.Y_AXIS));
        center.setBorder(BorderFactory.createLoweredBevelBorder());
        center.setLayout(new BorderLayout());
        center.add(drawPanel, BorderLayout.CENTER);

        setLayout(new BorderLayout());

        add(center, BorderLayout.CENTER);
        add(east2, BorderLayout.EAST);
        add(labeler , BorderLayout.SOUTH);


                //labeler.setHorizontalTextPosition(1);
                labeler.setBackground(Color.yellow);
                labeler.setVisible(false);
                drawPanel.setEnabled(false);


                // be compatible for a mouse listener.
                //enableEvents(AWTEvent.MOUSE_MOTION_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK);

                //starter.addMouseListener(this);
                //drawPanel.addMouseListener(this);

                //addMouseListener(this);

        String tempID = getParameter("id");

        if(tempID == null || tempID.length() <= 0)
        {
            JOptionPane.showMessageDialog(this, "Please reload, your signature will not attach properly.", "Success", JOptionPane.PLAIN_MESSAGE);
        }
    }

    public void start()
    {

    }

    public void stop()
    {

    }

    public void actionPerformed(ActionEvent e)
    {
        if(e.getActionCommand().equals(CLEAR_STRING))
        {
            drawPanel.clear();
        }
                else if(e.getActionCommand().equals(STARTER_STRING))
                {
                    // lock the cursor into the box.

                    // set everything to true.
                    center.setVisible(true);
                    clear.setVisible(true);
                    save.setVisible(true);

                    drawPanel.setEnabled(true);
                    drawPanel.clear();      // clear it.


                    drawPanel.setXPos(curX);
                    drawPanel.setYPos(curY);

                    System.out.println("Set Positions.");
                    starter.setVisible(false);
                    starter.setEnabled(false);

                }
        else if(e.getActionCommand().equals(SAVE_STRING))
        {
            Image image = drawPanel.getImage();

            BufferedImage bufferedImage = new BufferedImage(drawPanel.getWidth(), drawPanel.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
            Graphics graphics = bufferedImage.createGraphics();
            graphics.drawImage(image, 0, 0, null);

            try
            {
                                double randNumber = Math.random();

                //ImageIO.write(bufferedImage, "jpg", new java.io.File("new_abc.jpg"));
                ImageUploader.sendData(SERVER, getFileName() + "_"+randNumber+".jpg", (Image)bufferedImage);
                JOptionPane.showMessageDialog(this, "Image Uploaded, please attach it by clicking the button below.", "Success", JOptionPane.PLAIN_MESSAGE);

                                drawPanel.clear();

                                center.setVisible(false);
                                clear.setVisible(false);
                                starter.setVisible(false);
                                save.setVisible(false);
                                labeler.setVisible(true);
                                drawPanel.setVisible(false);

                                //drawPanel.resize(new Dimension(400,30));
                                this.resize(new Dimension(400,30));
                                //repaint();

            }
            catch(Exception ex)
            {
                JOptionPane.showMessageDialog(this, "Unable To Upload Image:" + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
                ex.printStackTrace();
            }

            //ImageIO.write(image, String formatName, null);    
        }   
    }

    private String getFileName()
    {
        //Calendar cal = Calendar.getInstance();
        //return dataFormat.format(cal.getTime());
        String fileName   = getParameter("id");
                  return fileName;
    }

    public static void main(String[] args)
    {
        DrawApplet drawApplet = new DrawApplet();
        drawApplet.setSize(400, 200);
        drawApplet.setVisible(true);
    }

           public void mousePressed(MouseEvent e) {
        //     System.out.println("Mouse pressed; # of clicks: " + e.getClickCount());
    }

    public void mouseReleased(MouseEvent e) {
       //System.out.println("Mouse released; # of clicks: "
       //             + e.getClickCount());
    }

    public void mouseEntered(MouseEvent e) {
        try
        {
            //int x = e.getX();
            //int y = e.getY();

            int x = MouseInfo.getPointerInfo().getLocation().x;
            int y = MouseInfo.getPointerInfo().getLocation().y;

            curX = x;
            curY = y;

        }
        catch(Exception ex)
        {
            String s = "mouse entred error" + ex.toString();
            //JOptionPane.showMessageDialog(this, s, "Success", JOptionPane.PLAIN_MESSAGE);
            //ex.printStackTrace();

        }
        System.out.println("Mouse entered: (" + curX + "," + curY + ")");

    }

    public void mouseExited(MouseEvent e) {
       //System.out.println("Mouse exited");

        if(e.getSource()==drawPanel)
        {
            // suck it back into the object
            System.out.println("In the attempt to exit");
            try
            {
                int x = MouseInfo.getPointerInfo().getLocation().x;
                int y = MouseInfo.getPointerInfo().getLocation().y;

                System.out.println("Mouse Exit: (" + curX + "," + curY + ") - exitX: (" + x + "," + y + ")");
                try
                {
                    Robot rob = new Robot();
                    rob.mouseMove(curX, curY);
                }
                catch(Exception ex3)
                {
                    System.out.println("Exception in the exit: " + ex3.toString());
                }
            }
            catch(Exception ex)
            {
                String s = "mouse entred error" + ex.toString();
                //JOptionPane.showMessageDialog(this, s, "Success", JOptionPane.PLAIN_MESSAGE);
                //ex.printStackTrace();

            }

        }
        else
        {
            System.out.println("Not the source");
        }


    }

    public void mouseClicked(MouseEvent e) {
       //System.out.println("Mouse clicked (# of clicks: "
       //             + e.getClickCount() + ")");
    }

    public void mouseMoved(MouseEvent e) {

        try
        {
            int x = MouseInfo.getPointerInfo().getLocation().x;
            int y = MouseInfo.getPointerInfo().getLocation().y;

            curX = x;
            curY = y;

        }
        catch(Exception ex)
        {
            String s = "mouse entred error" + ex.toString();
            //JOptionPane.showMessageDialog(this, s, "Success", JOptionPane.PLAIN_MESSAGE);
            //ex.printStackTrace();

        }

    }

我对Java完全陌生。最近有一个修复此错误的项目。我需要修复的错误是为什么小程序无法正常工作。我已经在IE中检查了并得到了classNotFoundException。

我已经安装了Java8。

任何人都可以告诉我我需要检查哪些问题才能解决此错误。

0 个答案:

没有答案