Topic: 一个程序问题:照书输的,但却无法编译,我检查了几遍,实在不知道错在哪了 |
Print this page |
1.一个程序问题:照书输的,但却无法编译,我检查了几遍,实在不知道错在哪了 | Copy to clipboard |
Posted by: io567n Posted on: 2004-10-07 15:13 一个程序问题:我照书输的,但却无法编译,我检查了几遍,实在不知道错在哪了,只好请教各位高手了. 源代码: import java.awt.*; import java.util.StringTokenizer; public class BlinkText extends java.applet.Applet implements Runnable { Thread blinker; String lbl; Font font; int speed; public void init() { font=new java.awt.Font("TimeRoman",Font.PLAIN,24); String att=getParameter("speed"); speed=(att==null)?4001000/Integer.valueOf(att).intValue()); att=getParameter("lbl"); lbl=(att==null)?"Blink":att; } public void paint(Graphics g) { int x=0,y=font.getSize(),space; int red=(int)(Math.random()*50); int green=(int)(Math.random()*50); int blue=(int)(Math.random()*256); Dimension d=size(); g.setColor(Color.black); g.setFont(font); FontMetrics fm=g.getFontMetrics(); space=fm.stringWidth(""); for(StringTokenizer t=new StringTokenizer(lbl);t.hasMoreTokens() { String word=t.nextToken(); int w=fm.stringWidth(word)+space; if(x+w>d.width){ x=0; y+=font.getSize(); } if(Math.random()<0.5) g.setColor(new java.awt.Color((red+y*30)%256,(green+x/3)%256,blue)); else g.setColor(Color.lightGray); g.drawString(word,x,y); x+=w; } } public void start(){ blinker=new Thread(this); blinker.start(); } public void stop(){ blinker.stop(); } public void run(){ while(true){ try{ Thread.currentThread().sleep(speed); } catch(InterruptedException e){ } } } } 编译D:\java\a>javac BlinkText.java后报错: BlinkText.java:38: illegal character: \11 if(Math.random()<0.5) g.setColor(new java.awt.Color((red+y*30)%256,(gr een+x/3)% 256,blue)); ^ BlinkText.java:51: illegal character: \11 public void stop(){ blinker.stop(); ^ BlinkText.java:63: illegal character: \11 ^ BlinkText.java:66: illegal character: \0 |
2.Re:一个程序问题:照书输的,但却无法编译,我检查了几遍,实在不知道错在哪了 [Re: io567n] | Copy to clipboard |
Posted by: aleel_008 Posted on: 2004-10-07 16:01 I think those words may be copyed from some html documents. you must input them using keybord.or replace the words with the space |
3.Re:一个程序问题:照书输的,但却无法编译,我检查了几遍,实在不知道错在哪了 [Re: io567n] | Copy to clipboard |
Posted by: marsboy Posted on: 2004-10-07 18:31 import java.awt.*; import java.util.StringTokenizer; public class BlinkText extends java.applet.Applet implements Runnable { Thread blinker; String lbl; Font font; int speed; public void init() { font=new java.awt.Font("TimeRoman",Font.PLAIN,24); String att=getParameter("speed"); speed=(att==null)?400:1000/Integer.valueOf(att).intValue(); att=getParameter("lbl"); lbl=(att==null)?"Blink":att; } public void paint(Graphics g) { int x=0,y=font.getSize(),space; int red=(int)(Math.random()*50); int green=(int)(Math.random()*50); int blue=(int)(Math.random()*256); Dimension d=size(); g.setColor(Color.black); g.setFont(font); FontMetrics fm=g.getFontMetrics(); space=fm.stringWidth(""); for(StringTokenizer t=new StringTokenizer(lbl);t.hasMoreTokens() { String word=t.nextToken(); int w=fm.stringWidth(word)+space; if(x+w>d.width){ x=0; y+=font.getSize(); } if(Math.random()<0.5) g.setColor(new java.awt.Color((red+y*30)%256,(green+x/3)%256,blue)); else g.setColor(Color.lightGray); g.drawString(word,x,y); x+=w; } } public void start(){ blinker=new Thread(this); blinker.start(); } public void stop(){ blinker.stop(); } public void run(){ while(true){ try{ Thread.currentThread().sleep(speed); } catch(InterruptedException e){ } } } } 比较一下有没有什么区别 for(StringTokenizer t=new StringTokenizer(lbl);t.hasMoreTokens() 还有别的地方 |
4.Re:一个程序问题:照书输的,但却无法编译,我检查了几遍,实在不知道错在哪了 [Re: io567n] | Copy to clipboard |
Posted by: kiffen Posted on: 2004-10-11 17:16 半角错误,请注意你使用的输入发 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |