当前位置: 代码迷 >> Java相关 >> 单击 "Internal Frame"没有反应 请指教
  详细解决方案

单击 "Internal Frame"没有反应 请指教

热度:879   发布时间:2007-05-07 17:21:57.0
单击 "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  指教  

----------------解决方案--------------------------------------------------------
没人?
----------------解决方案--------------------------------------------------------
  相关解决方案