标签:
利用重写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); } }
点击运行结果:
标签:
原文地址:http://www.cnblogs.com/xiangxi/p/4779281.html