| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1032 人关注过本帖
标题:JAVA 小程序调试的问题 请帮忙
只看楼主 加入收藏
luofuyan
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-3-8
收藏
 问题点数:0 回复次数:2 
JAVA 小程序调试的问题 请帮忙
NormalApplet小程序java编译成功,运行时出现错误,在网页中载入时失败,当前路径; d:\test\normal下有3个java文件(NormalGraphData;NormalControlPanel;NormalApplet)及转换的class文件,一个文包件夹 (edu.csusb.danby) ;classpath设置应该没有问题,运行其他小程序,没有问题,利用Jcreator调试的结果java.lang.NoSuchMethodError: main Exception in thread "main" 这个我估计是小程序在网页中才能运行,但在网页中测试,左下角显示,载入小程序失败(在网页中的代码没有问题)我是来鸟,清高手看一下
调用的其他文件在附件
源文件是:
package normal;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;
import edu.csusb.danby.applet.*;
import edu.csusb.danby.math.ProbMath;
import edu.csusb.danby.graph.*;

/**
* Normal distribution applet
* @author Charles S. Stanton
* @version Sat Jul 27 08:45:01 PDT 2002
*/
public class NormalApplet extends DApplet{
NormalControlPanel controlPanel;
NormalGraphData ngd;
PdfPlot normalPlot;

public void init(){
ngd = new NormalGraphData();
normalPlot = new PdfPlot(ngd);
controlPanel = new NormalControlPanel(this);
dFrame = new DFrame("Normal Distribution Calculator", normalPlot);
dFrame.setControlPanel(controlPanel);
dFrame.validate();
setVisible(true);
}

public void doControlPanelButtonAction( ActionEvent e){
String buttonLabel = e.getActionCommand();
if (buttonLabel.equals("calculate")){
calculate();
}
}

public void calculate(){
double x1, x2, mu, sigma;
String t1, t2, tMu, tSigma; //text values for x1, x2;
tMu = controlPanel.textMu.getText();
tSigma = controlPanel.textSigma.getText();
t1 = controlPanel.textX1.getText();
t2 = controlPanel.textX2.getText();
try {
x1=Double.valueOf(t1).doubleValue();
x2=Double.valueOf(t2).doubleValue();
mu = Double.valueOf(tMu).doubleValue();
sigma = Double.valueOf(tSigma).doubleValue();
ngd.setX1((float)x1);
ngd.setX2((float)x2);
ngd.setMu((float)mu);
ngd.setSigma((float)sigma);
controlPanel.printProbability(ProbMath.normalCdf((x2-mu)/sigma)
-ProbMath.normalCdf((x1-mu)/sigma));
normalPlot.update(ngd);
normalPlot.repaint();
} catch ( NumberFormatException n) {
String msg = "z1 = "+t1+" z2 = "+t2+"\n mu = "+tMu+" sigma = "+tSigma+"\n are not proper numerical values";
String errTitle = "Numerical Input Error";
JOptionPane.showMessageDialog(dFrame, msg , errTitle,
JOptionPane.ERROR_MESSAGE);
}

repaint();
}


/**
* provides applet info
*/
public String getAppletInfo() {
return "A normal probability calculator.\nAuthor: Charles S. Stanton";
}
}



2.
package normal;


import javax.swing.*;
import java.awt.event.*;
import java.applet.*;
import java.awt.*;
import edu.csusb.danby.applet.*;


public class NormalControlPanel extends JPanel {
    JTextField textMu, textSigma, textX1, textX2, textProb;
    DControlPanelAction mApplet;
   
   
    public NormalControlPanel(DControlPanelAction applet){
        mApplet=applet;
        setLayout(new FlowLayout());
        textMu = new JTextField("0.0",7);
        textSigma = new JTextField("1.0",7);
        textX1 = new JTextField(7);
        textX2 = new JTextField(7);
        add(new JLabel("mu ="));
        add(textMu);
        add(new JLabel("sigma ="));
        add(textSigma);
        add(new JLabel("x1 ="));
        add(textX1);
        add(new JLabel("x2 ="));
        add(textX2);
        JButton submitButton = new JButton("calculate");
        submitButton.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                mApplet.doControlPanelButtonAction(e);
            }
        });    
        
        add(submitButton);
        textProb = new JTextField(14);
        add(new JLabel("P(x1 < X < x2)="));
        add(textProb);
            }

        public void printProbability(double p){
            //textProb.setColor(Color.blue);
            textProb.setText(String.valueOf(p));
        }
        
   
        
}

3.
package normal;


import java.awt.*;
import javax.swing.*;
//import cern.jet.stat.*;
import java.awt.geom.Point2D;
import edu.csusb.danby.graph.*;

/**
 * This class graphs a normal curve and shows the area
 * under the curve specified
 *
 * @author Charles S. Stanton
 * @version Mon Jul 29 19:10:03 PDT 2002
 */
public class NormalGraphData  implements PdfPlotable {
    static final float c = (float)(1.0/(Math.sqrt(2.0*Math.PI)));
   
    float mu, sigma, x1, x2;
    //add a few extra points near zero so that the graph is smoother
    float[] normalAbcissa ={    4.000000000f, 3.800000000f, 3.600000000f,
                            3.400000000f, 3.200000000f, 3.000000000f,
                            2.800000000f, 2.600000000f, 2.400000000f,
                            2.200000000f, 2.000000000f, 1.800000000f,        
                            1.600000000f, 1.400000000f, 1.200000000f,
                            1.100000000f, 1.000000000f, .900000000f,
                            .800000000f, .700000000f, .600000000f,
                            .500000000f, .400000000f, .300000000f,
                            .200000000f, .100000000f, 0.f};
    float[] normalOrdinate = {.1338302258e-3f, .2919469256e-3f, .6119019298e-3f,
                            .1232219168e-2f, .2384088201e-2f, .4431848411e-2f,
                        .7915451578e-2f, .1358296922e-1f, .2239453029e-1f,
                        .3547459283e-1f, .5399096648e-1f, .7895015828e-1f,
                        .1109208346f, .1497274656f, .1941860549f, .2178521769f,
                     .2419707244f, .2660852498f, .2896915527f, .3122539332f,
                    .3332246028f, .3520653266f, .3682701402f, .3813878153f,
                    .3910426938f, .3969525473f, .3989422802f};

    boolean inverseSelected;
    int tailChoice; //PDFPlotable.LEFT_TAIL, PDFPlotable.RIGHT_TAIL, or PDFPlotable.BOTH_TAILS
   
    /**
    * constructs standard mu=0 sigma = 1<code>NormalGraphData</code>
    *
    */
    public NormalGraphData(){
        mu =0;
        sigma = 1;
        x1 = -21.01f;
        x2 =1.01f;
    }
   
    /**
    * constructs <code>NormalGraphData</code>
    *
    * @param mu is the mean
    * @param sigma is the standard deviation
    * @parm aX0 is the left end of the probability interval
    * @param aX1 is the right end of the probability interval
    */
    public NormalGraphData( float aMu, float aSigma, float aX1, float aX2){
        this( aMu, aSigma, aX1, aX2, false, PdfPlotable.BOTH_TAILS);
    }
   
    /**
    * constructs <code>NormalGraphData</code>
    *
    * @param mu is the mean
    * @param sigma is the standard deviation* @param n is the degrees of freedom
    * @parm aX0 is the left end of the probability interval
    * @param aX1 is the right end of the probability interval
    * @param aInverseSelected sets the inverse mode
    * @param aTailChoice sets the tail choice for inverse mode
    */
    public NormalGraphData( float aMu, float aSigma, float ax1, float ax2,
                                     boolean aInverseSelected, int aTailChoice){
        mu = aMu;
        sigma = aSigma;
        
        x1 = ax1;
        x2 = ax2;
        inverseSelected = aInverseSelected;
        tailChoice = aTailChoice;
    }

    private float f(float x){
        return (float)(c/Math.sqrt(sigma)*Math.exp(-1*(x-mu)*(x-mu)/(2*sigma*sigma)));
        }

    public Point2D.Float[] getPlotPoints() {
        Point2D.Float[] returnData = new Point2D.Float[53];
        //add a few extra points near zero so that the graph is smoother
        for (int i=0; i<27; i++) {
            returnData[i] = new Point2D.Float( -1*normalAbcissa[i]*sigma+mu, normalOrdinate[i]/(float)Math.sqrt(sigma));
            returnData[53-i-1] = new Point2D.Float( normalAbcissa[i]*sigma+mu, normalOrdinate[i]/(float)Math.sqrt(sigma));
        }
        return returnData;
    }
    // PdfPlotable viewport methods
    public float getLowX(){return -4.0f*sigma+mu;}
    public float getHighX(){ return 4.0f*sigma+mu;}
    public float getLowY(){ return 0.0f;} //usually should be 0
    public float getHighY()    {return 0.5f/(float)Math.sqrt(sigma);}
    // PdfPlotable interval methods
    public Point2D.Float getLowXInterval() {return new Point2D.Float(x1,f(x1));}

    public Point2D.Float getHighXInterval() {return new Point2D.Float(x2, f(x2));}
    // PdfPlotable String information
    public String getXAxisLabel(){return "x";}
    public String getTitle()    {
        String title = new String("Normal Plot, mu = "+mu+" sigma = "+sigma);
        return title;
    }
    public void reset(){;}
    public boolean isInverseSelected(){return inverseSelected;}
    public void setInverseSelected(boolean aInverseSelected){ inverseSelected = aInverseSelected;}
    public int getTailChoice(){return tailChoice;}
    public void setTailChoice(int aTailChoice){ tailChoice=aTailChoice;}
    public void setX1(float aX1){ x1 = aX1;}
    public void setX2(float aX2){ x2 = aX2;}
    public void setMu(float aMu){ mu = aMu;}
    public void setSigma(float aSigma){ sigma = aSigma;}
}

edu.rar (89.18 KB)
搜索更多相关主题的帖子: JAVA 网页 java 调试 
2008-03-08 17:04
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
收藏
得分:0 
什么和什么?

可惜不是你,陪我到最后
2008-03-08 19:07
luofuyan
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-3-8
收藏
得分:0 
java 控制台的结果:
请各位高手看一下
哪里有问题

Java Plug-in 1.6.0_05
使用 JRE 版本 1.6.0_05 Java HotSpot(TM) Client VM
用户主目录 = C:\Documents and Settings\Administrator
network: 正在载入用户定义的代理配置 ...
network: 完成。
network: 正在从 Internet Explorer 中载入代理配置 ...
network: 完成。
network: 正在载入直接代理配置 ...
network: 完成。
network: 代理配置:没有代理


----------------------------------------------------
c:   清除控制台窗口
f:   终结在结束队列上的对象
g:   垃圾收集
h:   显示此帮助消息
l:   转储类载入程序列表
m:   打印内存使用
o:   触发日志记录
p:   重新载入代理配置
q:   隐藏控制台
r:   重新载入策略配置
s:   转储系统和部署属性
t:   转储线程列表
v:   转储线程堆栈
x:   清除类载入程序高速缓存
0-5: 设置跟踪级别为<n>
----------------------------------------------------

liveconnect: 调用 JS 方法:document
liveconnect: 调用 JS 方法:URL
basic: 正在引用类载入程序:sun.plugin.ClassLoaderInfo@1c6f579, refcount=1
basic: 已添加进度监听程序:sun.plugin.util.GrayBoxPainter@228a02
basic: 正在载入小应用程序...
basic: 正在初始化小应用程序...
basic: 正在启动小应用程序...
basic: completed perf rollup
java.lang.NoClassDefFoundError: NormalApplet (wrong name: normal/NormalApplet)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at sun.applet.AppletClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.applet.AppletClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.applet.AppletClassLoader.loadCode(Unknown Source)
    at sun.applet.AppletPanel.createApplet(Unknown Source)
    at sun.plugin.AppletViewer.createApplet(Unknown Source)
    at sun.applet.AppletPanel.runLoader(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
basic: 异常:java.lang.NoClassDefFoundError: NormalApplet (wrong name: normal/NormalApplet)
java.lang.NoClassDefFoundError: NormalApplet (wrong name: normal/NormalApplet)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at sun.applet.AppletClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.applet.AppletClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.applet.AppletClassLoader.loadCode(Unknown Source)
    at sun.applet.AppletPanel.createApplet(Unknown Source)
    at sun.plugin.AppletViewer.createApplet(Unknown Source)
    at sun.applet.AppletPanel.runLoader(Unknown Source)
    at sun.applet.AppletPanel.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
2008-03-09 08:22
快速回复:JAVA 小程序调试的问题 请帮忙
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029235 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved