import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
private static final long serialVersionUID = 1L;
JButton fileselect_b, search_b, print_b, end_b
; JLabel announce1, announce2, announce3, kensuu, gyo, naiyo
; File file, cdirectory, filelist, filereader
;
int number, kensu, total;
//ボタンや入力欄を作る処理
public stringsearch() {
p.setLayout(null);
this.setSize(500, 600);
this.setTitle("ストリングスサーチ Var.0.01");
fileselect_b
= new JButton("ファイル選択"); fileselect_b.setBounds(325, 40, 130, 25);
fileselect_b.addActionListener(this);
p.add(fileselect_b);
path_f.setBounds(20, 40, 300, 25);
p.add(path_f);
announce1
= new JLabel("検索ファイル名の選択(直接入力可能)"); announce1.setBounds(23, 18, 250, 25);
p.add(announce1);
search_b.setBounds(325, 100, 130, 25);
search_b.addActionListener(this);
p.add(search_b);
keyword_f.setBounds(20, 100, 300, 25);
p.add(keyword_f);
announce2
= new JLabel("検索文字列の入力"); announce2.setBounds(23, 80, 250, 25);
p.add(announce2);
print_b.setBounds(325, 150, 130, 25);
p.add(print_b);
result_f.setBounds(23, 200, 434, 300);
p.add(result_f);
end_b.setBounds(355, 525, 100, 25);
end_b.addActionListener(this);
p.add(end_b);
announce3
= new JLabel("全検索数"); announce3.setBounds(120, 150, 130, 25);
p.add(announce3);
kensuu.setBounds(23, 175, 250, 25);
p.add(kensuu);
gyo.setBounds(100, 175, 250, 25);
p.add(gyo);
naiyo.setBounds(190, 175, 250, 25);
p.add(naiyo);
total_f.setBounds(175, 150, 60, 25);
p.add(total_f);
sl.
setVerticalScrollBarPolicy(JScrollPane.
VERTICAL_SCROLLBAR_ALWAYS); sl.
setHorizontalScrollBarPolicy(JScrollPane.
HORIZONTAL_SCROLLBAR_ALWAYS); sl.setBounds(23, 200, 434, 300);
p.add(sl);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
}
//ファイル選択ボタンを押された時の処理
if (e.getSource().equals(fileselect_b)) {
result_f.setText("");
total_f.setText("");
total = 0;
kensu = 0;
fileselect.
setFileSelectionMode(JFileChooser.
FILES_AND_DIRECTORIES); fileselect.setDialogTitle("ファイルの選択");
int selected = fileselect.showDialog(this, "選択");
file = fileselect.getSelectedFile();
path = file.getAbsolutePath();
path_f.setText(path);
path_f.setText("キャンセルされました。");
path_f.setText("エラーです。");
}
}
//検索ボタンを押された時の処理
if (e.getSource().equals(search_b)) {
keyword = keyword_f.getText();
int i = 0;
total = 0;
kensu = 0;
if (path == null || keyword == null) {
result_f.setText("検索文字列を入力してください");
} else {
result_f.setText("");
try {
// マッチしたかを示す。一度マッチしたら true に変更する。
boolean matched = false;
// ファイル中の行番号
int lineNumber = 1;
// result_f 用メッセージ。マッチした結果はここに追加する。
StringBuilder message = new StringBuilder();
while ((read = br.readLine()) != null) {
if (str.indexOf(keyword) >= 0) {
matched = true;
total++;
kensu++;
message.append(kensu + "件 " + lineNumber + "行 " + read + "\n");
}
lineNumber++;
}
// 結果の出力 - 全検索数
total_f.setText(total + "件");
// 結果の出力 - 件数, 行数, 内容
if (matched) {
result_f.setText(message.toString());
} else {
result_f.setText("検索した文字列が見つかりません");
}
br.close();
result_f.setText("読み込めませんでした。");
result_f.setText("読み込めませんでした。");
}
}
}
if (e.getSource().equals(end_b)) {
}
}
public static void main
(String[] args
) { new stringsearch();
}
}
aW1wb3J0IGphdmF4LnN3aW5nLio7CmltcG9ydCBqYXZhLmF3dC4qOwppbXBvcnQgamF2YS5hd3QuZXZlbnQuQWN0aW9uRXZlbnQ7CmltcG9ydCBqYXZhLmF3dC5ldmVudC5BY3Rpb25MaXN0ZW5lcjsKaW1wb3J0IGphdmEuaW8uKjsKCgpwdWJsaWMgY2xhc3Mgc3RyaW5nc2VhcmNoIGV4dGVuZHMgSkZyYW1lIGltcGxlbWVudHMgQWN0aW9uTGlzdGVuZXIgewoKICAgIHByaXZhdGUgc3RhdGljIGZpbmFsIGxvbmcgc2VyaWFsVmVyc2lvblVJRCA9IDFMOwogICAgSkJ1dHRvbiBma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GlzLCAi6YG45oqeIik7CiAgICAgICAgICAgIGlmIChzZWxlY3RlZCA9PSBKRmlsZUNob29zZXIuQVBQUk9WRV9PUFRJT04pIHsKICAgICAgICAgICAgICAgIGZpbGUgPSBmaWxlc2VsZWN0LmdldFNlbGVjdGVkRmlsZSgpOwogICAgICAgICAgICAgICAgcGF0aCA9IGZpbGUuZ2V0QWJzb2x1dGVQYXRoKCk7CiAgICAgICAgICAgICAgICBwYXRoX2Yuc2V0VGV4dChwYXRoKTsKICAgICAgICAgICAgfSBlbHNlIGlmIChzZWxlY3RlZCA9PSBKRmlsZUNob29zZXIuQ0FOQ0VMX09QVElPTikgewogICAgICAgICAgICAgICAgcGF0aF9mLnNldFRleHQoIuOCreODo+ODs+OCu+ODq+OBleOCjOOBvuOBl+OBn+OAgiIpOwogICAgICAgICAgICB9IGVsc2UgaWYgKHNlbGVjdGVkID09IEpGaWxlQ2hvb3Nlci5FUlJPUl9PUFRJT04pIHsKICAgICAgICAgICAgICAgIHBhdGhfZi5zZXRUZXh0KCLjgqjjg6njg7zjgafjgZnjgIIiKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAvL+aknOe0ouODnOOCv+ODs+OCkuaKvOOBleOCjOOBn+aZguOBruWHpueQhgogICAgICAgIGlmIChlLmdldFNvdXJjZSgpLmVxdWFscyhzZWFyY2hfYikpIHsKICAgICAgICAgICAga2V5d29yZCA9IGtleXdvcmRfZi5nZXRUZXh0KCk7CiAgICAgICAgICAgIGludCBpID0gMDsKICAgICAgICAgICAgdG90YWwgPSAwOwogICAgICAgICAgICBrZW5zdSA9IDA7CiAgICAgICAgICAgIGlmIChwYXRoID09IG51bGwgfHwga2V5d29yZCA9PSBudWxsKSB7CiAgICAgICAgICAgICAgICByZXN1bHRfZi5zZXRUZXh0KCLmpJzntKLmloflrZfliJfjgpLlhaXlipvjgZfjgabjgY/jgaDjgZXjgYQiKTsKICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgIHJlc3VsdF9mLnNldFRleHQoIiIpOwogICAgICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgICAgICBGaWxlUmVhZGVyIGZpbGUgPSBuZXcgRmlsZVJlYWRlcihwYXRoKTsKICAgICAgICAgICAgICAgICAgICBCdWZmZXJlZFJlYWRlciBiciA9IG5ldyBCdWZmZXJlZFJlYWRlcihmaWxlKTsKCiAgICAgICAgICAgICAgICAgICAgLy8g44Oe44OD44OB44GX44Gf44GL44KS56S644GZ44CC5LiA5bqm44Oe44OD44OB44GX44Gf44KJIHRydWUg44Gr5aSJ5pu044GZ44KL44CCCiAgICAgICAgICAgICAgICAgICAgYm9vbGVhbiBtYXRjaGVkID0gZmFsc2U7CgogICAgICAgICAgICAgICAgICAgIC8vIOODleOCoeOCpOODq+S4reOBruihjOeVquWPtwogICAgICAgICAgICAgICAgICAgIGludCBsaW5lTnVtYmVyID0gMTsKCiAgICAgICAgICAgICAgICAgICAgLy8gcmVzdWx0X2Yg55So44Oh44OD44K744O844K444CC44Oe44OD44OB44GX44Gf57WQ5p6c44Gv44GT44GT44Gr6L+95Yqg44GZ44KL44CCCiAgICAgICAgICAgICAgICAgICAgU3RyaW5nQnVpbGRlciBtZXNzYWdlID0gbmV3IFN0cmluZ0J1aWxkZXIoKTsKCiAgICAgICAgICAgICAgICAgICAgd2hpbGUgKChyZWFkID0gYnIucmVhZExpbmUoKSkgIT0gbnVsbCkgewogICAgICAgICAgICAgICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4ocmVhZCk7CgogICAgICAgICAgICAgICAgICAgICAgICBTdHJpbmcgc3RyID0gbmV3IFN0cmluZyhyZWFkKTsKCiAgICAgICAgICAgICAgICAgICAgICAgIGlmIChzdHIuaW5kZXhPZihrZXl3b3JkKSA+PSAwKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBtYXRjaGVkID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRvdGFsKys7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBrZW5zdSsrOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgbWVzc2FnZS5hcHBlbmQoa2Vuc3UgKyAi5Lu2ICAgICAgICAgICIgKyBsaW5lTnVtYmVyICsgIuihjCAgICAgICAgICAiICsgcmVhZCArICJcbiIpOwogICAgICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgICAgICAgICBsaW5lTnVtYmVyKys7CiAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgICAgICAvLyDntZDmnpzjga7lh7rlipsgLSDlhajmpJzntKLmlbAKICAgICAgICAgICAgICAgICAgICB0b3RhbF9mLnNldFRleHQodG90YWwgKyAi5Lu2Iik7CgogICAgICAgICAgICAgICAgICAgIC8vIOe1kOaenOOBruWHuuWKmyAtIOS7tuaVsCwg6KGM5pWwLCDlhoXlrrkKICAgICAgICAgICAgICAgICAgICBpZiAobWF0Y2hlZCkgewogICAgICAgICAgICAgICAgICAgICAgICByZXN1bHRfZi5zZXRUZXh0KG1lc3NhZ2UudG9TdHJpbmcoKSk7CiAgICAgICAgICAgICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICAgICAgICAgICAgcmVzdWx0X2Yuc2V0VGV4dCgi5qSc57Si44GX44Gf5paH5a2X5YiX44GM6KaL44Gk44GL44KK44G+44Gb44KTIik7CiAgICAgICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgICAgICBici5jbG9zZSgpOwoKICAgICAgICAgICAgICAgIH0gY2F0Y2ggKEZpbGVOb3RGb3VuZEV4Y2VwdGlvbiBlMikgewogICAgICAgICAgICAgICAgICAgIHJlc3VsdF9mLnNldFRleHQoIuiqreOBv+i+vOOCgeOBvuOBm+OCk+OBp+OBl+OBn+OAgiIpOwogICAgICAgICAgICAgICAgfSBjYXRjaCAoSU9FeGNlcHRpb24gZTIpIHsKICAgICAgICAgICAgICAgICAgICByZXN1bHRfZi5zZXRUZXh0KCLoqq3jgb/ovrzjgoHjgb7jgZvjgpPjgafjgZfjgZ/jgIIiKTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KCiAgICAgICAgaWYgKGUuZ2V0U291cmNlKCkuZXF1YWxzKGVuZF9iKSkgewogICAgICAgICAgICBTeXN0ZW0uZXhpdCgwKTsKICAgICAgICB9CiAgICB9CgogICAgcHVibGljIHN0YXRpYyB2b2lkIG1haW4oU3RyaW5nW10gYXJncykgewogICAgICAgIG5ldyBzdHJpbmdzZWFyY2goKTsKCiAgICB9Cn0=