📄 swim.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -