Panel p11 = new Panel(); Panel p12 = new Panel(); Panel p13 = new Panel(); Panel p14 = new Panel(); p10.setLayout(new FlowLayout()); p11.setLayout(new FlowLayout()); p12.setLayout(new FlowLayout()); p13.setLayout(new FlowLayout()); p14.setLayout(new FlowLayout()); p10.add(l1); p11.add(ph1); p11.add(b1); p12.add(l2); p13.add(ph2); p13.add(b2); p14.add(b3); p1.add(p10); p1.add(p11); p1.add(p12); p1.add(p13); p1.add(p14); add(p1); add(ps); // add listener b1.addActionListener(new CFileChooseLis(ph1)); b2.addActionListener(new CFileChooseLis(ph2)); initFile(); b3.addActionListener(new CAnalyzeLis(this, area)); } public File getAnalyzeFile() {return f1;} public File getDictionFile() {return f2;}
public void initFile() { f1 = ph1.getText().equals(\ new File(ph1.getText()); f2 = ph2.getText().equals(\ new File(ph2.getText()); } public static void main(String[] args) { FileTextChecker f = new FileTextChecker(); } } class IntString extends Object { int num = 0; public IntString(int i) {num = i; } public int getNumber() {return num;} public void add() {num += 1;} } class CFileChooser extends JFileChooser { // @override public boolean accept(File f) { if (f == null) return false; if (f.isDirectory()) return true; if (f.getAbsolutePath().endsWith(\ return true; return false;} public boolean choosedFile() { int state = this.showOpenDialog(null); File f = this.getSelectedFile();
if (accept(f) && state == JFileChooser.APPROVE_OPTION) {return true;} return false;} } class CFileChooseLis implements ActionListener { public CFileChooseLis(TextComponent rst) { t = rst;} TextComponent t; public void actionPerformed(ActionEvent e) { if (t == null) return; CFileChooser chooser = new CFileChooser(); if (chooser.choosedFile()) { File f = chooser.getSelectedFile(); t.setText(f.getAbsolutePath());} } } class CAnalyzeLis implements ActionListener { File analyzeF; File dictionaryF; TextComponent rst; Window window; public CAnalyzeLis(FileTextChecker w, TextComponent tcomp) { analyzeF = w.getAnalyzeFile(); dictionaryF = w.getDictionFile(); rst = tcomp; window = w; }
// @Override public void actionPerformed(ActionEvent e) { ((FileTextChecker)window).initFile(); analyzeF = ((FileTextChecker)window).getAnalyzeFile(); dictionaryF = ((FileTextChecker)window).getDictionFile(); if (analyzeF == null) { JOptionPane.showMessageDialog(window, \未添加分析文档,点击“确定”重新添加.\ return;} if (dictionaryF == null) { JOptionPane.showMessageDialog(window, \未添加敏感词汇库,点击“确定”重新添加.\ return;} Set
table.get(s).add(); } else { table.put(s, new IntString(1)); } } } } Iterator