关于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)中的内部框架怎么显示不出来呀? 麻烦各位高人看一看! ……不胜感激 展开
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)中的内部框架怎么显示不出来呀? 麻烦各位高人看一看! ……不胜感激 展开
2个回答
展开全部
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 是不能单独存在的...
必须放到 框架里面才能显示....
祝楼主早日成功!!!
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 是不能单独存在的...
必须放到 框架里面才能显示....
祝楼主早日成功!!!
展开全部
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)中的内部框架怎么显示不出来呀? 麻烦各位高人看一看! ……不胜感激
{
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)中的内部框架怎么显示不出来呀? 麻烦各位高人看一看! ……不胜感激
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询