我在appletviewer里看到的显示很是重叠的,我怎么才能让它显示清楚呢?多谢大家了

iceandfire 2002-11-17 08:29:17
请帮我看看这段程序,让它能在appletviewer里清晰的显示

import java.awt.*;
import java.applet.*;
import java.util.*;
import java.text.*;

class Queue3 extends Vector
{
Queue3()
{
super();
}
Queue3(int capacity)
{
super(capacity);
//System.out.println("call this()");
}
Queue3(String[] objs)
{
this(objs.length);
for (int index=0;index<objs.length;index++)
{
addElement(objs[index]);
}
}

Object dequeue()
{
Object obj=firstElement();
boolean success=removeElement(obj);
return obj;
}
}

public class Queue extends Applet
{
public void paint(Graphics g)
{
String[] s={"2002-08-09 20:00:00","2002-08-10 21:00:05","2002-08-11 22:00:32"};
Queue3 queue=new Queue3(s);
String[] s1=new String[5];
Date[] dt=new Date[5];

for (int i=0;i<s.length;i++)
{
s1[i]=(String)queue.dequeue();
SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
try
{
dt[i]=df.parse(s1[i]);
}
catch(ParseException e)
{
g.drawString("ParseException caught.",10,10);
}
}
for (int i=0;i<s.length;i++)
{
g.drawString("dt["+i+"]="+dt[i],10,10);
}
}
}

...全文
30 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
希偌 2002-11-17
  • 打赏
  • 举报
回复
主要是这句g.drawString("dt["+i+"]="+dt[i],10,10);
把间隔适当放大,其实你完全可以得到字符串的长和高,如下:
String str="beyond_xiruo";
Font font;
if(this.getFont()==null)
font = new Font("Times Roman", Font.PLAIN, 20);
else
font=this.getFont();
FontMetrics fm=this.getFontMetrics(font);
System.out.print(fm.stringWidth(str)+"*");
System.out.print(fm.getHeight());
iceandfire 2002-11-17
  • 打赏
  • 举报
回复
多谢,我也看到了~~可以结贴了
Iforgot 2002-11-17
  • 打赏
  • 举报
回复
对,哦,原来是指绘图重叠啊!:)
netwebs 2002-11-17
  • 打赏
  • 举报
回复
把最后的改为,这么画当然要重叠了
for (int i=0;i<s.length;i++)
{
g.drawString("dt["+i+"]="+dt[i],10,10*i);
}
Iforgot 2002-11-17
  • 打赏
  • 举报
回复
setSize试试,比较懒没看代码。

62,615

社区成员

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

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