标题:单击 "Internal Frame"没有反应 请指教
只看楼主
事过境迁
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2006-8-2
 问题点数:0 回复次数:1 
单击 "Internal Frame"没有反应 请指教

//DesktopTest.java
//Demonstating JDesktopPane
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class DesktopTest extends JFrame{
public DesktopTest(){
super("Using a JDesktopPane");

JMenuBar bar=new JMenuBar();
JMenu addMenu=new JMenu("Add");
JMenuItem newFrame=new JMenuItem("Internal Frame");
addMenu.add(newFrame);
bar.add(addMenu);
setJMenuBar(bar);

final JDesktopPane theDesktop=new JDesktopPane();
getContentPane().add(theDesktop);

newFrame.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
JInternalFrame aframe=new JInternalFrame("Internal Frame",true,true,true,true);
//内部窗口标题栏,能否改变内部窗大小,能否关闭内部窗,能否最大化,能否最小化

Container c=aframe.getContentPane();
MyJPanel panel=new MyJPanel();

c.add(panel,BorderLayout.CENTER);
aframe.setSize(panel.getImageWidthHeight().width,panel.getImageWidthHeight().height);
aframe.setOpaque(true); //窗口不透明
theDesktop.add(aframe);
}
}
);

setSize(500,400);
show();
}

public static void main(String args[]){
DesktopTest app=new DesktopTest();

app.addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
);
}
}

class MyJPanel extends JPanel{
private ImageIcon imgIcon;

public MyJPanel(){
imgIcon=new ImageIcon("buganim.gif");
}

public void paintComponent(Graphics g){
super.paintComponent(g);
imgIcon.paintIcon(this,g,0,0);
}

public Dimension getImageWidthHeight(){
return new Dimension(imgIcon.getIconWidth(),imgIcon.getIconHeight());
}
}

搜索更多相关主题的帖子: Frame 单击 Internal 指教 
2007-05-07 17:21
事过境迁
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2006-8-2
得分:0 
没人?
2007-05-08 21:50



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-137459-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.461821 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved