-
Notifications
You must be signed in to change notification settings - Fork 5
DirectoryViewer
Michael Karneim edited this page May 9, 2018
·
1 revision
package wiki.quickstart;
import java.awt.BorderLayout;
import java.io.File;
import javax.swing.JFrame;
import javax.swing.UIManager;
/**
* The DirectoryViewer shows the contents of a given directory.
*/
public class DirectoryViewer {
// Create the model
DirectoryViewerPM model = new DirectoryViewerPM();
// Create the view
DirectoryViewerPanel view = new DirectoryViewerPanel();
// Create a window for the view
JFrame frame = new JFrame();
public DirectoryViewer() {
// bind the view directly to the model
view.setPresentationModel(model);
// place the view inside the window
frame.add( view, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo( null);
}
public void show(File dir) {
// put the data into the model
model.setDirectory(dir);
// show the window
frame.setVisible(true);
}
/**
* The main-routine
* @param args
*/
public static void main(String args[]) throws Exception {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
// Create the application and show the data from the user's home directory
new DirectoryViewer().show(new File(System.getProperty("user.home")));
}
}