⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 一个记事本的源代码.htm

📁 一个用Java编写的记事本源程序
💻 HTM
📖 第 1 页 / 共 4 页
字号:
<BR>return fbgc; <BR>} <BR>else <BR>return fbgcOld; <BR>}//end of myLayout 
<BR><BR>//ActionListener <BR>public void actionPerformed(ActionEvent ae) { 
<BR>if(ae.getSource() == colorButtonOk) { <BR>changed = true; <BR>dispose(); 
<BR>} <BR>else if(ae.getSource() == colorButtonCancel) { <BR>changed = false; 
<BR>dispose(); <BR>} <BR>}//end of ActionListener <BR><BR>//ItemListener 
<BR>public void itemStateChanged(ItemEvent ie) { <BR>if(ie.getSource() == fore) 
{ <BR>isFore = true; <BR>scrollbarRed.setValue(fbgc[0].getRed()); 
<BR>textFieldRed.setText(scrollbarRed.getValue() + ""); 
<BR>scrollbarGreen.setValue(fbgc[0].getGreen()); 
<BR>textFieldGreen.setText(scrollbarGreen.getValue() + ""); 
<BR>scrollbarBlue.setValue(fbgc[0].getBlue()); 
<BR>textFieldBlue.setText(scrollbarBlue.getValue() + ""); 
<BR>colorTextField.setForeground(setColorVarSrollbar()); <BR>} <BR>else 
if(ie.getSource() == back) { <BR>isFore = false; 
<BR>scrollbarRed.setValue(fbgc[1].getRed()); 
<BR>textFieldRed.setText(scrollbarRed.getValue() + ""); 
<BR>scrollbarGreen.setValue(fbgc[1].getGreen()); 
<BR>textFieldGreen.setText(scrollbarGreen.getValue() + ""); 
<BR>scrollbarBlue.setValue(fbgc[1].getBlue()); 
<BR>textFieldBlue.setText(scrollbarBlue.getValue() + ""); 
<BR>colorTextField.setBackground(setColorVarSrollbar()); <BR>} <BR>else 
if(ie.getSource() == colorCheckbox) { <BR>if(colorCheckbox.getState()) { 
<BR>synchronism = true; <BR>} <BR>else { <BR>synchronism = false; <BR>} <BR>} 
<BR>}//end of ItemListener <BR><BR>//AdjustmentListener <BR>public void 
adjustmentValueChanged(AdjustmentEvent ade) { <BR>if(ade.getSource() == 
scrollbarRed) { <BR>if(synchronism) { 
<BR>textFieldRed.setText(scrollbarRed.getValue() + ""); 
<BR>scrollbarGreen.setValue(scrollbarRed.getValue()); 
<BR>textFieldGreen.setText(scrollbarRed.getValue() + ""); 
<BR>scrollbarBlue.setValue(scrollbarRed.getValue()); 
<BR>textFieldBlue.setText(scrollbarRed.getValue() + ""); <BR>if(isFore) { 
<BR>colorTextField.setForeground(setColorVarSrollbar()); <BR>fbgc[0] = 
setColorVarSrollbar(); <BR>} <BR>else { 
<BR>colorTextField.setBackground(setColorVarSrollbar()); <BR>fbgc[1] = 
setColorVarSrollbar(); <BR>} <BR>} <BR>else { 
<BR>textFieldRed.setText(scrollbarRed.getValue()+""); <BR>if(isFore) { 
<BR>colorTextField.setForeground(setColorVarSrollbar()); <BR>fbgc[0] = 
setColorVarSrollbar(); <BR>} <BR>else { 
<BR>colorTextField.setBackground(setColorVarSrollbar()); <BR>fbgc[1] = 
setColorVarSrollbar(); <BR>} <BR>} <BR>} <BR>else if(ade.getSource() == 
scrollbarGreen) { <BR>if(synchronism) { 
<BR>textFieldGreen.setText(scrollbarGreen.getValue() + ""); 
<BR>scrollbarBlue.setValue(scrollbarGreen.getValue()); 
<BR>textFieldBlue.setText(scrollbarGreen.getValue() + ""); 
<BR>scrollbarRed.setValue(scrollbarGreen.getValue()); 
<BR>textFieldRed.setText(scrollbarGreen.getValue() + ""); <BR>if(isFore) { 
<BR>colorTextField.setForeground(setColorVarSrollbar()); <BR>fbgc[0] = 
setColorVarSrollbar(); <BR>} <BR>else { 
<BR>colorTextField.setBackground(setColorVarSrollbar()); <BR>fbgc[1] = 
setColorVarSrollbar(); <BR>} <BR>} <BR>else { 
<BR>textFieldGreen.setText(scrollbarGreen.getValue() + ""); <BR>if(isFore) { 
<BR>colorTextField.setForeground(setColorVarSrollbar()); <BR>fbgc[0] = 
setColorVarSrollbar(); <BR>} <BR>else { 
<BR>colorTextField.setBackground(setColorVarSrollbar()); <BR>fbgc[1] = 
setColorVarSrollbar(); <BR>} <BR>} <BR>} <BR>else if(ade.getSource() == 
scrollbarBlue) { <BR>if(synchronism) { 
<BR>textFieldBlue.setText(scrollbarBlue.getValue() + ""); 
<BR>scrollbarRed.setValue(scrollbarBlue.getValue()); 
<BR>textFieldRed.setText(scrolbarBlue.getValue() + ""); 
<BR>scrollbarGreen.setValue(scrollbarBlue.getValue()); 
<BR>textFieldGreen.setText(scrollbarBlue.getValue() + ""); <BR>if(isFore) { 
<BR>colorTextField.setForeground(setColorVarSrollbar()); <BR>fbgc[0] = 
setColorVarSrollbar(); <BR>} <BR>else { 
<BR>colorTextField.setBackground(setColorVarSrollbar()); <BR>fbgc[1] = 
setColorVarSrollbar(); <BR>} <BR>} <BR>else { 
<BR>textFieldBlue.setText(scrollbarBlue.getValue() + ""); <BR>if(isFore) { 
<BR>colorTextField.setForeground(setColorVarSrollbar()); <BR>fbgc[0] = 
setColorVarSrollbar(); <BR>} <BR>else { 
<BR>colorTextField.setBackground(setColorVarSrollbar()); <BR>fbgc[1] = 
setColorVarSrollbar(); <BR>} <BR>} <BR>} <BR>}//end of AdjustmentListener 
<BR><BR>//TextListener <BR>public void textValueChanged(TextEvent te) { 
<BR>if(te.getSource() == textFieldRed) { <BR>int i = 0; <BR>try { <BR>i = 
Integer.parseInt(textFieldRed.getText()); <BR>} catch(NumberFormatException nfe) 
{ <BR>} <BR>if(i &lt; 0) <BR>i = 0; <BR>if(i &gt; 255) <BR>i = 255; 
<BR>scrollbarRed.setValue(i); <BR>if(synchronism) { 
<BR>scrollbarGreen.setValue(scrollbarRed.getValue()); 
<BR>textFieldGreen.setText(scrollbarRed.getValue() + ""); 
<BR>scrollbarBlue.setValue(scrollbarRed.getValue()); 
<BR>textFieldBlue.setText(scrollbarRed.getValue() + ""); <BR>if(isFore) { 
<BR>colorTextField.setForeground(setColorVarSrollbar()); <BR>fbgc[0] = 
setColorVarSrollbar(); <BR>} <BR>else { 
<BR>colorTextField.setBackground(setColorVarSrollbar()); <BR>fbgc[1] = 
setColorVarSrollbar(); <BR>} <BR>} <BR>else { <BR>if(isFore) { 
<BR>colorTextField.setForeground(setColorVarSrollbar()); <BR>fbgc[0] = 
setColorVarSrollbar(); <BR>} <BR>else { 
<BR>colorTextField.setBackground(setColorVarSrollbar()); <BR>fbgc[1] = 
setColorVarSrollbar(); <BR>} <BR>} <BR><BR>} <BR>//else if(te.getSource() == 
textFieldGreen) { <BR>//} conflict with textFieldRed <BR>//else 
if(te.getSource() == textFieldBlue) { <BR>//} <BR>}//end of TextListener 
<BR><BR>private Color setColorVarSrollbar() { <BR>return new 
Color(scrollbarRed.getValue(), <BR>scrollbarGreen.getValue(), 
<BR>scrollbarBlue.getValue()); <BR>} <BR><BR>}//end of class MenuColor&nbsp;</P>
<P><IMG alt=发贴心情 src="一个记事本的源代码.files/p1.gif" border=0> 
&nbsp;<B>回复:一个记事本的源代码</B> <BR>//保存为PrintableTextArea.java <BR>import java.awt.*; 
<BR>import java.io.*; <BR>import java.awt.print.*; <BR><BR>import javax.swing.*; 
<BR>import javax.swing.text.*; <BR><BR>class PrintableTextArea extends JTextArea 
<BR>implements Printable { <BR><BR>String str; <BR>Font font; <BR>PrinterJob pj; 
<BR>PageFormat defaultFormat; <BR>int visiblePageWidth = 0, visiblePageHeight = 
0; <BR>final static int PageX = 10, PageY = 10; <BR><BR>PrintableTextArea(int 
rows, int columns) { <BR>super(rows, columns); <BR>} <BR><BR>public void 
printIt(String str, Font font) { <BR>this.str = str; <BR>this.font = font; 
<BR>pj = PrinterJob.getPrinterJob(); <BR>defaultFormat = pj.defaultPage(); 
<BR>pj.setPrintable(this, defaultFormat); <BR>visiblePageWidth = 
(int)defaultFormat.getImageableWidth(); <BR>visiblePageHeight = 
(int)defaultFormat.getImageableHeight(); <BR>if(pj.printDialog()) { <BR>try { 
<BR>pj.print(); <BR>} catch(PrinterException e) { <BR>} <BR>} <BR>} 
<BR><BR>public int print(Graphics g, PageFormat pf, int page) throws 
PrinterException { <BR>if(page &gt;= 1) <BR>return Printable.NO_SUCH_PAGE; 
<BR>Graphics2D g2 = (Graphics2D) g; <BR>g2.translate((int)pf.getImageableX(), 
(int)pf.getImageableY()); <BR>g2.setFont(font); <BR>int fontHeight = 0, 
fontStringWidth = 0; <BR>int line = 0; <BR>String s = null; <BR>FontMetrics fm = 
getFontMetrics(font); <BR>fontHeight = fm.getHeight(); <BR>try{ 
<BR>DataOutputStream osw = new DataOutputStream(new 
FileOutputStream("$temp.$$p")); <BR>osw.writeBytes(str); <BR>osw.close(); <BR>} 
catch(IOException e) { <BR>} <BR>try { <BR>BufferedReader br = new 
BufferedReader(new FileReader("$temp.$$p")); <BR>s = br.readLine(); <BR>while(s 
!= null) { <BR>if(s.length() == 0) <BR>g2.drawString(" ", PageX, PageY + 
fontHeight*(line++)); <BR>else { <BR>//g2.drawString(s, PageX, PageY + 
fontHeight*(line++)); <BR>fontStringWidth = fm.stringWidth(s); 
<BR>if(fontStringWidth &gt; visiblePageWidth) { <BR>String s1, s2; <BR>int 
goBack = 0; <BR>while( fm.stringWidth(s1 = s.substring(0, s.length() - goBack)) 
&gt; <BR>visiblePageWidth) { <BR>goBack++; <BR>} <BR>s1 = s.substring(0, 
s.length() - goBack); <BR>s2 = s.substring(s.length() - goBack - 1); 
<BR>g2.drawString(s1, PageX, PageY + fontHeight*(line++)); <BR>g2.drawString(s2, 
PageX, PageY + fontHeight*(line++)); <BR>} <BR>else { <BR>g2.drawString(s, 
PageX, PageY + fontHeight*(line++)); <BR>} <BR>} <BR>s = br.readLine(); <BR>} 
<BR>br.close(); <BR>} catch(IOException e) { <BR>} <BR>return 
Printable.PAGE_EXISTS; <BR>} <BR><BR>} <BR><BR>/* other usefull functions 
<BR>PageFormat defaultFormat = pj.defaultPage(); 
<BR>defaultFormat.getImageableX(); <BR>defaultFormat.getImageableY(); 
<BR>defaultFormat.getWidth(); <BR>defaultFormat.getHeight(); 
<BR>defaultFormat.getImageableWidth(); <BR>defaultFormat.getImageableHeight(); 
<BR><BR><BR>PageFormat selectedFormat = pj.pageDialog(defaultFormat); 
<BR>selectFormat.getImageableX(); <BR>selectFormat.getImageableY(); 
<BR>selectFormat.getWidth(); <BR>selectFormat.getHeight(); 
<BR>selectFormat.getImageableWidth(); <BR>selectFormat.getImageableHeight(); 
<BR><BR>stringWidth(String str) 
<BR><BR>*/&nbsp;<BR><BR><BR><BR><BR><BR>&nbsp;<BR><BR><BR><BR><BR><BR><BR></P>
<P></P>
<P class=diaryFoot>- 作者: <A 
title="姓名:美女程序&#10;性别:女&#10;出生年月:1982-06-06&#10;所在地区:江苏-南京&#10;从事行业:IT&#10;联系电话:空&#10;OICQ:空&#10;婚姻状况:保密&#10;" 
onclick="window.open('/jsp/control/userInfo/messageMgr/postMessage.jsp?receiverName=强强联手&amp;receiver=60836','发送短消息','width=310,height=265')" 
href="javascript:void(0);">强强联手</A> 2004年08月13日,星期五 16:23:02 </P></DIV>
<DIV class=operation><A name=trackback>
<H3>Trackback</H3></A>
<P class=trackback>你可以使用这个链接引用该篇日志 
http://www.blogdriver.com/service/tb.do?diaryID=281195 </P></DIV>
<DIV class=operation><A name=comment>
<H3>回复</H3></A></DIV>
<DIV class=operation>
<TABLE class=comment cellSpacing=0 cellPadding=0 width=700 border=0>
  <FORM id=replyForm method=post><INPUT type=hidden value=44157 name=bloggerID> 
  <INPUT type=hidden value=281195 name=diaryID> <INPUT type=hidden 
  value=heromeeting name=blogDomino> 
  <TBODY>
  <TR>
    <TD width=70>发布人:</TD>
    <TD width=150><INPUT class=inputStyle id=remarker maxLength=20 
      name=remarker> </TD>
    <TD width=70>邮箱:</TD>
    <TD width=435><INPUT class=inputStyle id=mail maxLength=40 
name=mail></TD></TR>
  <TR>
    <TD>主 页:</TD>
    <TD colSpan=3><INPUT class=inputStyle id=blog maxLength=40 size=63 
      name=blog></TD></TR>
  <TR align=left>
    <TD colSpan=4><TEXTAREA class=textStyle id=remark name=remark rows=8 cols=60></TEXTAREA> 
    </TD></TR>
  <TR align=left>
    <TD colSpan=4>              <INPUT onclick=reply() type=button value=提交 name=Submit>   <INPUT type=reset value=重置 name=Submit2> 
</TD></TR></FORM></TBODY></TABLE></DIV></DIV>
<SCRIPT src="" type=text/javascript></SCRIPT>

<DIV id=footer><A href="http://www.blogdriver.com/jsp/reg/register.jsp"><IMG 
class=logo src="一个记事本的源代码.files/logo3.gif" border=0></A><A 
href="http://www.blogdriver.com/">2003-2004 BLOGDRIVER.COM All rights 
reserved</A></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -