求大神看一下哪有错误

略懂略懂 2015-01-12 10:27:21
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Container;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;//它包含鼠标的点击\按下\松开\进入\离开事件
import java.awt.event.MouseMotionListener;//它包含鼠标的移动\ 拖动
import javax.swing.JFrame;
public class AutoDrawingLines extends JFrame{
private int x1,y1;
private int x2,y2;

private Graphics2D g2;
public AutoDrawingLines(){
super("画图板");
//1 调用方法获取一个容器
Container c = this.getContentPane();
// 设置容器的布局方式为null(即:取消容器的默认布局方式)
c.setLayout(null);
//设置容器的背景为白色
c.setBackground(Color.black);
//2 点击窗口的关闭按钮时,会实现窗口的关闭。
this.detDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//4
this.setLocation(400,200);
this.setSize(500,400);
this.setVisible(true);
new Drawing().start();

}
class Drawing extends Thread{
@Override
public void run(){
int centerX = 500/2;
int centerY = 400/2;
//获得一个图形对象
Graphics g = getGraphics();
g2 = (Graphics2D)g;//强制转换成二维模式
g2.setColor( Color.blue);

while(true){
repaint();
//画线条
for(int n = 1;n<=300;n++){
//设置图画的颜色
int red = (int)(255 * Math.random());
iet green = (int)(255 * Math.random());
int blue = (int)(255 * Math.random());
g2.setColor( new Color(red,green,blue));
//设置线条的宽度
float lineWidth = (float)(2.5 * Math.random());
g2.setStroke(new BasicStroke(lienWidth));
if(n % 2!=0){
x2 = (int)(500 * Math.sin(1.5 * 3.14 * Math.random()));
y2 = (int)(400 * Math.sin(1.5 * 3.14 * Math.random()));
}
else{
x2 =(int)(100 + 250 * Math.sin(3.14 * Math.random()));
y2 = (int)(100 + 200 * Math.sin(3.14 * Math.random()));

}
g2.drawLine(centerX,centerY,x2,y2);
try{
Thread.sleep(30);

} catch (InterrupteException e){

e.printStackTrace();
}
}


}
}
}
public static void main(Sting[] args){
new AutoDrawingLines();
}
}




...全文
133 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
skyhitnow 2015-01-13
  • 打赏
  • 举报
回复
用个高级点的ide吧
scott_129 2015-01-12
  • 打赏
  • 举报
回复
if(n % 2!=0){ x2 = (int)(500 * Math.sin(1.5 * 3.14 * Math.random())); y2 = (int)(400 * Math.sin(1.5 * 3.14 * Math.random())); } else{ x2 =(100 + 250 * Math.sin(3.14 * Math.random())); y2 = (int)(100 + 200 * Math.sin(3.14 * Math.random())); } 这是个中文状态下的左括号。 要学会看错误提示,已经提示你60行有非法字符了,你就应该看到你代码的第60行,然后仔细看哪里有问题。
  • 打赏
  • 举报
回复
装个IDE会有错误提示的。。
seeker3589 2015-01-12
  • 打赏
  • 举报
回复
左边括号非英文

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧