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.

public void init() {<br />

}<br />

this.addWindowListener(this);<br />

fc.setApproveButtonText("View File");<br />

fc.setApproveButtonMnemonic('V');<br />

fc.addActionListener(this);<br />

this.getContentPane().add("Center", fc);<br />

JScrollPane sp = new JScrollPane(theView);<br />

this.getContentPane().add("South", sp);<br />

this.getContentPane().add("West", mp);<br />

this.pack();<br />

// Center on display.<br />

Dimension display = getToolkit().getScreenSize();<br />

Dimension bounds = this.getSize();<br />

int x = (display.width - bounds.width)/2;<br />

int y = (display.height - bounds.height)/2;<br />

if (x < 0) x = 10;<br />

if (y < 0) y = 15;<br />

this.setLocation(x, y);<br />

public void actionPerformed(ActionEvent e) {<br />

}<br />

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

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

File f = fc.getSelectedFile();<br />

if (f != null) {<br />

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

try {<br />

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

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

if (!mp.isText()) {<br />

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

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

}<br />

else {<br />

FileDumper6.dump(in, out, mp.getEncoding(), null,<br />

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

}<br />

}<br />

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

}<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 />

393

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

Saved successfully!

Ooh no, something went wrong!