JPanel子类显示不出来 200
publicclassMyDrawPanelextendsJPanel{@Overridepublicvoidpaint(Graphicsg){g.setColor(Co...
public class MyDrawPanel extends JPanel {
@Override
public void paint(Graphics g) {
g.setColor(Color.GREEN);
g.drawRect(20, 50, 100,100);
}
public static void main(String[] args) {
JFrame jf=new JFrame();
MyDrawPanel panel=new MyDrawPanel();
jf.getContentPane().add(BorderLayout.CENTER,panel);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setSize(600,600);
jf.setVisible(true);
}
} 展开
@Override
public void paint(Graphics g) {
g.setColor(Color.GREEN);
g.drawRect(20, 50, 100,100);
}
public static void main(String[] args) {
JFrame jf=new JFrame();
MyDrawPanel panel=new MyDrawPanel();
jf.getContentPane().add(BorderLayout.CENTER,panel);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setSize(600,600);
jf.setVisible(true);
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询