关于JPanel的问题 在主类中有很多的Panel,没个Panel里都有很多组件,整个主类显的特别长,也特别乱,一点层次也没有,时间久了自己也看不懂写的什么了.我就是想把每个Panel都单独的写一个类,然后在主类里分别去调用这些Panel.是不是这个思路就是所谓的继承Panel重写Panel类呢?但是这样一个类要怎么写呢?能不能给个例子... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 直接继承JPanel即可, 把组件都放在该面板中, 然后在主类新建该类. 下面只是一个简单的示例, 没有排版.public class Animater extends JPanel{private JButton jButton1;private JLabel jLabel1; Animater(){ super(new BorderLayout()); jLabel1 = new JLabel(); jButton1 = new JButton(); this.addComponent(jLabel1); this.addComponent(jButton1); } protected void paintComponent(Graphics g){ super.paintComponent(g); ImageIcon img=new ImageIcon("E:\\2.jpg"); img.paintIcon(this, g, 0, 0); }} 不好意思, 发错了. 应该是this.add(jLabel1);this.add(jButton1);而不是this.addComponent(jLabel1);this.addComponent(jButton1); try里面有个return 那后面的finally还执行吗? 线程问题 如何获得局域网开放某个端口的所有机器IP 请问JDK文件中的JRE和在安装JDK过程中安装的JRE有什么两样? 请教一个struts2的问题 一个连接池的问题: 如何从ImageIcon获取BufferedImage unix下如何连接数据库? 悄悄的问各位:jbuilder6的系列号? CLASSPATH问题,我实在受不了了,高手帮我看看 九九乘法 100元求高手改java小程序,功能完善立即付费!
private JButton jButton1;
private JLabel jLabel1; Animater(){
super(new BorderLayout()); jLabel1 = new JLabel();
jButton1 = new JButton(); this.addComponent(jLabel1);
this.addComponent(jButton1);
} protected void paintComponent(Graphics g){
super.paintComponent(g);
ImageIcon img=new ImageIcon("E:\\2.jpg");
img.paintIcon(this, g, 0, 0);
}
}
应该是this.add(jLabel1);
this.add(jButton1);而不是this.addComponent(jLabel1);
this.addComponent(jButton1);