import java.io.*;
import java.awt.*;
import java.awt.event.*;
public class TextMemo {
public static void main
(String args
[]) { TextFrame tf = new TextFrame();
}
}
public TextFrame(){
frm.setMenuBar(mb);
menu1
= new Menu("メニュー"); menu1.add(mi1);
mi1.addActionListener(this);
menu1.add(mi2);
mi2.addActionListener(this);
menu1.add(mi3);
mi3.addActionListener(this);
mb.add(menu1);
frm.add(ta);
frm.setSize(400, 200);
frm.setVisible(true);
windowexit();
}
new FileIO(e, this);
}
private void windowexit(){
}
});
}
}
class FileIO {
TextFrame frame;
if(s.getSource() == frame.mi1) {
frame.ta.setText("");
} else if(s.getSource() == frame.mi2) {
fd.setVisible(true);
fileName = fd.getDirectory() + fd.getFile();
try {
for(String line
; (line
=br.
readLine()) != null; ) { frame.ta.append(line + "\n");
}
ex.printStackTrace();
} finally {
if(br
!= null) { try { br.
close(); } catch(Exception ex
) {} } }
} else if(s.getSource() == frame.mi3) {
fd.setVisible(true);
fileName = fd.getDirectory() + fd.getFile();
try {
bw.write(frame.ta.getText());
bw.flush();
ex.printStackTrace();
} finally {
if(bw
!= null) { try { bw.
close(); } catch(Exception ex
) {} } }
}
}
}
aW1wb3J0IGphdmEuaW8uKjsKaW1wb3J0IGphdmEuYXd0Lio7CmltcG9ydCBqYXZhLmF3dC5ldmVudC4qOwoKcHVibGljIGNsYXNzIFRleHRNZW1vIHsKICAgIHB1YmxpYyBzdGF0aWMgdm9pZCBtYWluKFN0cmluZyBhcmdzW10pIHsKICAgICAgICBUZXh0RnJhbWUgdGYgPSBuZXcgVGV4dEZyYW1lKCk7CiAgICB9Cn0KCmNsYXNzIFRleHRGcmFtZSBpbXBsZW1lbnRzIEFjdGlvbkxpc3RlbmVyewogICAgRnJhbWUgZnJtOwogICAgTWVudUJhciBtYjsKICAgIE1lbnUgbWVudTE7CiAgICBNZW51SXRlbSBtaTEsbWkyLG1pMzsKICAgIFRleHRBcmVhIHRhOwoKICAgIHB1YmxpYyBUZXh0RnJhbWUoKXsKICAgICAgICBmcm0gPSBuZXcgRnJhbWUoIuODoeODouW4syIpOwogICAgICAgIG1iID0gbmV3IE1lbnVCYXIoKTsKICAgICAgICBmcm0uc2V0TWVudUJhcihtYik7CiAgICAgICAgbWVudTEgPSBuZXcgTWVudSgi44Oh44OL44Ol44O8Iik7CiAgICAgICAgbWkxID0gbmV3IE1lbnVJdGVtKCLmlrDopo8iKTsKICAgICAgICBtZW51MS5hZGQobWkxKTsKICAgICAgICBtaTEuYWRkQWN0aW9uTGlzdGVuZXIodGhpcyk7CiAgICAgICAgbWkyID0gbmV3IE1lbnVJdGVtKCLoqq3ovrwiKTsKICAgICAgICBtZW51MS5hZGQobWkyKTsKICAgICAgICBtaTIuYWRkQWN0aW9uTGlzdGVuZXIodGhpcyk7CiAgICAgICAgbWkzID0gbmV3IE1lbnVJdGVtKCLkv53lrZgiKTsKICAgICAgICBtZW51MS5hZGQobWkzKTsKICAgICAgICBtaTMuYWRkQWN0aW9uTGlzdGVuZXIodGhpcyk7CiAgICAgICAgbWIuYWRkKG1lbnUxKTsKICAgICAgICB0YSA9IG5ldyBUZXh0QXJlYSgpOwogICAgICAgIGZybS5hZGQodGEpOwoKICAgICAgICBmcm0uc2V0U2l6ZSg0MDAsIDIwMCk7CiAgICAgICAgZnJtLnNldFZpc2libGUodHJ1ZSk7CgogICAgICAgIHdpbmRvd2V4aXQoKTsKICAgIH0KCiAgICBwdWJsaWMgdm9pZCBhY3Rpb25QZXJmb3JtZWQoQWN0aW9uRXZlbnQgZSl7CiAgICAgICAgbmV3IEZpbGVJTyhlLCB0aGlzKTsKICAgIH0KCiAgICBwcml2YXRlIHZvaWQgd2luZG93ZXhpdCgpewogICAgICAgIGZybS5hZGRXaW5kb3dMaXN0ZW5lcihuZXcgV2luZG93QWRhcHRlcigpIHsKICAgICAgICAgICAgcHVibGljIHZvaWQgd2luZG93Q2xvc2luZyhXaW5kb3dFdmVudCBlKXsKICAgICAgICAgICAgICAgIFN5c3RlbS5leGl0KDApOwogICAgICAgICAgICB9CiAgICAgICAgfSk7CiAgICB9Cn0KCmNsYXNzIEZpbGVJTyB7CiAgICBUZXh0RnJhbWUgZnJhbWU7CiAgICBGcmFtZSBmcm1kID0gbmV3IEZyYW1lKCk7CiAgICBGaWxlRGlhbG9nIGZkOwogICAgU3RyaW5nIGZpbGVOYW1lOwogICAgcHVibGljIEZpbGVJTyhBY3Rpb25FdmVudCBzLCBUZXh0RnJhbWUgZnJhbWUpIHsKICAgICAgICBpZihzLmdldFNvdXJjZSgpID09IGZyYW1lLm1pMSkgewogICAgICAgICAgICBmcmFtZS50YS5zZXRUZXh0KCIiKTsKICAgICAgICB9IGVsc2UgaWYocy5nZXRTb3VyY2UoKSA9PSBmcmFtZS5taTIpIHsKICAgICAgICAgICAgZmQgPSBuZXcgRmlsZURpYWxvZyhmcm1kLCAi6ZaL44GPIiwgRmlsZURpYWxvZy5MT0FEKTsKICAgICAgICAgICAgZmQuc2V0VmlzaWJsZSh0cnVlKTsKICAgICAgICAgICAgZmlsZU5hbWUgPSBmZC5nZXREaXJlY3RvcnkoKSArIGZkLmdldEZpbGUoKTsKICAgICAgICAgICAgRmlsZSBmaWxlID0gbmV3IEZpbGUoZmlsZU5hbWUpOwogICAgICAgICAgICBCdWZmZXJlZFJlYWRlciBiciA9IG51bGw7CiAgICAgICAgICAgIHRyeSB7CiAgICAgICAgICAgICAgICBiciA9IG5ldyBCdWZmZXJlZFJlYWRlcihuZXcgRmlsZVJlYWRlcihmaWxlKSk7CiAgICAgICAgICAgICAgICBmb3IoU3RyaW5nIGxpbmU7IChsaW5lPWJyLnJlYWRMaW5lKCkpICE9IG51bGw7ICkgewogICAgICAgICAgICAgICAgICAgIGZyYW1lLnRhLmFwcGVuZChsaW5lICsgIlxuIik7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0gY2F0Y2goRXhjZXB0aW9uIGV4KSB7CiAgICAgICAgICAgICAgICBleC5wcmludFN0YWNrVHJhY2UoKTsKICAgICAgICAgICAgfSBmaW5hbGx5IHsKICAgICAgICAgICAgICAgIGlmKGJyICE9IG51bGwpIHsgdHJ5IHsgYnIuY2xvc2UoKTsgfSBjYXRjaChFeGNlcHRpb24gZXgpIHt9IH0KICAgICAgICAgICAgfQogICAgICAgIH0gZWxzZSBpZihzLmdldFNvdXJjZSgpID09IGZyYW1lLm1pMykgewogICAgICAgICAgICBmZCA9IG5ldyBGaWxlRGlhbG9nKGZybWQsICLkv53lrZgiLCBGaWxlRGlhbG9nLlNBVkUpOwogICAgICAgICAgICBmZC5zZXRWaXNpYmxlKHRydWUpOwogICAgICAgICAgICBmaWxlTmFtZSA9IGZkLmdldERpcmVjdG9yeSgpICsgZmQuZ2V0RmlsZSgpOwogICAgICAgICAgICBGaWxlIGZpbGUgPSBuZXcgRmlsZShmaWxlTmFtZSk7CiAgICAgICAgICAgIEJ1ZmZlcmVkV3JpdGVyIGJ3ID0gbnVsbDsKICAgICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgICAgIGJ3ID0gbmV3IEJ1ZmZlcmVkV3JpdGVyKG5ldyBGaWxlV3JpdGVyKGZpbGUpKTsKICAgICAgICAgICAgICAgIGJ3LndyaXRlKGZyYW1lLnRhLmdldFRleHQoKSk7CiAgICAgICAgICAgICAgICBidy5mbHVzaCgpOwogICAgICAgICAgICB9IGNhdGNoKEV4Y2VwdGlvbiBleCkgewogICAgICAgICAgICAgICAgZXgucHJpbnRTdGFja1RyYWNlKCk7CiAgICAgICAgICAgIH0gZmluYWxseSB7CiAgICAgICAgICAgICAgICBpZihidyAhPSBudWxsKSB7IHRyeSB7IGJ3LmNsb3NlKCk7IH0gY2F0Y2goRXhjZXB0aW9uIGV4KSB7fSB9CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9Cn0=