import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ImageViewer
{
public static void main(String args[]){
JFrame frame=new ImageViewerFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}
class ImageViewerFrame extends JFrame
{ private JLabel label;
public void ImageViewFrame(){
setTitle("ImageViewer");
setSize(300,500);
label = new JLabel();
JMenuBar menu=new JMenuBar();
JMenu filemenu=new JMenu("File");
JMenuItem openmenu=new JMenuItem("open");
JMenuItem exitmenu=new JMenuItem("exit");
final JFileChooser chooser=new JFileChooser();
getContentPane().add(label);
setJMenuBar(menu);
menu.add(filemenu);
filemenu.add(openmenu);
filemenu.add(exitmenu);
openmenu.addActionListener( new
ActionListener()
{ public void actionPerformed(ActionEvent e)
{
int r = chooser.showOpenDialog(null);
if (r== JFileChooser.APPROVE_OPTION)
{ String name=chooser.getSelectedFile().getPath();
label.setIcon(new ImageIcon(name));
}
}
});
exitmenu.addActionListener(new
ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});
}
}
我在里面添加的菜单和标签为什么没有显示呀,清高手指点
是不是哪出错了?