23.07.2013 Views

Java IO.pdf - Nguyen Dang Binh

Java IO.pdf - Nguyen Dang Binh

Java IO.pdf - Nguyen Dang Binh

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

}<br />

}<br />

}<br />

theView.setText("");<br />

OutputStream out = theView.getOutputStream();<br />

try {<br />

FileInputStream in = new FileInputStream(f);<br />

FileDumper5.dump(in, out, mp.getMode(), mp.isBigEndian(),<br />

mp.isDeflated(), mp.isGZipped(), mp.getPassword());<br />

}<br />

catch (<strong>IO</strong>Exception ex) {<br />

}<br />

<strong>Java</strong> I/O<br />

}<br />

else if (e.getActionCommand().equals(JFileChooser.CANCEL_SELECT<strong>IO</strong>N)) {<br />

this.closeAndQuit();<br />

}<br />

public void windowClosing(WindowEvent e) {<br />

this.closeAndQuit();<br />

}<br />

// Do-nothing methods for WindowListener.<br />

public void windowOpened(WindowEvent e) {}<br />

public void windowClosed(WindowEvent e) {}<br />

public void windowIconified(WindowEvent e) {}<br />

public void windowDeiconified(WindowEvent e) {}<br />

public void windowActivated(WindowEvent e) {}<br />

public void windowDeactivated(WindowEvent e) {}<br />

private void closeAndQuit() {<br />

}<br />

this.setVisible(false);<br />

this.dispose();<br />

System.exit(0);<br />

public static void main(String[] args) {<br />

}<br />

FileViewer fv = new FileViewer();<br />

fv.init();<br />

fv.show();<br />

FileViewer implements the WindowListener interface simply so that it will be closed when<br />

the user clicks the Close box. It also implements the ActionListener interface. However, the<br />

action events that its actionPerformed() method responds to are fired by the file chooser,<br />

indicating that the user pressed the View File button.<br />

When the user presses the View File button, the mode panel is read to determine exactly how<br />

the file is to be interpreted. These parameters and the selected file are fed to the static<br />

FileDumper5.dumpFile() method from Chapter 10.<br />

The next new class in this application is the ModePanel, shown in Example 13.13. This class<br />

provides a simple user interface to allow the user to specify the format the file is in, whether<br />

and how it's compressed, and the password, if any. This part of the GUI is completely<br />

contained inside this class. Other methods that need access to this information can query the<br />

333

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!