📄 用java 编写一个记事本,要有保存和设置字体的功能_百度知道.mht
字号:
<DIV class=3D"mb12 bai">
<DIV class=3Drg_1></DIV>
<DIV class=3Drg_2></DIV>
<DIV class=3Drg_3></DIV>
<DIV class=3Drg>
<DIV class=3Dt1><SPAN=20
style=3D"PADDING-RIGHT: 10px; FONT-WEIGHT: normal; FONT-SIZE: 12px; =
FLOAT: right">
<DIV class=3Dicosc></DIV><A class=3Dlbk=20
onclick=3D"window.open('http://cang.baidu.com/do/add?it=3D'+encodeURIComp=
onent(document.title)+'&iu=3D'+encodeURIComponent(location.href)+'&am=
p;tn=3D%E7%9F%A5%E9%81%93%E9%97%AE%E9%A2%98%2C&fr=3Dik#nw=3D1','_s','=
scrollbars=3Dno,width=3D600,height=3D450,right=3D75,top=3D20,status=3Dno,=
resizable=3Dyes'); return false;"=20
href=3D"http://cang.baidu.com/do/add" =
target=3D_blank>=CC=ED=BC=D3=B5=BD=CB=D1=B2=D8</A></SPAN>
<DIV class=3Dico>
<DIV class=3Diok></DIV></DIV>=D2=D1=BD=E2=BE=F6 </DIV>
<DIV class=3Dbc0>
<DIV class=3Dp90>
<DIV class=3D"f14 B wr"><CQ>=D3=C3JAVA =
=B1=E0=D0=B4=D2=BB=B8=F6=BC=C7=CA=C2=B1=BE=A3=AC=D2=AA=D3=D0=B1=A3=B4=E6=BA=
=CD=C9=E8=D6=C3=D7=D6=CC=E5=B5=C4=B9=A6=C4=DC</CQ></DIV>
<DIV class=3Dwr><SPAN class=3Dred><IMG height=3D16=20
src=3D"http://img.baidu.com/img/iknow/icn_point.gif" width=3D16 =
align=3DabsMiddle>=20
=D0=FC=C9=CD=B7=D6=A3=BA30</SPAN> - <SPAN =
class=3Dgray>=BD=E2=BE=F6=CA=B1=BC=E4=A3=BA2007-10-11 16:52</SPAN></DIV>
<DIV class=3D"f14 wr"><CD>=D3=C3JAVA =
=B1=E0=D0=B4=D2=BB=B8=F6=BC=C7=CA=C2=B1=BE=A3=AC=D2=AA=D3=D0=B1=A3=B4=E6=BA=
=CD=C9=E8=D6=C3=D7=D6=CC=E5=B5=C4=B9=A6=C4=DC~=CE=D2=D2=AA=D4=B4=B4=FA=C2=
=EB~~</CD></DIV>
<DIV class=3D"f14 wr"></DIV></DIV>
<DIV class=3Dgray align=3Dright>=CC=E1=CE=CA=D5=DF=A3=BA <A=20
href=3D"http://passport.baidu.com/?business&aid=3D6&un=3Drenzhiji=
e99#2"=20
target=3D_blank>renzhijie99</A> - <A=20
href=3D"http://www.baidu.com/search/zhidao_help.html#n5" =
target=3D_blank>=CA=D4=D3=C3=C6=DA =D2=BB=BC=B6</A>=20
</DIV></DIV></DIV>
<DIV class=3Drg_4></DIV>
<DIV class=3Drg_5></DIV>
<DIV class=3Drg_1></DIV></DIV>
<DIV class=3D"mb12 bai">
<DIV class=3Drr_1></DIV>
<DIV class=3Drr_2></DIV>
<DIV class=3Drr_3></DIV>
<DIV class=3Drr>
<DIV class=3Dt1>
<DIV class=3Dico>
<DIV class=3Dibest></DIV></DIV>=D7=EE=BC=D1=B4=F0=B0=B8</DIV>
<DIV class=3Dbc0=20
style=3D"PADDING-RIGHT: 0pt; PADDING-LEFT: 0pt; PADDING-BOTTOM: 5px; =
PADDING-TOP: 5px">
<DIV class=3Dwr>
<DIV class=3D"f14 p90 =
pl10"><CA>=C2=A5=C9=CF=B5=C4=CE=DE=B7=A8=B1=E0=D2=EB..=CE=D2=D5=FB=C0=ED=C1=
=CB=D2=BB=CF=C2,=B4=FA=C2=EB=C8=E7=CF=C2: <BR>import java.awt.*;=20
<BR>import java.io.*; <BR><BR>public class MyClipboard extends Frame =
implements=20
ActionListener { <BR>/** <BR>* <BR>*/ <BR>private static final long=20
serialVersionUID =3D 5541943532647624059L; <BR><BR>private TextArea =
editor =3D new=20
TextArea(); <BR><BR>private MyFile mf =3D new MyFile(this); =
<BR><BR>private=20
MyClipboard1 cb =3Dnew MyClipboard1(); <BR><BR>private MyFindDialog =
findDlg =3D new=20
MyFindDialog(this, editor); <BR><BR>public MyClipboard(String title) {=20
<BR>super(title); <BR>MyMenuBar mb =3D new MyMenuBar(this); =
<BR>mb.addMenus(new=20
String[] { "=CE=C4=BC=FE", "=B1=E0=BC=AD", "=B2=E9=D5=D2", =
"=B0=EF=D6=FA" }); <BR>mb.addMenuItems(0, new String[] {=20
"=D0=C2=BD=A8", "=B4=F2=BF=AA", "=B1=A3=B4=E6", null, "=CD=CB=B3=F6" }); =
<BR>mb.addMenuItems(1, new String[] { "=BC=F4=CC=F9",=20
"=B8=B4=D6=C6", "=D5=B3=CC=F9", "=C7=E5=B3=FD", null, "=C8=AB=D1=A1" }); =
<BR>mb.addMenuItems(2, new String[] { "=B2=E9=D5=D2",=20
null, "=B2=E9=D5=D2=CC=E6=BB=BB" }); <BR>mb.addMenuItems(3, new String[] =
{ "=CE=D2=B5=C4=BC=C7=CA=C2=B1=BE=D0=C5=CF=A2" });=20
<BR>add(editor); <BR>mb.addActionListener(this); =
<BR>addWindowListener(new=20
WindowAdapter() { <BR>public void windowClosing(WindowEvent e) {=20
<BR>MyClipboard.this.dispose(); <BR>} <BR>}); <BR>} <BR><BR>public void=20
actionPerformed(ActionEvent e) { <BR>String selected =3D =
e.getActionCommand();=20
<BR>if (selected.equals("=D0=C2=BD=A8")) <BR>editor.setText(""); =
<BR>else if=20
(selected.equals("=B4=F2=BF=AA")) { <BR>try { =
<BR>editor.setText(mf.getData()); <BR>}=20
catch (IOException ie) { <BR>} <BR>} else if =
(selected.equals("=B1=A3=B4=E6")) { <BR>try {=20
<BR>mf.setData(editor.getText()); <BR>} catch (IOException ie) { <BR>} =
<BR>}=20
else if (selected.equals("=CD=CB=B3=F6")) { <BR>dispose(); <BR>} else if =
(selected.equals("=BC=F4=CC=F9")) { =
<BR>cb.setData(editor.getSelectedText());=20
<BR>editor.replaceRange("", editor.getSelectionStart(), editor=20
<BR>.getSelectionEnd()); <BR>} else if (selected.equals("=B8=B4=D6=C6")) =
{=20
<BR>cb.setData(editor.getSelectedText()); <BR>} else if =
(selected.equals("=D5=B3=CC=F9"))=20
{ <BR>String str =3D cb.getData(); <BR>editor.replaceRange(str,=20
editor.getSelectionStart(), editor <BR>.getSelectionEnd()); <BR>} else =
if=20
(selected.equals("=C7=E5=B3=FD")) { <BR>editor.replaceRange("",=20
editor.getSelectionStart(), editor <BR>.getSelectionEnd()); <BR>} else =
if=20
(selected.equals("=C8=AB=D1=A1")) { <BR>editor.setSelectionStart(0);=20
<BR>editor.setSelectionEnd(editor.getText().length()); <BR>} else if=20
(selected.equals("=B2=E9=D5=D2")) { <BR>findDlg.showFind(); <BR>} else =
if=20
(selected.equals("=B2=E9=D5=D2=CC=E6=BB=BB")) { =
<BR>findDlg.showReplace(); <BR>} <BR>}=20
<BR><BR>public static void main(String[] args) { <BR>MyClipboard memo =
=3D new=20
MyClipboard("=CE=D2=B5=C4=BC=C7=CA=C2=B1=BE"); <BR>memo.setSize(500, =
500); <BR>memo.setLocation(239,=20
120); <BR>memo.setVisible(true); <BR>} <BR>} <BR><BR><BR>class =
MyClipboard1 {=20
<BR>private Clipboard cb; <BR><BR>public MyClipboard1() { <BR>cb =3D=20
Toolkit.getDefaultToolkit().getSystemClipboard(); <BR>} <BR><BR>public =
void=20
setData(String data) { <BR>cb.setContents(new StringSelection(data), =
null);=20
<BR>} <BR><BR>public String getData() { <BR>Transferable content =3D=20
cb.getContents(null); <BR>try { <BR>return (String)=20
content.getTransferData(DataFlavor.stringFlavor); <BR>} catch (Exception =
ue) {=20
<BR>} <BR>return null; <BR>} <BR>} <BR><BR>class MyFile { <BR>private =
FileDialog=20
fDlg; <BR><BR>public MyFile(Frame parent) { <BR>fDlg =3D new =
FileDialog(parent,=20
"", FileDialog.LOAD); <BR>} <BR><BR>private String getPath() { =
<BR>return=20
fDlg.getDirectory() + "\\" + fDlg.getFile(); <BR>} <BR><BR>public String =
getData() throws IOException { <BR>fDlg.setTitle("=B4=F2=BF=AA");=20
<BR>fDlg.setMode(FileDialog.LOAD); <BR>fDlg.setVisible(true); =
<BR>BufferedReader=20
br =3D new BufferedReader(new FileReader(getPath())); <BR>StringBuffer =
sb =3D new=20
StringBuffer(); <BR>String aline; <BR>while ((aline =3D br.readLine()) =
!=3D null)=20
<BR>sb.append(aline + '\n'); <BR>br.close(); <BR>return sb.toString(); =
<BR>}=20
<BR><BR>public void setData(String data) throws IOException {=20
<BR>fDlg.setTitle("=B1=A3=B4=E6"); <BR>fDlg.setMode(FileDialog.SAVE);=20
<BR>fDlg.setVisible(true); <BR>BufferedWriter bw =3D new =
BufferedWriter(new=20
FileWriter(getPath())); <BR>bw.write(data); <BR>bw.close(); <BR>} <BR>}=20
<BR><BR>class MyFindDialog extends Dialog implements ActionListener { =
<BR>/**=20
<BR>* <BR>*/ <BR>private static final long serialVersionUID =3D=20
4380007102323378083L; <BR><BR>private Label lFind =3D new =
Label("=B2=E9=D5=D2=D7=D6=B7=FB=B4=AE:");=20
<BR><BR>private Label lReplace =3D new =
Label("=CC=E6=BB=BB=D7=D6=B7=FB=B4=AE:"); <BR><BR>private TextField=20
tFind =3D new TextField(10); <BR><BR>private TextField tReplace =3D new=20
TextField(10); <BR><BR>private Button bFind =3D new =
Button("=B2=E9=D5=D2"); <BR><BR>private=20
Button bReplace =3D new Button("=CC=E6=BB=BB"); <BR><BR>private TextArea =
ta; <BR><BR>public=20
MyFindDialog(Frame owner, TextArea ta) { <BR>super(owner, =
"=B2=E9=D5=D2", false);=20
<BR>this.ta =3D ta; <BR>setLayout(null); <BR>lFind.setBounds(10, 30, 80, =
20);=20
<BR>lReplace.setBounds(10, 70, 80, 20); <BR>tFind.setBounds(90, 30, 90, =
20);=20
<BR>tReplace.setBounds(90, 70, 90, 20); <BR>bFind.setBounds(190, 30, 80, =
20);=20
<BR>bReplace.setBounds(190, 70, 80, 20); <BR>add(lFind); <BR>add(tFind); =
<BR>add(bFind); <BR>add(lReplace); <BR>add(tReplace); <BR>add(bReplace); =
<BR>setResizable(false); <BR>bFind.addActionListener(this);=20
<BR>bReplace.addActionListener(this); <BR>addWindowListener(new =
WindowAdapter()=20
{ <BR>public void windowClosing(WindowEvent e) {=20
<BR>MyFindDialog.this.dispose(); <BR>} <BR>}); <BR>} <BR><BR>public void =
showFind() { <BR>setTitle("=B2=E9=D5=D2"); <BR>setSize(280, 60); =
<BR>setVisible(true);=20
<BR>} <BR><BR>public void showReplace() { =
<BR>setTitle("=B2=E9=D5=D2=CC=E6=BB=BB"); <BR>setSize(280,=20
110); <BR>setVisible(true); <BR>} <BR><BR>private void find() { =
<BR>String text=20
=3D ta.getText(); <BR>String str =3D tFind.getText(); <BR>int end =3D =
text.length();=20
<BR>int len =3D str.length(); <BR>int start =3D ta.getSelectionEnd(); =
<BR>if (start=20
=3D=3D end) <BR>start =3D 0; <BR>for (; start <=3D end - len; =
start++) { <BR>if=20
(text.substring(start, start + len).equals(str)) {=20
<BR>ta.setSelectionStart(start); <BR>ta.setSelectionEnd(start + len);=20
<BR>return; <BR>} <BR>} <BR>ta.setSelectionStart(end);=20
<BR>ta.setSelectionEnd(end); <BR>} <BR><BR>private void replace() { =
<BR>String=20
str =3D tReplace.getText(); <BR>if =
(ta.getSelectedText().equals(tFind.getText()))=20
<BR>ta.replaceRange(str, ta.getSelectionStart(), ta.getSelectionEnd()); =
<BR>else=20
<BR>find(); <BR>} <BR><BR>public void actionPerformed(ActionEvent e) { =
<BR>if=20
(e.getSource() =3D=3D bFind) <BR>find(); <BR>else if (e.getSource() =
=3D=3D bReplace)=20
<BR>replace(); <BR>} <BR>} <BR><BR><BR>class MyMenuBar extends MenuBar=20
implements Serializable { <BR>/** <BR>* <BR>*/ <BR>private static final =
long=20
serialVersionUID =3D 2311645080753585104L; <BR><BR>public =
MyMenuBar(Frame parent)=20
{ <BR>parent.setMenuBar(this); <BR>} <BR><BR>public void =
addMenus(String[]=20
menus) { <BR>for (int i =3D 0; i < menus.length; i++) <BR>add(new=20
Menu(menus[i])); <BR>} <BR><BR>public void addMenuItems(int menuNumber, =
String[]=20
items) { <BR>for (int i =3D 0; i < items.length; i++) { <BR>if =
(items[i] !=3D=20
null) <BR>getMenu(menuNumber).add(new MenuItem(items[i])); <BR>else=20
<BR>getMenu(menuNumber).addSeparator(); <BR>} <BR>} <BR><BR>public void=20
addActionListener(ActionListener al) { <BR>for (int i =3D 0; i <=20
getMenuCount(); i++) <BR>for (int j =3D 0; j < =
getMenu(i).getItemCount(); j++)=20
<BR>getMenu(i).getItem(j).addActionListener(al); <BR>} <BR>}</CA></DIV>
<DIV class=3Dgray style=3D"MARGIN: 5px 5px 8px" =
align=3Dright>=BB=D8=B4=F0=D5=DF=A3=BA<A=20
href=3D"http://passport.baidu.com/?business&aid=3D6&un=3Dbio1984#=
2"=20
target=3D_blank>bio1984</A> -<A=20
href=3D"http://www.baidu.com/search/zhidao_help.html#n5" =
target=3D_blank> =BE=AD=C0=ED =CE=E5=BC=B6</A>=20
10-11 16:15</DIV>
<DIV =
class=3Dt2>=CC=E1=CE=CA=D5=DF=B6=D4=D3=DA=B4=F0=B0=B8=B5=C4=C6=C0=BC=DB=A3=
=BA</DIV>
<DIV class=3D"p90 pl10 =
f14">=D0=BB=D0=BB=A3=AC=CB=E4=C8=BB=B2=BB=CA=C7=CE=D2=D2=AA=B5=C4=B4=F0=B0=
=B8=BB=B9=CA=C7=D2=AA=D0=BB=D0=BB=C4=E3</DIV>
<DIV =
class=3Dt2>=C6=C0=BC=DB=D2=D1=BE=AD=B1=BB=B9=D8=B1=D5 &n=
bsp;<SPAN class=3D"f12 gray"=20
style=3D"FONT-WEIGHT: normal">=C4=BF=C7=B0=D3=D0 1 =
=B8=F6=C8=CB=C6=C0=BC=DB</SPAN></DIV>
<DIV class=3Dpl10>
<TABLE cellSpacing=3D0 cellPadding=3D0 border=3D0>
<TBODY>
<TR vAlign=3Dtop>
<FORM name=3Dfpj action=3Dhttp://zhidao.baidu.com/q =
method=3Dpost><INPUT=20
type=3Dhidden value=3D22 name=3Dct> <INPUT type=3Dhidden name=3Dmpn> =
<INPUT=20
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -