Java 使用 ArrayList 中的数据绘制字符串
我有一个 java Graphics 问题,我正在编写一个程序,它读取一个文本文件并显示一些结果。
例如:
文本文件
print("Text",20,100)
print("Hello",135,50)
所需结果 2 屏幕上显示的字符串。 但我只拿最后一张。
我的代码示例:
ArrayList<String[]> StringsToDraw = new ArrayList<String[]>();
//Add some data to the List
StringsToDraw.add(new String[] {"Hello","20","35"});
StringsToDraw.add(new String[] {"World","100","100"});
@Override
public void paint(Graphics g){
Graphics2D g2d = (Graphics2D) g;
for(String[] printMe : StringsToDraw){
drawString(g2d, printMe[0], printMe[1], printMe[2])
}
}
public void drawString(Graphics g2d, String text, String xString, String yString){
int x = Integer.parseInt(xString);
int y = Integer.parseInt(yString);
g2d.drawString(text, x, y);
}
如何更改它以便它可以同时显示它们?
I have a problem with java Graphics, I m writting a program which takes reads a text file and displays some results.
For example:
Text File
print("Text",20,100)
print("Hello",135,50)
Desired result 2 Strings displayed on the screen.
But I only take the last one.
A sample of my code:
ArrayList<String[]> StringsToDraw = new ArrayList<String[]>();
//Add some data to the List
StringsToDraw.add(new String[] {"Hello","20","35"});
StringsToDraw.add(new String[] {"World","100","100"});
@Override
public void paint(Graphics g){
Graphics2D g2d = (Graphics2D) g;
for(String[] printMe : StringsToDraw){
drawString(g2d, printMe[0], printMe[1], printMe[2])
}
}
public void drawString(Graphics g2d, String text, String xString, String yString){
int x = Integer.parseInt(xString);
int y = Integer.parseInt(yString);
g2d.drawString(text, x, y);
}
How can I change it so it can display both of them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的边界框可能太小。试试这个,看看它是否适合你:
You're bounding box might be too small. Try this and see if it works for you: