Skip to content

Instantly share code, notes, and snippets.

@rjayako
Created March 4, 2011 23:45
Show Gist options
  • Save rjayako/855921 to your computer and use it in GitHub Desktop.
Save rjayako/855921 to your computer and use it in GitHub Desktop.
FileController :
public class FileController implements ActionListener {
public void actionPerformed(ActionEvent e) {
System.out.println("Action!:" + e.getActionCommand());
if( e.getActionCommand().equals(Command.LOAD.toString())){
doLoad();
}
if( e.getActionCommand().equals(Command.SAVE.toString())){
doSave();
}
}
public void doLoad()
{
JFileChooser fileChooser = new JFileChooser();
fileChooser.showOpenDialog(null);
File selected = fileChooser.getSelectedFile();
System.out.println(selected);
}
public void doSave()
{
}
}
view.java
public class FileView extends JFrame {
public FileView(FileController controller)
{
setTitle("FileEditor 1.0");
setSize(500,500);
setLayout(new BorderLayout());
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("File");
JMenuItem loadMenuItem = new JMenuItem("Open Sesame");
JMenuItem saveMenuItem = new JMenuItem("Save");
loadMenuItem.addActionListener(controller);
loadMenuItem.setActionCommand(Command.LOAD.toString());
saveMenuItem.addActionListener(controller);
saveMenuItem.setActionCommand(Command.SAVE.toString());
menu.add(loadMenuItem);
menu.add(saveMenuItem);
menuBar.add(menu);
this.setJMenuBar(menuBar);
getContentPane().add(new JTextArea(), BorderLayout.CENTER);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
}
Main.java
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
File file = new File("./foo.txt");
FileController controller = new FileController();
FileView view = new FileView(controller);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment