一个画图程序paint问题 恩,估计你是通过在JPanel上getGraphics来得到Graphics对象然后进行画图的吧建议你扩展JPanel类,直接重写paint(Graphics g)方法就能够解决这个问题了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 只是在JPanel绘图的,主类继承了jpanel。是直接重写paint函数的,paint函数如下:public void paint(Graphics g){ super.paint(g); Graphics2D g2D=(Graphics2D)g; g2D.setColor(Color.red); g2D.setStroke(new BasicStroke(1.2f)); g2D.setFont(new Font("宋体",0,15)); g2D.drawString("My draw program!",0,-10); for(int i=0;i<trace.size()-1;i++){ g2D.drawLine((int)((Point2D.Double)trace.elementAt(i)).getX(), -(int)((Point2D.Double)trace.elementAt(i)).getY(), (int)((Point2D.Double)trace.elementAt(i+1)).getX(), -(int)((Point2D.Double)trace.elementAt(i+1)).getY()); } g2D.setStroke(new BasicStroke(1.0f)); g2D.setColor(Color.blue); g2D.drawLine(0,0,30,-220); } 在适当的时候使用repaint重画,如何? 不知道这个帖子对你有没有帮助http://expert.csdn.net/Expert/topic/1682/1682278.xml?temp=.8472864 你必须在弹对话框之后显示的调repaint() 你应该覆写paintComponent方法,而不是paint方法public void paintComponent(Graphics g){ super.paintComponent(g); Graphics2D g2D=(Graphics2D)g; g2D.setColor(Color.red); g2D.setStroke(new BasicStroke(1.2f)); g2D.setFont(new Font("宋体",0,15)); g2D.drawString("My draw program!",0,-10); for(int i=0;i<trace.size()-1;i++){ g2D.drawLine((int)((Point2D.Double)trace.elementAt(i)).getX(), -(int)((Point2D.Double)trace.elementAt(i)).getY(), (int)((Point2D.Double)trace.elementAt(i+1)).getX(), -(int)((Point2D.Double)trace.elementAt(i+1)).getY()); } g2D.setStroke(new BasicStroke(1.0f)); g2D.setColor(Color.blue); g2D.drawLine(0,0,30,-220); } Jtable和Jtree设置高度的问题 JMf 怎样通过 索引获得 某个Arraylist 中的数据。。 Hibernate UUID 的问题 请教高手一个“io流”的“文件写入读出”的问题.... sdk的源码为什么不让中国人下载呢 请教目录出错的问题。。。谢谢。。。。 Jbuilder5.0的怪问题 JAVA究竟适合做什么呢?大家都用JAVA来做什么啦 Java单循环链表解约瑟夫问题 请问String 的interface toString(),在构造函数之前被调用还是在之后被调用? 获得当前焦点位置怎么做?
public void paint(Graphics g){
super.paint(g);
Graphics2D g2D=(Graphics2D)g;
g2D.setColor(Color.red);
g2D.setStroke(new BasicStroke(1.2f));
g2D.setFont(new Font("宋体",0,15));
g2D.drawString("My draw program!",0,-10);
for(int i=0;i<trace.size()-1;i++){
g2D.drawLine((int)((Point2D.Double)trace.elementAt(i)).getX(),
-(int)((Point2D.Double)trace.elementAt(i)).getY(),
(int)((Point2D.Double)trace.elementAt(i+1)).getX(),
-(int)((Point2D.Double)trace.elementAt(i+1)).getY());
}
g2D.setStroke(new BasicStroke(1.0f));
g2D.setColor(Color.blue);
g2D.drawLine(0,0,30,-220);
}
http://expert.csdn.net/Expert/topic/1682/1682278.xml?temp=.8472864
super.paintComponent(g);
Graphics2D g2D=(Graphics2D)g;
g2D.setColor(Color.red);
g2D.setStroke(new BasicStroke(1.2f));
g2D.setFont(new Font("宋体",0,15));
g2D.drawString("My draw program!",0,-10);
for(int i=0;i<trace.size()-1;i++){
g2D.drawLine((int)((Point2D.Double)trace.elementAt(i)).getX(),
-(int)((Point2D.Double)trace.elementAt(i)).getY(),
(int)((Point2D.Double)trace.elementAt(i+1)).getX(),
-(int)((Point2D.Double)trace.elementAt(i+1)).getY());
}
g2D.setStroke(new BasicStroke(1.0f));
g2D.setColor(Color.blue);
g2D.drawLine(0,0,30,-220);
}