当前位置: 技术问答>java相关
为何我的actionPerformed没有响应事件?? help
来源: 互联网 发布时间:2015-02-13
本文导语: 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.java测试...
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.java测试");
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);
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+150;
inFrame.setSize(w,h);
inFrame.reshape(100,50,w,h);
inFrame.setOpaque(true);
desktopPane.add(inFrame);
}
public static void main(String args[])
{
mydesktoppane newdesk=new mydesktoppane();
}
}
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());
}
}
为什么点击新建窗口后
没有得到预要的inFrame元件
高手们帮帮忙
help
import java.awt.event.*;
import java.awt.*;
public class mydesktoppane extends JFrame implements ActionListener
{
final static JDesktopPane desktopPane=new JDesktopPane();
public mydesktoppane()
{
super("Mydesktoppane.java测试");
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);
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+150;
inFrame.setSize(w,h);
inFrame.reshape(100,50,w,h);
inFrame.setOpaque(true);
desktopPane.add(inFrame);
}
public static void main(String args[])
{
mydesktoppane newdesk=new mydesktoppane();
}
}
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());
}
}
为什么点击新建窗口后
没有得到预要的inFrame元件
高手们帮帮忙
help
|
在方法public void actionPerformed(ActionEvent e)
的最后加上 inFrame.setVisible(true);
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。