嗨,我有MainFrame
课:
public class MainFrame extends JFrame{
private JLabel originalLabel;
private JLabel filteredImage;
public MainFrame(){
setExtendedState(JFrame.MAXIMIZED_BOTH);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
initComponents();
setVisible(true);
}
private void initComponents(){
ImageFilterMenuBar menuBar = new ImageFilterMenuBar();
originalLabel = new JLabel("Test1");
filteredImage = new JLabel("Test2");
Component verticalStrut = Box.createVerticalStrut(10);
JPanel central = new JPanel();
central.add(originalLabel);
central.add(verticalStrut);
central.add(filteredImage);
add(new RadioButtonsPanel(), BorderLayout.SOUTH);
add(central, BorderLayout.CENTER);
setJMenuBar(menuBar);
}
}
和MenuBar
类:
public class ImageFilterMenuBar extends JMenuBar{
private JMenu fileMenu;
private JMenuItem openImage;
private JMenuItem exit;
public ImageFilterMenuBar(){
initCompoments();
}
private void initCompoments() {
fileMenu = new JMenu("File");
setMenuItems();
add(fileMenu);
}
private void setMenuItems(){
openImage = new JMenuItem("Open Image");
exit = new JMenuItem("Exit");
openImage.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,
InputEvent.CTRL_MASK));
exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_CANCEL,InputEvent.SHIFT_MASK));
openImage.addActionListener(new OpenListener());
exit.addActionListener(new ExiteListener());
fileMenu.add(openImage);
fileMenu.add(exit);
}
}
在 MenuBar 类中,您可以使用 OpenButton。它打开 JFileChooser 并返回我选择的文件的 url。所以现在我不知道如何将这个 url 发送到我想显示这个文件的 MainFrame 类中。有什么想法吗?