关于JInternalFrame问题 JAVA

-----------------------MyDesktopPane.JAVA---------------------------importjava.awt.*;... -----------------------MyDesktopPane.JAVA---------------------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class MyDesktopPane extends JFrame implements ActionListener {

/**
* Creates a new instance of <code>MyDesktopPane</code>.
*/
final static JDesktopPane desktopPane=new JDesktopPane();

public MyDesktopPane() {
super("MyDesktopPane.java:JDesktopPane测试");
JMenuBar menuBar=new JMenuBar();
JMenu menu=new JMenu("新增菜单");
JMenuItem menuItem=new JMenuItem("内部框架窗口");
menu.add(menuItem);
menuBar.add(menu);
getContentPane().add(desktopPane);
getContentPane().add(menuBar,BorderLayout.NORTH);
menuItem.addActionListener(this);
setSize(350,200);
show();
}
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);
desktopPane.show();

}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
MyDesktopPane app=new MyDesktopPane();
app.addWindowListener(new MyWindowListener());
}
class CirclePanel extends JPanel{
private ImageIcon imgIcon;
public CirclePanel()
{
imgIcon=new ImageIcon("circle.gif");
}
public void paintComponent(Graphics g)
{
imgIcon.paintIcon(this,g,0,0);
}
public Dimension getImageWidthHeight()
{
return new Dimension(imgIcon.getIconWidth(),imgIcon.getIconHeight());
}

}
}

--------------------------MyWindowListener--------------------------
import java.awt.*;
import java.awt.event.*;

class MyWindowListener extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(1);
}
}

public void actionPerformed(ActionEvent e)中的内部框架怎么显示不出来呀? 麻烦各位高人看一看! ……不胜感激
展开
 我来答
韦涵涵
2009-04-18 · TA获得超过3892个赞
知道大有可为答主
回答量:1034
采纳率:100%
帮助的人:1510万
展开全部
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(c);
desktopPane.add(inFrame);
desktopPane.setBounds(0, 0, 300, 200);
JFrame frame=new JFrame();
frame.setBounds(0, 0, 300, 200);
frame.add(desktopPane);
frame.add(c);
frame.setVisible(true);
}

已经为楼主实现了..

只需要改这个方法就可以了...

楼主主要就是忘了把 panel 放到 JFrame 中

因为 Panel 是不能单独存在的...

必须放到 框架里面才能显示....

祝楼主早日成功!!!
lesson111
2009-04-21
知道答主
回答量:23
采纳率:0%
帮助的人:0
展开全部
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);
desktopPane.show();

}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
MyDesktopPane app=new MyDesktopPane();
app.addWindowListener(new MyWindowListener());
}
class CirclePanel extends JPanel{
private ImageIcon imgIcon;
public CirclePanel()
{
imgIcon=new ImageIcon("circle.gif");
}
public void paintComponent(Graphics g)
{
imgIcon.paintIcon(this,g,0,0);
}
public Dimension getImageWidthHeight()
{
return new Dimension(imgIcon.getIconWidth(),imgIcon.getIconHeight());
}

}
}

--------------------------MyWindowListener--------------------------
import java.awt.*;
import java.awt.event.*;

class MyWindowListener extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(1);
}
}

public void actionPerformed(ActionEvent e)中的内部框架怎么显示不出来呀? 麻烦各位高人看一看! ……不胜感激
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式