In my program, I have created a menu bar which allows the user to switch between three programs using file chooser. However, it does not seem to be compiling or working. I am pretty sure my code is incorrect however, I could only find a few examples to work with. I have copied the code that for when "Basic" is clicked on, it is supposed to open BasicCalculator.java
. Any help would be appreciated.
JMenuBar menuBar = new JMenuBar();
JMenu calculatorMenu = new JMenu("Calculator");
menuBar.add(calculatorMenu);
JMenuItem basic = new JMenuItem("Basic");
JMenuItem intermediate = new JMenuItem("Intermediate");
JMenuItem scientific = new JMenuItem("Scientific");
basic.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if (e.getActionCommand().equals("Basic")){
JFileChooser fileChooser = new JFileChooser();
fileChooser.setCurrentDirectory(new File(System.getProperty("BasicCalculator.java")));
int result = fileChooser.showOpenDialog(frame);
if (result == JFileChooser.APPROVE_OPTION){
File selectedFile = fileChooser.getSelectedFile();
System.out.println("Selected file: " + selectedFile.getAbsolutePath());
}
}
}
});