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

📄 sinewaveframe.html

📁 java编程思想第3版原代码分享是java编程思想一本好书,大家多多学习
💻 HTML
字号:
<html><head><title>Display page for SineWave at www.BruceEckel.com</title></head>
<FONT FACE="Verdana,Tahoma,Arial,Helvetica,Sans" SIZE="-1">
<FONT FACE="Verdana,Tahoma,Arial,Helvetica,Sans"><H2>SineWave.java</H2><hr></FONT>
<!--"CONVERTED_APPLET"-->
<!-- HTML CONVERTER -->
<OBJECT 
    classid = "clsid:CAFEEFAC-0014-0001-0001-ABCDEFFEDCBA"
    codebase = "http://java.sun.com/products/plugin/autodl/jinstall-1_4_1_01-windows-i586.cab#Version=1,4,1,1"
    WIDTH = "700" HEIGHT = "400" ALIGN = "baseline" >
    <PARAM NAME = CODE VALUE = "SineWave.class" >
    <PARAM NAME = "type" VALUE = "application/x-java-applet;jpi-version=1.4.1_01">
    <PARAM NAME = "scriptable" VALUE = "false">

    <COMMENT>
	<EMBED 
            type = "application/x-java-applet;jpi-version=1.4.1_01" 
            CODE = "SineWave.class"
            WIDTH = "700"
            HEIGHT = "400"
            ALIGN = "baseline"  
	    scriptable = false 
	    pluginspage = "http://java.sun.com/products/plugin/index.html#download">
	    <NOEMBED>
            
            </NOEMBED>
	</EMBED>
    </COMMENT>
</OBJECT>

<!--
<APPLET CODE = "SineWave.class" WIDTH = "700" HEIGHT = "400" ALIGN = "baseline">


</APPLET>
-->


<!--"END_CONVERTED_APPLET"-->

<FONT SIZE="+3"><PRE><B>
//: c14:SineWave.java
// Drawing with Swing, using a JSlider.
// &lt;applet code=SineWave width=700 height=400&gt;&lt;/applet&gt;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import com.bruceeckel.swing.*;

class SineDraw extends JPanel {
  private static final int SCALEFACTOR = 200;
  private int cycles;
  private int points;
  private double[] sines;
  private int[] pts;
  public SineDraw() { setCycles(5); }
  public void setCycles(int newCycles) {
    cycles = newCycles;
    points = SCALEFACTOR * cycles * 2;
    sines = new double[points];
    for(int i = 0; i &lt; points; i++) {
      double radians = (Math.PI/SCALEFACTOR) * i;
      sines[i] = Math.sin(radians);
    }
    repaint();
  }
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    int maxWidth = getWidth();
    double hstep = (double)maxWidth/(double)points;
    int maxHeight = getHeight();
    pts = new int[points];
    for(int i = 0; i &lt; points; i++)
      pts[i] =
        (int)(sines[i] * maxHeight/2 * .95 + maxHeight/2);
    g.setColor(Color.RED);
    for(int i = 1; i &lt; points; i++) {
      int x1 = (int)((i - 1) * hstep);
      int x2 = (int)(i * hstep);
      int y1 = pts[i-1];
      int y2 = pts[i];
      g.drawLine(x1, y1, x2, y2);
    }
  }
}

public class SineWave extends JApplet {
  private SineDraw sines = new SineDraw();
  private JSlider adjustCycles = new JSlider(1, 30, 5);
  public void init() {
    Container cp = getContentPane();
    cp.add(sines);
    adjustCycles.addChangeListener(new ChangeListener() {
      public void stateChanged(ChangeEvent e) {
        sines.setCycles(
          ((JSlider)e.getSource()).getValue());
      }
    });
    cp.add(BorderLayout.SOUTH, adjustCycles);
  }
  public static void main(String[] args) {
    Console.run(new SineWave(), 700, 400);
  }
} ///:~

</B></PRE></FONT>
</html>

⌨️ 快捷键说明

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