swim.java

来自「这是一个applet程序的代码」· Java 代码 · 共 53 行

JAVA
53
字号
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class swim extends Applet implements AdjustmentListener
{ 
  Scrollbar Scrollbar1;
  Scrollbar Scrollbar2;
  int x1,y1,x2,y2,x3,x4,y3,y4;
  float size;
  float longdepth;
  float shortdepth;
  float high;	
  public void init(){
   x1=50;y1=50;x2=300;y2=50;x3=300;y3=50;x4=50;y4=50;
   this.longdepth=y4-y1;
   this.shortdepth=y3-y2;
   this.high=x2-x1;
   this.size=(longdepth+shortdepth)*high/2;
  
	 Scrollbar1=new Scrollbar(Scrollbar.VERTICAL,50,50,50,200);
     Scrollbar2=new Scrollbar(Scrollbar.VERTICAL,50,50,50,300);
     add(Scrollbar1);
     add(Scrollbar2);
     Scrollbar1.addAdjustmentListener(this);
     Scrollbar2.addAdjustmentListener(this);
   }
   public void paint(Graphics g){
		g.drawLine(x1,y1, x2,y2);
		g.drawLine(x2,y2, x3,y3);
	    g.drawLine(x4,y4, x3,y3);
        g.drawLine(x4,y4, x1,y1);
	    g.drawString("the size is"+size,350,250);
	}



   public void adjustmentValueChanged(AdjustmentEvent e){
	 y3=Scrollbar1.getValue();
	 y4=Scrollbar2.getValue();
	 this.longdepth=y4-y1;
     this.shortdepth=y3-y2;
     this.high=x2-x1;
	 this.size=(this.longdepth+this.shortdepth)*this.high/2;
	 repaint();
	
	}

}



⌨️ 快捷键说明

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