美文网首页
Java Grapgics

Java Grapgics

作者: 滴答大 | 来源:发表于2018-10-23 19:25 被阅读7次

绘制线段和文字

public class TestPaintComponent  extends JFrame {
 //    UI
public TestPaintComponent (){
   add(new newPanel());
}

public static void main(String[] args) {

    TestPaintComponent frame = new TestPaintComponent();
    frame.setTitle("绘制");
    frame.setSize(300,300);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}
}

class newPanel extends JPanel{
 //成员方法
protected  void paintCompent(Graphics g){
    super.paintComponents(g);
    g.drawLine(0,0,50,50);
    g.drawString("Banner",0,40);

}
}

相关文章

网友评论

      本文标题:Java Grapgics

      本文链接:https://www.haomeiwen.com/subject/zrzazftx.html