这是光线演示程序,但是为什么窗口什么也没显示,请教各位大虾,帮忙修改下
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;
public class lineDemo extends Applet implements ActionListener
{
JLabel lab1,lab2;
JTextField text1,text2;
JButton but;
JPanel pan;
Thread t;
String s1,s2;
int len=100,x,y,dx,dy;
int i=0,n2;
double n1;
public void init()
{
Frame fram=new Frame();
lab1=new JLabel("start arcs");
lab2=new JLabel("demo time");
but=new JButton("start");
text1=new JTextField("45",3);
text2=new JTextField("0",3);
pan=new JPanel();
drawpan panent=new drawpan();
pan.add(lab1); pan.add(text1);
pan.add(lab2); pan.add(text2);
pan.add(but);
but.addActionListener(this);
fram.add(pan,BorderLayout.NORTH);
fram.add(panent,BorderLayout.CENTER);
fram.setSize(300,280);
fram.setLocation(300,300);
fram.setVisible(true);
fram.setResizable(false);
}
public void actionPerformed(ActionEvent e)
{
t=new Thread(new drawpan());
t.start();
}
class drawpan extends JPanel implements Runnable
{
public drawpan()
{
s1=text1.getText();
n1=Double.parseDouble(s1);
x=(int)Math.cos(n1)*len;
y=(int)Math.sin(n1)*len;
s2=text2.getText();
n2=Integer.parseInt(s2);
dx=0;
dy=0;
}
public void paint(Graphics g)
{
g.drawLine(0,0,x,y);
}
public void update(Graphics g)
{
g.drawLine(dx,dy,x,y);
if(x>300)
{
x=-x;
g.drawLine(dx,dy,x,y);
}
else if(y>280)
{
y=-y;
g.drawLine(dx,dy,x,y);
}
else if(x>300||y>280)
{
x=-x;
y=-y;
g.drawLine(dx,dy,x,y);
}
}
public void run()
{
while(i<n2)
{
x=x+1;
y=y+1;
dx=dx+1;
dy=dy+1;
i++;
try
{
Thread.sleep(100);
}catch(InterruptedException e){return;}
repaint();
}
}
}
}