⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fourier.java

📁 this is fourier transformation algorithm programmed in java
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            }
        }

        else if (e.target.equals(SinExpr)) {
            ParseFunction function = new ParseFunction( ((TextField)e.target).getText() );

            if(!function.parse()) {
               this.showStatus("Failed to parse function!");
               System.out.println("Failed to parse function!");
               return true;
            }
            for (int i=1; i < MAX_ANZ; i++) {
              try {
               double X = (double)(i);
               double value = function.getResult(X);
  	         bcoeff[Wnum][i] = value;
               bcoeff[Wnum][i] = Math.min(bcoeff[Wnum][i],1.0);
               bcoeff[Wnum][i] = Math.max(bcoeff[Wnum][i],-1.0);
              } catch(Exception err) {
               this.showStatus("Failed to parse function!");
               System.out.println("Failed to parse function!");
               bcoeff[Wnum][i] = 0.0;
              }
  	        ta_b[i].setText(""+bcoeff[Wnum][i]);
	        s_b[i].setValue( (int)(bcoeff[Wnum][i]*INT_MULT) );
            }
        }
      repaint();
      return true;
      } //  if (e.target instanceof TextField)

      if (e.target instanceof Button) {
       for (int i=0; i < MAX_ANZ; i++)  {
  	   if ( e.target.equals(la_a[i]) )  {
//             this.showStatus("Zeroing "+e.target);
  	       acoeff[Wnum][i] = 0.0;
             CosExpr.setText("");
             SinExpr.setText("");
	       ta_a[i].setText(""+acoeff[Wnum][i]);
	       s_a[i].setValue( (int)(acoeff[Wnum][i]*INT_MULT) );
             repaint();
             return true;
	   }  // if ( e.target.equals(ta_a[i]) )
  	   else if ( e.target.equals(la_b[i]) )  {
           if (i > 0) {
//             this.showStatus("Zeroing "+e.target);
  	       bcoeff[Wnum][i] = 0.0;
             CosExpr.setText("");
             SinExpr.setText("");
	       ta_b[i].setText(""+bcoeff[Wnum][i]);
	       s_b[i].setValue( (int)(bcoeff[Wnum][i]*INT_MULT) );
             repaint();
             return true;
           } // if (i > 0)
	   }  // else if ( e.target.equals(ta_b[i]) )
        } // for (int i=0; i < MAX_ANZ; i++)
      } // if (e.target instanceof Button)


      else if (e.target.equals(Wave1)) {
         Wnum = 0;
         CosExpr.setText("");
         SinExpr.setText("");
         this.showStatus("Using Wave Number 1");
         for (int i=0; i < MAX_ANZ; i++)  {
  	      ta_a[i].setText(""+acoeff[Wnum][i]);
	      s_a[i].setValue( (int)(acoeff[Wnum][i]*INT_MULT) );
            if (i > 0) {
     	         ta_b[i].setText(""+bcoeff[Wnum][i]);
	         s_b[i].setValue( (int)(bcoeff[Wnum][i]*INT_MULT) );
            }
         }
         repaint();
         return true;

      }
      else if (e.target.equals(Wave2)) {
         Wnum = 1;
         CosExpr.setText("");
         SinExpr.setText("");
         this.showStatus("Using Wave Number 2");
         for (int i=0; i < MAX_ANZ; i++)  {
  	      ta_a[i].setText(""+acoeff[Wnum][i]);
	      s_a[i].setValue( (int)(acoeff[Wnum][i]*INT_MULT) );
            if (i > 0) {
     	         ta_b[i].setText(""+bcoeff[Wnum][i]);
	         s_b[i].setValue( (int)(bcoeff[Wnum][i]*INT_MULT) );
            }
         }
         repaint();
         return true;

      }
      else if (e.target.equals(Wave3)) {
         Wnum = 2;
         CosExpr.setText("");
         SinExpr.setText("");
         this.showStatus("Using Wave Number 3");
         for (int i=0; i < MAX_ANZ; i++)  {
  	      ta_a[i].setText(""+acoeff[Wnum][i]);
	      s_a[i].setValue( (int)(acoeff[Wnum][i]*INT_MULT) );
            if (i > 0) {
     	         ta_b[i].setText(""+bcoeff[Wnum][i]);
	         s_b[i].setValue( (int)(bcoeff[Wnum][i]*INT_MULT) );
            }
         }
         repaint();
         return true;

      }
      else if (e.target.equals(AudioOff)) {
         if ( soundOn ) {
   	      AudioPlayer.player.stop(soundStream);
	      showStatus("Audio OFF");
            soundOn = false;
         }
         return true;
      }

      else if (e.target.equals(AudioOn)) {
         if ( !soundOn ) {
  	      AudioPlayer.player.start(soundStream);
	      showStatus("Audio ON");
            soundOn = true;
         }
         return true;

      }

    case Event.SCROLL_ABSOLUTE:
    case Event.SCROLL_LINE_UP:
    case Event.SCROLL_PAGE_UP:
    case Event.SCROLL_LINE_DOWN:
    case Event.SCROLL_PAGE_DOWN:

      for (int i=0; i < MAX_ANZ; i++) {
   	   if ( e.target.equals(s_a[i]) )
	   {
           CosExpr.setText("");
           SinExpr.setText("");
           int value = ((Scrollbar)e.target).getValue();
	     acoeff[Wnum][i] = (double)(value) / INT_MULT;
	     ta_a[i].setText(""+acoeff[Wnum][i]);
	     break;
	   }
	   else if ( ( i != 0 ) &&  ( e.target.equals(s_b[i]) ) )
	   {
           CosExpr.setText("");
           SinExpr.setText("");
           int value = ((Scrollbar)e.target).getValue();
	     bcoeff[Wnum][i] = (double)(value) / INT_MULT;
	     ta_b[i].setText(""+bcoeff[Wnum][i]);
	     break;
	   }
	} // for (int i=0...
      repaint();
      return true;
    case Event.WINDOW_DESTROY:
      destroy();
      return true;


    default:
       return super.handleEvent(e);

    } // switch ...

  }

  public void paint(Graphics g) {
    CalculatePlot();
    g.drawImage(bg, 0, 0, null);
    g.clipRect(0, 0, 320, 200);  // Keeps drawing out of area

    g.setColor(Color.red);
    for (int i = 0; i < 320; i+=80) {
      for (int j = 0; j < 80; j++) {
	      g.drawLine(i+j, iy[j], i+j+1, iy[j+1]);
      }
    }


  }

  public void stop() {
     if ( AUDIO && soundOn )
	AudioPlayer.player.stop(soundStream);
  }

  public void start() {
     if ( AUDIO && soundOn )
	AudioPlayer.player.start(soundStream);
  }

  public void destroy() {
    if ( AUDIO )
      AudioPlayer.player.stop(soundStream);
    for (int i=0; i < MAX_ANZ; i++)
      {
      for (int j=0; j<MAX_WAVES; j++) {
	   acoeff[j][i] = 0.0;
	   bcoeff[j][i] = 0.0;
      }
	la_a[i] = null;
	la_b[i] = null;
	s_a[i] = null;
	s_b[i] = null;
      iy = null;
      }
      Wnum = 0;
      removeAll();
  }

  public static byte int2ulaw(int ch) {
    int mask;

    if (ch < 0) {
      ch = -ch;
      mask = 0x7f;
    }
    else {
      mask = 0xff;
    }
    //
    if (ch < 32) {
      ch = 0xF0 | 15 - (ch/2);
    }
    else
      if (ch < 96) {
	ch = 0xE0 | 15 - (ch-32)/4;
      }
      else
	if (ch < 224) {
	  ch = 0xD0 | 15 - (ch-96)/8;
	}
	else
	  if (ch < 480) {
	    ch = 0xC0 | 15 - (ch-224)/16;
	  }
	  else
	    if (ch < 992 ) {
	      ch = 0xB0 | 15 - (ch-480)/32;
	    }
	    else
	      if (ch < 2016) {
		ch = 0xA0 | 15 - (ch-992)/64;
	      }
	      else
		if (ch < 4064) {
		  ch = 0x90 | 15 - (ch-2016)/128;
		}
		else
		  if (ch < 8160) {
		    ch = 0x80 | 15 - (ch-4064)/256;
		  }
		  else {
		    ch = 0x80;
		  }
    return (byte)(mask & ch);
  }


  public String getAppletInfo()
    {
      return "fourier.class 96/07/15, Copyright (C) 1996 Manfred Thole\n" +
	     "This program is free software; you can redistribute it and/or modify it\n" +
             "under the terms of the GNU General Public License as published by the\n" +
             "Free Software Foundation; either version 2 of the License, or (at your\n" +
             "option) any later version.\n" +
             "\n" +
             "This program is distributed in the hope that it will be useful, but\n" +
             "WITHOUT ANY WARRANTY; without even the implied warranty of\n" +
             "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n" +
             "General Public License for more details.\n" +
             "\n" +
             "You should have received a copy of the GNU General Public License along\n" +
             "with this program; if not, write to the Free Software Foundation, Inc.,\n" +
             "675 Mass Ave, Cambridge, MA 02139, USA.\n";
    }

  public String[][] getParameterInfo() {
    String[][] info = { { "sin_name", "String", "Sine: / Sine: / ..." },
			{ "cos_name", "String", "Cosine: / Cosine: / ..." }
		      };
    return info;
  }

   public void constrain(Container container, Component component,
                  int grid_x, int grid_y, int grid_width, int grid_height,
                  int fill, int anchor, double weight_x, double weight_y,
                  int top, int left, int bottom, int right, int ipad_x,
                  int ipad_y)
    {
        GridBagConstraints c = new GridBagConstraints();
        c.gridx = grid_x; c.gridy = grid_y;
        c.gridwidth = grid_width; c.gridheight = grid_height;
        c.fill = fill; c.anchor = anchor;
        c.ipadx = ipad_x; c.ipady = ipad_y;
        c.weightx = weight_x; c.weighty = weight_y;
        if (top+bottom+left+right > 0)
            c.insets = new Insets(top, left, bottom, right);

        ((GridBagLayout)container.getLayout()).setConstraints(component, c);
        container.add(component);
    }

    public void constrain(Container container, Component component,
                  int grid_x, int grid_y, int grid_width, int grid_height,
                  int fill, int anchor, double weight_x, double weight_y,
                  int top, int left, int bottom, int right) {
       constrain(container, component, grid_x, grid_y, grid_width,
                  grid_height, fill, anchor, weight_x, weight_y,
                  top, left, bottom, right, 0, 0);
    }

    public void constrain(Container container, Component component,
                  int grid_x, int grid_y, int grid_width, int grid_height) {
        constrain(container, component, grid_x, grid_y,
              grid_width, grid_height, GridBagConstraints.NONE,
              GridBagConstraints.NORTHWEST, 0.0, 0.0, 0, 0, 0, 0, 0, 0);
    }

    public void constrain(Container container, Component component,
                  int grid_x, int grid_y, int grid_width, int grid_height,
                  int top, int left, int bottom, int right) {
        constrain(container, component, grid_x, grid_y,
              grid_width, grid_height, GridBagConstraints.NONE,
              GridBagConstraints.NORTHWEST,
              0.0, 0.0, top, left, bottom, right, 0, 0);
    }


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -