当前位置: 技术问答>java相关
怎样在一个Jpanel上画图形?
来源: 互联网 发布时间:2017-04-10
本文导语: 我的界面上添加了16个jpanel,怎么在这些jpanel上画上自己的图形呢? getGriphics() 方法能用来得到jpanel的画布吗? | public class PanelExample extends JPanel { ... public void paintComponent(Graphics g...
我的界面上添加了16个jpanel,怎么在这些jpanel上画上自己的图形呢?
getGriphics() 方法能用来得到jpanel的画布吗?
getGriphics() 方法能用来得到jpanel的画布吗?
|
public class PanelExample extends JPanel
{
...
public void paintComponent(Graphics g)
{//在这儿你想怎么画就怎么画
super.paintComponent(g);
g.drawImage();
g.drawArc();
g.draw3DRect();
.....
}
....
}
{
...
public void paintComponent(Graphics g)
{//在这儿你想怎么画就怎么画
super.paintComponent(g);
g.drawImage();
g.drawArc();
g.draw3DRect();
.....
}
....
}
|
public class PanelExample extends JPanel {
public PanelExample() {
repaint();
}
...
public void paintComponent(Graphics g) {
super.paintComponent(g);
//在这儿你想怎么画就怎么画
g.drawImage();
g.drawArc();
g.draw3DRect();
.....
}
....
}
public PanelExample() {
repaint();
}
...
public void paintComponent(Graphics g) {
super.paintComponent(g);
//在这儿你想怎么画就怎么画
g.drawImage();
g.drawArc();
g.draw3DRect();
.....
}
....
}