JAVA  新手问题 如何在JFrame里画一条直线 

解决方案 »

  1.   

        public void paint(Graphics g) {
            g.drawLine(x1, y1, x2, y2)
        }(x1,y1)和(x2,y2)分别是两个端点坐标。
      

  2.   

    public class Test {
        /**
         * @param args
         */
        public static void main(String[] args) throws Exception {
    // TODO Auto-generated method stub
    JFrame kkk = new lll();
        }
    }
    class lll extends JFrame{
        public lll(){
    this.setTitle("test");
    this.setSize(500,400);
    this.setVisible(true);
        }    @Override
        public void paint(Graphics g) {
    // TODO Auto-generated method stub
    super.paint(g);
    g.drawLine(10, 10, 100, 100);
        }    
    }
      

  3.   

    1楼和2楼 都可以建议使用netbeans 直接可视化编辑