【发布时间】:2013-12-07 15:23:47
【问题描述】:
好的,我有一个这样的 JPanel:
public class GUI {
JFrame frame = new JFrame("Net");
JPanel panel = new JPanel();
public GUI()
{
frame.setSize(835,650);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setVisible(true);
frame.add(panel);
panel.setSize(600,600);
panel.setLocation(215,5);
panel.add(new DrawPlanes(300,300,200,Color.BLACK));}
那里的表格等还有其他一些面板。我的主要是这个:
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable(){
@Override
public void run(){
//new GUI();
new GUI().buildTable();
}
});
我还有另一门课:
public class DrawPlanes extends JPanel
{
private static int centreX, centreY, radius;
private Color colour;
public DrawPlanes()
{
centreX = 300;
centreY = 300;
radius = 200;
colour = Color.BLACK;
}
public DrawPlanes(int centreX,int centreY, int radius, Color colour)
{
this.centreX = centreX;
this.centreY = centreY;
this.radius = radius;
this.colour = colour;
}
@Override
protected void paintComponent(Graphics g)
{
super.paintComponent(g);
System.out.println("ppp");
Graphics2D g2D = (Graphics2D) g;
g2D.setStroke(new BasicStroke(2F));
g.setColor(Color.BLACK);
g.drawOval(centreX - radius , centreY - radius, radius * 2 , radius * 2);
......
}
}
好的,所以我已将面板的背景颜色设置为红色,以查看整个面板上发生的情况,它是红色的,但我相信图纸所在的位置有一个灰色的小方块。我尝试更改 opaque,因为可能存在不兼容问题,但没有任何改变。任何建议,我有什么遗漏的吗?
结果的链接
panel.add(new DrawPlanes(300,300,200,Color.BLACK))
当我检查 DrawPlanes 类在 DrawPlanes 本身 http://dc626.4shared.com/img/NPDkiQRJ/s7/142d22f23b0/1451491_586878858047235_191988.jpg?async&rand=0.27479583155781395 中具有主和面板等时,它会绘制什么。当我应用布局管理器时,当我使用 getPreferredSize 覆盖或不覆盖时,灰色方块只会移动到中心整个红色面板显示为灰色。
【问题讨论】:
标签: java swing class object jpanel