A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© 18618120018 中级黑马   /  2014-7-25 17:14  /  980 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 18618120018 于 2014-7-25 17:18 编辑

                我照着教材打的例子,为什么没出现效果,请问是哪里出问题了,点击新建窗口—内部框架 就没反应了

代码如下:
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;

public class MyDesktopPane extends JFrame
implements ActionListener{
        final static JDesktopPane desktopPane=new JDesktopPane();
        public MyDesktopPane(){
                super("MyDesktopPane");       
                JMenuBar menuBar=new JMenuBar();
                JMenu menu=new JMenu("新增窗口");
                JMenuItem menuItem=new JMenuItem("内部框架窗口");
                menu.add(menuItem);
                menuBar.add(menu);
                setJMenuBar(menuBar);
                getContentPane().add(desktopPane);
                menuItem.addActionListener(this);
                setBounds(300,300,300,300);
                setVisible(true);
        }
        public void actionPerformed(ActionEvent e){
                JInternalFrame inFrame=new JInternalFrame("内部框架(圆环)",true,true,true,true);
                Container c=inFrame.getContentPane();
                CirclePanel circlePanel=new CirclePanel();
                JLabel label=new JLabel("圆环");
                c.add(circlePanel,BorderLayout.CENTER);
                c.add(label,BorderLayout.WEST);       
                int w=circlePanel.getImageWidthHeight().width+150;
                int h=circlePanel.getImageWidthHeight().height+50;
                inFrame.setSize(w,h);
                inFrame.reshape(100,50,w,h);
                inFrame.setOpaque(true);
                desktopPane.add(inFrame);
        }
        public static void main(String args[]){
                MyDesktopPane app=new MyDesktopPane();
                app.addWindowListener(new MyWindowListener());       
        }
}
class CirclePanel extends JPanel{
        private ImageIcon imgIcon;
        public CirclePanel(){
                imgIcon=new ImageIcon("1.gif");       
        }
        public void paintComponent(Graphics g){
                imgIcon.paintIcon(this,g,0,0);       
        }
        public Dimension getImageWidthHeight(){
                return new Dimension(imgIcon.getIconWidth(),imgIcon.getIconHeight());
        }
}         

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马