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.

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

numeric data. If they choose text, you'll need to use a reader to read the file instead of an input<br />

stream. You'll also need to provide some means for the user to pick the encoding they want<br />

text read in (e.g., MacRoman, ISO Latin-1, Unicode, etc). Since there are several dozen text<br />

encodings, the best choice is a list box. All of this can be integrated into the mode panel.<br />

Figure 15.1 shows the revised ModePanel2 class. The code is given in Example 15.9. Two<br />

new public methods are added, isText() and getEncoding(). The rest of the changes are<br />

fairly minor ones to set up the GUI.<br />

Figure 15.1. A mode panel with a list box for encodings<br />

Example 15.9. ModePanel2<br />

import java.awt.*;<br />

import javax.swing.*;<br />

public class ModePanel2 extends JPanel {<br />

JCheckBox bigEndian = new JCheckBox("Big Endian", true);<br />

JCheckBox deflated = new JCheckBox("Deflated", false);<br />

JCheckBox gzipped = new JCheckBox("GZipped", false);<br />

ButtonGroup dataTypes = new ButtonGroup();<br />

JRadioButton asciiRadio = new JRadioButton("Text");<br />

JRadioButton decimalRadio = new JRadioButton("Decimal");<br />

JRadioButton hexRadio = new JRadioButton("Hexadecimal");<br />

JRadioButton shortRadio = new JRadioButton("Short");<br />

JRadioButton intRadio = new JRadioButton("Int");<br />

JRadioButton longRadio = new JRadioButton("Long");<br />

JRadioButton floatRadio = new JRadioButton("Float");<br />

JRadioButton doubleRadio = new JRadioButton("Double");<br />

JTextField password = new JTextField();<br />

final static String[] encodings = {"8859_1", "8859_2", "8859_3",<br />

"8859_4",<br />

"8859_5", "8859_6", "8859_7", "8859_8", "8859_9", "Big5", "CNS11643",<br />

"Cp037", "Cp273", "Cp277", "Cp278", "Cp280", "Cp284", "Cp285", "Cp297",<br />

387

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

Saved successfully!

Ooh no, something went wrong!