同样的,排出了三种原因:
1。确认我的程序通过编译。并且,.class文件和在同一目录下。
2。主类是public修饰的。
3。主类的名字.class和文件要加载的类的名字完全相同。
剩下的,我不知道还有什么原因,觉得init()那里有问题,可是又不知道是什么。
程序就是想实现这样的功能:在页面上先画一个细长的矩形图,在鼠标选定图上的一个区域后,放大显示图中该区域更详细的内容。这个我通过判断坐标来动态画图。
另外,我是在JCreater里编译和运行的。一直没有搞清楚怎么进行单步调试:(
 
package mouse;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.awt.image.*;
import java.applet.*;
import java.net.*;
/*为了达到画线的功能,我们分别implements MouseListener与MouseMotionListener.
 */
public class MouseApplet extends Applet implements MouseListener,MouseMotionListener{
     
     String str;         //param1
     String chrLength;   //param2
     int flag = 0;
     int x=0;
     int y=0;
     Graphics g = null;
     
     int startx,starty,endx,endy;//起始坐标与终点坐标
     int imgOrig = Integer.parseInt(chrLength);
     int zoomLength = imgOrig;
     int imgStart = 0;
     int imgEnd = imgStart + zoomLength;
     
     public void init(){
         str = getParameter("str");
         chrLength = getParameter("chrLength");
         paint(g);
         //setLayout(new FlowLayout(FlowLayout.CENTER,0,0));
         this.addMouseListener(this);        //将鼠标注册给鼠标事件的监听者
         this.addMouseMotionListener(this);  //将鼠标注册给鼠标动作事件的监听者
     }
     
     public void destroy() {
        }
     public void start(){
                       
      }
public void stop(){
}
     
     public void drawCoordinate(Graphics g)               //maybe incorrect coordinate
     {                    
        int interval = zoomLength>>2;
           for(int i=imgStart; i<imgEnd; i+=interval)
           {
              g.drawLine(((int)(i-imgStart)/zoomLength*800),130,((int)(i-imgStart)/zoomLength*800),135);
              if(i>1000000)
              {
                   int j=i/1000000;
                   g.drawString(String.valueOf(j)+"M",((int)(i-imgStart)/zoomLength*800),133);
              }
              else if((i>1000)&&(i<1000000))
              {
                   int j=i/1000;
                   g.drawString(String.valueOf(j)+"K",((int)(i-imgStart)/zoomLength*800),133);
              }
              else
                 g.drawString(String.valueOf(i),((int)(i-imgStart)/zoomLength*800),133);
           }
     }    
     /*由mousePressed(),mouseReleased()取得示拖曳的开始与结束坐标*/
     public void mousePressed(MouseEvent e){
        startx=e.getX();
        starty=e.getY();
     }
     public void mouseReleased(MouseEvent e){
        endx=e.getX();
        endy=e.getY();
        
        //Container c=(Container)e.getSource(); 
        //Graphics g=c.getGraphics(); 
 
        //Graphics g = null;
        int zoom;
        int zoomTemp;
        
        if(endx > startx){
          zoomTemp = (endx-startx)/800*zoomLength;
          imgStart = imgStart + ((startx - /*imgleftx*/100)/800*zoomLength);
          //imgEnd = imgStart + zoomLength;
          zoomLength = zoomTemp;
          zoom = imgOrig/zoomLength;
          if(zoom <= 30){
              flag = 1;
              repaint();
          }
          if((zoom>30)&&(zoom<=900)){
              flag = 2;
              repaint();
          }
          if((zoom>900)&&(zoom<=27000)){
              flag = 3;
              paint(g);
          }
          if((zoom>27000)&&(zoom<=810000)){
              flag = 4;
              repaint();
         }
        }
        else{
        int exchange = startx;
        startx = endx;
        endx = exchange;
        
        zoomTemp = 800/(endx-startx)*zoomLength;
        zoomLength = zoomTemp;
        zoom = imgOrig/zoomLength;
        
        if(zoomTemp>imgOrig)
        {
            zoomLength = imgOrig;
            imgStart = 0;
            imgEnd = imgStart + zoomLength;
        }
        if(zoom<=30){
              flag = 1;
              repaint();
          }
          if((zoom>30)&&(zoom<=900)){
              flag = 2;
              repaint();
          }
          if((zoom>900)&&(zoom<=27000)){
              flag = 3;
              repaint();
          }
          if((zoom>27000)&&(zoom<=810000)){
              flag = 4;
              repaint();
         }
         
         imgStart = imgStart + (zoomLength>>1) - (int)(zoomTemp%2.0); //zoom out in center
       }
     }
        
        
     public void mouseEntered(MouseEvent e){}     
     public void mouseExited(MouseEvent e){}
     public void mouseClicked(MouseEvent e){}
     /*mouseMoved(),mouseDragged()取得鼠标移动的每一个坐标,并调用repaint()方法*/ 
     public void mouseMoved(MouseEvent e){
        //flag=1;
        x=e.getX();
        y=e.getY();
        repaint();
     }
     
    public void mouseDragged(MouseEvent e){
        //flag=2;
        //x=e.getX();
        //y=e.getY();
        //repaint();
     }
     
     public void update(Graphics g){
          g.setColor(this.getBackground());
          g.fillRect(100,100,/*getWidth()*/800,/*getHeight()*/500);
          paint(g);
     }
     
     public void paint(Graphics g){
     int geneWidth;
     int geneNum;
     int queryNum;
     String sbuf;
     if(flag==0)
     {
           g.setColor(Color.blue);
           g.fillRect(100,150,800,20);
     }
     if(flag==1)
     {  
          g.setColor(Color.blue);
           g.fillRect(100,150,/*getWidth*/800,/*getHeight*/500);
           
           geneNum = findGenes(imgStart,imgEnd).length;    //find genes from whole_genes.txt and no mark symbol
           gene[] gn = new gene[geneNum];
           for(int i=0; i<geneNum; i++)
           {  
                geneWidth = gn[i].txEnd - gn[i].txStart;
              g.fillRect((int)(800/zoomLength*(gn[i].txStart-imgStart)),150,((int)geneWidth/zoomLength*800),20);                              //show every gene in this region
        }
        
        repaint();
     }
     if(flag == 2)
     {  
           
          g.setColor(Color.blue);
          g.drawLine(100,150,/*getWidth*/800,150);
          
          geneNum = findGenes(imgStart,imgEnd).length;
          gene[] gn = new gene[geneNum];
          for(int i=0; i<geneNum; i++)
          { 
              geneWidth = gn[i].txEnd - gn[i].txStart;
              g.fillRect((int)(/*getWidth*/800/zoomLength*(gn[i].txStart-imgStart)),140,((int)geneWidth/zoomLength*/*getWidth*/800),20);                               //show genes & mark genes' name
              g.drawString("gn[geneNum].symbol",(int)(/*getWidth*/800/zoomLength*(gn[i].txStart-imgStart)),135);
          }
          
          repaint();
     }
     if(flag == 3)
     {
          g.setColor(Color.blue);
          g.drawLine(100,150,/*getWidth*/800,150);
          
          geneNum = findGenes(imgStart,imgEnd).length;
          gene[] gn = new gene[geneNum];
          for(int i=0; i<geneNum; i++)
          { 
                geneWidth = gn[i].txEnd - gn[i].txStart;
                g.fillRect((int)(800/zoomLength*(gn[i].txStart-imgStart)),140,((int)(geneWidth/zoomLength*800)),20);                               //show genes 
               g.drawString("gn[geneNum].symbol",(int)(800/zoomLength*(gn[i].txStart-imgStart)),135);                              //mark genes' name
             
                for(int j=0; j<gn[geneNum].exonCount; j++)                               //show exons
                {
                      int exonLen = gn[i].exonEnds[j] - gn[i].exonStarts[j];
                      int exonWidth = exonLen/zoomLength*800;
                      g.fillRect((int)(800/zoomLength*(gn[i].exonStarts[j]-imgStart)),140,exonWidth,20);
           }
          }
          
          queryNum = findQueries(imgStart,imgEnd).length;
          query[] qr = new query[queryNum];
          for(int j=0; j<queryNum; j++)                          //show queries & mark queries' position
          {  
                 int qrLen = qr[j].qrEnd - qr[j].qrStart;
               int qrWidth = qrLen/zoomLength*/*getWidth*/800;
               g.setColor(Color.red);
               g.drawLine((int)(/*getWidth*/800/zoomLength*(qr[j].qrStart-imgStart)),170,(int)(/*getWidth*/800/zoomLength*(qr[j].qrStart-imgStart))+ qrWidth,170);  
         }
        
     }
     if(flag == 4)                     //show their sequences
     { 
          g.setColor(Color.blue);
          char cbuf[] = new char[1000];
          sbuf = getGeneSeq(imgStart,imgEnd);
          g.drawString(sbuf,100,150);
            
          g.setColor(Color.red);
          queryNum = findQueries(imgStart,imgEnd).length;
          query[] qr = new query[queryNum];
          for(int i=0; i<queryNum; i++)
          {
           g.drawString(qr[i].seq,(int)(800/zoomLength*(qr[i].qrStart-imgStart)),170);  //how to decide its position? is it right?
          }
        
     }    
  }  
    public gene[] findGenes(int x,int y)
    {
     try{
      BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("F:\\blast\\blast数据库\\genes_"+str+".txt")));
        String geneline = null;
        String[] geneTemp = geneline.split(" ");
        //String[] gs = new String[100];
        
      int Start = Integer.parseInt(geneTemp[2]);
      int End = Integer.parseInt(geneTemp[3]);
      
        gene[] gn = new gene[100];
        for(int m=0; m<100; m++)
        {
            gn[m] = new gene();
        }
        
        int geneNum = 0;
        while((geneline = br.readLine())!= null)
        {
               geneTemp = geneline.split(" ");
             if((Start>x)&&(End<y))
                {
                     //gs[geneNum] = geneline;
                     geneNum++;
                     //gn[geneNum] = new gene();
                     gn[geneNum].txStart = Integer.parseInt(geneTemp[2]);
                     gn[geneNum].txEnd = Integer.parseInt(geneTemp[3]);
                     gn[geneNum].symbol = geneTemp[5];
                     gn[geneNum].exonCount = Integer.parseInt(geneTemp[6]);
                
                   for(int i=0; i<gn[geneNum].exonCount; i++)
                 {
                      gn[geneNum].exonStarts[i] = Integer.parseInt(geneTemp[6+i*2-1]);
                      gn[geneNum].exonEnds[i] = Integer.parseInt(geneTemp[6+i*2]);
                 }
              }
             geneline = br.readLine();
        }
      return gn;
     }catch(IOException e){
      System.out.println(e.getStackTrace());
      return null;
      }
   } 
      public query[] findQueries(int x,int y)
      {
        try{
          BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("F:\\blast\\blast数据库\\query_"+str+".txt")));
          String queryline = null;
          String[] queryTemp = queryline.split(" ");
        //String[] qs = new String[100];
          int Start = Integer.parseInt(queryTemp[2]);
          int End = Integer.parseInt(queryTemp[3]);
          
          query[] qr = new query[100];
          for(int n=0; n<100; n++)
          {
               qr[n] = new query();
          }
          
          int queryNum = 0;
          while((queryline = br.readLine())!= null)
          {
              queryTemp = queryline.split(" ");
              if((Start > x)&&(End < y))
               {
                   //qs[queryNum] = queryline;
                   queryNum++;
                   //qr[queryNum] = new query();
                   qr[queryNum].queryIndex = Integer.parseInt(queryTemp[0]);
                   qr[queryNum].qrStart = Integer.parseInt(queryTemp[2]);
                   qr[queryNum].qrEnd = Integer.parseInt(queryTemp[3]);
                   qr[queryNum].seq = queryTemp[4];
                   qr[queryNum].varNum = Integer.parseInt(queryTemp[5]);
                  
                  for(int i=0; i<qr[queryNum].varNum; i++)
                  {
                       qr[queryNum].varPos[i]= Integer.parseInt(queryTemp[6+i]);
                  }
               }
             queryline = br.readLine();
          }
          return qr;
       }
       catch(IOException e){
       System.out.println(e.getStackTrace());
       return null;
      }
     }
          
      public String getGeneSeq(int x,int y)   //read gene sequences
      {
          try{
          BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("F:\\blast\\blast数据库\\seq_"+str+".txt")));
          int off = x;
          int len = y - x;
          char cbuf[] = new char[len];
          //String sbuf = cbuf.toString();
          br.read(cbuf,off,len);
          String sbuf = cbuf.toString();
        return sbuf;
        }
        catch(IOException e){
          System.out.println(e.getStackTrace());
        return null;
        }
      }
    }     
     
     
        class gene
          {
              public int txStart;
              public int txEnd;
              public String symbol;
              public int exonCount;
              public int exonStarts[];
              public int exonEnds[];
              
          }
      
        class query
          {
              public int queryIndex;
              public int qrStart;
              public int qrEnd;
              public String seq;
              public int varNum;
              public int varPos[];
              public String varInf;
          }
----------------解决方案--------------------------------------------------------
打开控制台看一下,输出了什么?
控制台在系统的右下角
----------------解决方案--------------------------------------------------------
正在初始化 jdb...
> 正在延迟 断点 MouseApplet:62。
将在装入类之后对其进行设置。
> 正在延迟 断点 MouseApplet:97。
将在装入类之后对其进行设置。
> 正在延迟 断点 MouseApplet:122。
将在装入类之后对其进行设置。
> 正在延迟 断点 MouseApplet:204。
将在装入类之后对其进行设置。
> 正在延迟 断点 MouseApplet:217。
将在装入类之后对其进行设置。
> 正在延迟 断点 MouseApplet:253。
将在装入类之后对其进行设置。
> 正在延迟 断点 MouseApplet:303。
将在装入类之后对其进行设置。
> 正在延迟 断点 MouseApplet:349。
将在装入类之后对其进行设置。
> 正在延迟 断点 MouseApplet:395。
将在装入类之后对其进行设置。
> 运行 sun.applet.AppletViewer MouseApplet.htm
设置 未捕捉到 java.lang.Throwable
设置延迟的 未捕捉到 java.lang.Throwable
> 
VM 已启动: 无法设置延迟的 断点 MouseApplet:395: MouseApplet 中的第 395 行没有代码
由于延迟的断点错误而停止。
设置延迟的 断点 MouseApplet:349
设置延迟的 断点 MouseApplet:303
无法设置延迟的 断点 MouseApplet:253: MouseApplet 中的第 253 行没有代码
由于延迟的断点错误而停止。
无法设置延迟的 断点 MouseApplet:217: MouseApplet 中的第 217 行没有代码
由于延迟的断点错误而停止。
无法设置延迟的 断点 MouseApplet:204: MouseApplet 中的第 204 行没有代码
由于延迟的断点错误而停止。
设置延迟的 断点 MouseApplet:122
无法设置延迟的 断点 MouseApplet:97: MouseApplet 中的第 97 行没有代码
由于延迟的断点错误而停止。
无法设置延迟的 断点 MouseApplet:62: MouseApplet 中的第 62 行没有代码
由于延迟的断点错误而停止。
java.lang.NumberFormatException: null
        at java.lang.Integer.parseInt(Integer.java:415)
        at java.lang.Integer.parseInt(Integer.java:497)
        at MouseApplet.<init>(MouseApplet.java:40)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
        at java.lang.Class.newInstance0(Class.java:350)
        at java.lang.Class.newInstance(Class.java:303)
        at sun.applet.AppletPanel.createApplet(AppletPanel.java:721)
        at sun.applet.AppletPanel.runLoader(AppletPanel.java:650)
        at sun.applet.AppletPanel.run(AppletPanel.java:324)
        at java.lang.Thread.run(Thread.java:595)
以上就是控制台输出的东西。好像很多错误。-_-!
----------------解决方案--------------------------------------------------------