标题:请教光线演示程序
取消只看楼主
oujianqiang
Rank: 1
等 级:新手上路
帖 子:138
专家分:0
注 册:2006-5-16
 问题点数:0 回复次数:1 
请教光线演示程序

这是光线演示程序,但是为什么窗口什么也没显示,请教各位大虾,帮忙修改下
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();
}
}
}
}

搜索更多相关主题的帖子: 光线演示 import java awt 
2006-06-13 18:51
oujianqiang
Rank: 1
等 级:新手上路
帖 子:138
专家分:0
注 册:2006-5-16
得分:0 
那该怎么改好呢?

2006-06-14 12:57



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-72037-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.991333 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved