当前位置: 代码迷 >> Java相关 >> 画线如何实现?
  详细解决方案

画线如何实现?

热度:86   发布时间:2006-04-29 09:44:00.0
画线如何实现?

编程如何实现在手标两点之间画一条线。不使用mousedrag

还有创建两个线程的实例,分别将一个数组从小到大和从大到小排列?大家也帮忙看看!谢谢!

搜索更多相关的解决方案: 如何  实现  

----------------解决方案--------------------------------------------------------
不用这样
把两个点的坐标记下来,再调用g.drawLine()就可以了

----------------解决方案--------------------------------------------------------
可以不可以编给我看看,我没写多久。
----------------解决方案--------------------------------------------------------
没编多久的话,你就先学学JAVA基础的东西,那一定的时候了,你就自然而然的会画线了
----------------解决方案--------------------------------------------------------
以前写过的一个里面用到画线方法了 简单屏保的Applet
贴出来你看看:
/*<applet code="Screen.class",width=500 height=500>
</applet>*/
import java.awt.*;
import java.awt.event.*;
import java.awt.color.*;
import java.applet.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import java.lang.*;
public class Screen extends JApplet implements Runnable{
int a,b,c,d,e,f,h,i;
//int const=10000;
public void init(){
resize(500,500);
Container cp=getContentPane();

}
public void run(){
try{
System.out.println("");
}
catch(Exception e){
}

}
public void paint(Graphics g){
//Thread t=new Thread()
for(i=0;i<1000;i++){
a=(int)(Math.random()*500);
b=(int)(Math.random()*500);
c=(int)(Math.random()*500);
d=(int)(Math.random()*500);
e=(int)(Math.random()*256);
f=(int)(Math.random()*256);
h=(int)(Math.random()*256);
g.setColor(new Color(e,f,h));
g.drawLine(a,b,c,d);

if (i<1000)

try
{Thread.sleep(10);}
catch(Exception e) {}}

//g.setColor(Color.blue);
if (i==1000){
i=0;
super.paint(g);
repaint();
}
}

}

----------------解决方案--------------------------------------------------------
哦,我会了。谢谢2位版主
----------------解决方案--------------------------------------------------------
  相关解决方案