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

📄 applet1.java~7~

📁 Java灵感编程1-101之21-40
💻 JAVA~7~
字号:
package vectorapp;import java.awt.*;import java.awt.event.*;import java.applet.*;import java.util.Vector;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: </p> * @author unascribed * @version 1.0 */public class Applet1 extends Applet {  boolean isStandalone = false;  Label label1 = new Label();  Choice choice1 = new Choice();  //Get a parameter value  public String getParameter(String key, String def) {    return isStandalone ? System.getProperty(key, def) :      (getParameter(key) != null ? getParameter(key) : def);  }  //Construct the applet  public Applet1() {  }  //Initialize the applet  public void init() {    try {      jbInit();    }    catch(Exception e) {      e.printStackTrace();    } Vector x1vector=new Vector(360);//存放余弦x轴坐标值 Vector y1vector=new Vector(360);//存放余弦x轴坐标值Vector x2vector=new Vector(360);//存放正弦x轴坐标值 Vector y2vector=new Vector(360);//存放正弦x轴坐标值 Vector x3vector=new Vector(360);//存放指数x轴坐标值 Vector y3vector=new Vector(360);//存放指数x轴坐标值  double x,y;  Double xobj,yobj;//一个Double类型对象for(int i=0;i<360;i++){x=2*Math.PI*i/360;y=Math.cos(x);xobj=new Double(x*20+70);yobj=new Double(y*40+150);x1vector.addElement(xobj);y1vector.addElement(yobj);} for(int i=0;i<360;i++){x=2*Math.PI*i/360;y=Math.sin(x);xobj=new Double(x*20+70);yobj=new Double(y*40+150);x2vector.addElement(xobj);y2vector.addElement(yobj);}  for(int i=0;i<360;i++){x=-2+0.01*i;y=Math.exp(x);xobj=new Double(x*20+150);yobj=new Double(y*40+30);x3vector.addElement(xobj);y3vector.addElement(yobj);  }}  //Component initialization  private void jbInit() throws Exception {    label1.setText("选择图形");    choice1.addItemListener(new java.awt.event.ItemListener() {      public void itemStateChanged(ItemEvent e) {        choice1_itemStateChanged(e);      }    });    this.add(label1, null);    this.add(choice1, null);     choice1.addItem("余弦");      choice1.addItem("正弦");      choice1.addItem("指数");  }  //Get Applet information  public String getAppletInfo() {    return "Applet Information";  }  //Get parameter info  public String[][] getParameterInfo() {    return null;  }  void choice1_itemStateChanged(ItemEvent e) {repaint();  }public void paint(Graphics g){int x1,x2,y1,y2;switch(choice1.getSelectedIndex()){case 0:for(int i=0;i<360;i++){x1=((Double)x1vector.elementAt(i)).intValue();y1=((Double)y1vector.elementAt(i)).intValue();x2=((Double)x1vector.elementAt(i+1)).intValue();y2=((Double)x1vector.elementAt(i+1)).intValue();g.drawLine(x1,y1,x2,y2);}break;case 1:for(int i=0;i<360;i++){x1=((Double)x2vector.elementAt(i)).intValue();y1=((Double)y2vector.elementAt(i)).intValue();x2=((Double)x2vector.elementAt(i+1)).intValue();y2=((Double)x2vector.elementAt(i+1)).intValue();g.drawLine(x1,y1,x2,y2);}break;case 2:for(int i=0;i<360;i++){x1=((Double)x3vector.elementAt(i)).intValue();y1=((Double)y3vector.elementAt(i)).intValue();x2=((Double)x3vector.elementAt(i+1)).intValue();y2=((Double)x3vector.elementAt(i+1)).intValue();g.drawLine(x1,y1,x2,y2);}}}  }

⌨️ 快捷键说明

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