绘制线段和文字
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);
}
}
网友评论