java工具类之Graphics

利用重写paint()方法绘画出一个坐标轴:

package huaxian;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics; import javax.swing.JFrame;
import javax.swing.JPanel; public class huaxian2 extends JFrame { private JPanel jp;
private JFrame jf; public static void main(String[] args) {
// TODO Auto-generated method stub
huaxian2 h2 = new huaxian2();
} public huaxian2(){ this.setSize(500, 500);
this.setVisible(true);
this.setDefaultCloseOperation(jf.EXIT_ON_CLOSE); jp = new JPanel();
this.add(jp); } @Override
public void paint(Graphics g){
super.paint(g);
g.drawLine(50, 350, 498, 350);
g.drawLine(50, 50, 50, 350);
}
}

  点击运行结果:

java工具类之Graphics

上一篇:8.2.1.5 Engine Condition Pushdown Optimization 引擎条件下推优化


下一篇:Linux下用来获取各种系统信息的C++类