编写了一个小程序.
import java.applet.*;
import java.awt.*;
public class Boy extends Applet
{
public void paint(Graphics g)
{
g.setColor(Color.red);
g.drawString("我一边喝着咖啡,一边学Java呢"); //出错了.
g.setColor(Color.blue);
g.drawString("我学得很认真",10,50);
}
}
在eclipse 编写的.
结果出错了:
Exception in thread "AWT-EventQueue-1" java.lang.Error: Unresolved compilation problem:
The method drawString(String, int, int) in the type Graphics is not applicable for the arguments (String)
at Boy.paint(Boy.java:9)
at sun.awt.RepaintArea.paintComponent(RepaintArea.java:248)
at sun.awt.RepaintArea.paint(RepaintArea.java:224)
at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:301)
at java.awt.Component.dispatchEventImpl(Component.java:4489)
at java.awt.Container.dispatchEventImpl(Container.java:2116)
at java.awt.Component.dispatchEvent(Component.java:4243)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
不知是什么原因???请各位帮忙???谢谢...
------解决方案--------------------
The method drawString(String, int, int) in the type Graphics is not applicable for the arguments (String)
类Graphics 的方法drawString(String, int, int) 无法接受String行参数.
------解决方案--------------------
g.drawString("我一边喝着咖啡,一边学Java呢" ,x,x); //出错了.
x为int 型 建议去看看啊api
abstract void drawString(AttributedCharacterIterator iterator, int x, int y)
使用此图形上下文的当前颜色绘制由指定迭代器给定的文本。
abstract void drawString(String str, int x, int y)
使用此图形上下文的当前字体和颜色绘制由指定 string 给定的文本。