?? haiming3.java
字號:
import java.awt.*;
import java.awt.event.*;
import java.math.*;
class Mypanel extends Panel implements ActionListener{
float x1=0,y1=0,x2=100,y2=200;
float x,y;
TextField t1,t2;
Button b1;
Mypanel(){
setSize(400,400);
setLayout(null);
setBackground(Color.blue);
setVisible(true);
t1=new TextField(10);
t2=new TextField(10);
b1=new Button("點我啊");
b1.addActionListener(this);
b1.setBounds(300,5,60,30);
t2.setBounds(220,5,60,30);
t1.setBounds(140,5,60,30);
add(b1);
add(t1);
add(t2);
}
public void paint(Graphics g){
y=y2;
for(x=100;x>0.3;x=(float)(y2-y1)){
g.setColor(Color.green);
g.drawLine((int)x1,(int)y1,(int)x1+1,(int)y1+1);
g.setColor(Color.black);
g.drawLine((int)x2,(int)y2,(int)x2+1,(int)y2+1);
y2=y2+(float)0.1;
x1=x1+(float)(0.3*(x2-x1)/Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
y1=y1+(float)(0.3*(y2-y1)/Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
}
System.out.println("時間是"+(float)(y2-y)/10+"分鐘;其余自己去算!");
}
public void actionPerformed(ActionEvent e){
x2=Integer.parseInt(t1.getText());
x2=x2*10;
y2=Integer.parseInt(t2.getText());
y2=y2*10;
x1=0;
y1=0;
repaint();
}
}
class haiming1{
public static void main(String args[]){
Frame m=new Frame("畫圖畫圖哈哈");
Mypanel f=new Mypanel();
m.add(f);
m.setSize(404,404);
m.setVisible(true);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -