java 绘画直线的问题

来源:百度知道 编辑:UC知道 时间:2024/05/15 08:53:03
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JFrame;
public class A extends JFrame{
int orgX,orgY;

/**
* @param args
*/
A(){
this.setSize(400,400);
this.setVisible(true);
Graphics g=this.getGraphics();
g.setFont(new Font("null",Font.ITALIC+Font.BOLD,12));
g.setColor(Color.red);

g.drawLine(33, 81, 173, 188);

}
public static void main(String[] args) {

new A();
}
}
请问各位高手,为什么不能显示直线?
都不对,高手快来看看。

能画出来啊
我试拉你在看看
不过一般不这样在上面直接画
加个JLable

this.setVisible(true);
放到构造器最后一句或者倒数第二句试试

this.setVisible(true);
这句在Graphics画完之后再用,这样应该就能显示出来了