一段Java代码!请问高手为什么运行不出结果????

来源:百度知道 编辑:UC知道 时间:2024/06/21 19:54:42
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ShiMS extends JFrame{
ShiMS()
{
setSize(400,400);
setVisible(true);
}
public static void main(String[] args) {
ShiMS shi=new ShiMS();
final MyCanvas mcan=new MyCanvas();
shi.add(mcan);
new Thread()
{
public void run()
{ boolean flag=true;
int count=0;
while(flag)
{
try{
Thread.sleep(1000);
}catch(Exception e){e.printStackTrace();}
mcan.setValue();
mcan.repaint();
count++;
if(count==8) flag=false;
}
}
}.start();
}

}
class MyCanvas extends Canvas{
int x1 ,y1 ,x2 ,y2 ;
MyCanvas()<

因为两个点坐标完全相同,所以成了绘点,稍微修改一下就好了~
另外最好加上退出语句

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ShiMS extends JFrame
{
ShiMS()
{
setSize(400, 400);
setVisible(true);
//最好这样
setDefaultCloseOperation(EXIT_ON_CLOSE);
}

public static void main(String[] args)
{
ShiMS shi = new ShiMS();
final MyCanvas mcan = new MyCanvas();
shi.add(mcan);
new Thread()
{
public void run()
{
boolean flag = true;
int count = 0;
while (flag)
{
try
{
Thread.sleep(1000);
} catch (Exception e)
{
e.printStackTrace();
}
mcan.setValue();
mcan.repaint();
count++;
if (count == 8)