1. 求代碼(用記事本編寫的html代碼)

<html>
<head>
<styletype="text/css">
h2{background:orange}
</style>
</head>
<body>
<h2>個人基金投資者投資情況調查問卷</h2>
<p>(1)您選擇投資公募基金的主要原因是:()</p>
<p><inputtype="radio"name="one"value="1"/>公募運作管理規范、信息披露全面,可以方便地查找相關信息,申購、贖回等均很便利</p>
<p><inputtype="radio"name="one"value="2"/>公募基金有比較強大的投研團隊</p>
<p><inputtype="radio"name="one"value="3"/>公募基金投資門檻極低,對投資者沒有太多的資質及投資金額要求</p>
<p>(2)您選擇投資專戶一對多基金的主要原因是:()</p>
<p><inputtype="radio"name="two"value="1"/>專戶一對多基金管理規范,同公募基金一樣有比較強大的投研團隊,且投資范圍、投資比例較自由</p>
<p><inputtype="radio"name="two"value="2"/>專戶一對多產品相對於公募基金有更強的針對性,可以更好地滿足投資者要求</p>
<p><inputtype="radio"name="two"value="3"/>其他</p>
<p>(3)您希望獲得哪方面的訊息?(多選題)</p>
<p><inputtype="checkbox"name="three"value="1"/>產品設計理念</p>
<p><inputtype="checkbox"name="three"value="2"/>投資思路</p>
<p><inputtype="checkbox"name="three"value="3"/>基金經理介紹</p>
<p><inputtype="checkbox"name="three"value="4"/>購買渠道</p>
<p><inputtype="checkbox"name="three"value="5"/>購買費率</p>
<h2>如您希望獲得抽獎機會,請留下如下信息</h2>
<p>姓名:<inputtype="text"name="name"value=""/></p>
<p>手機:<inputtype="text"name="phone"value=""/></p>
<p>住址:<inputtype="text"name="address"value=""/></p>
<p>建議:<textareaname="jy"rows="3"cols="8"></textarea></p>
<p><inputtype="submit"name="submit"value="提交"/><inputtype="reset"name="reset"value="重置"/></p>
</body>
</html>

2. java記事本代碼

import java.awt.event.ActionListener;
import java.util.EventListener;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.lang.*;
import java.awt.datatransfer.*;
import javax.swing.*;

public class MiniEdit extends JFrame implements ActionListener {

/**
* Method main
*
*
* @param args
*
*/
MenuBar menuBar = new MenuBar();
Menu file = new Menu("File"),
edit = new Menu("Edit"),
help = new Menu("Help");

MenuItem[] menuItem ={
new MenuItem("New"),
new MenuItem("Open"),
new MenuItem("Save"),
new MenuItem("Exit"),
new MenuItem("Select All"),
new MenuItem("Copy"),
new MenuItem("Cut"),
new MenuItem("Paste"),
new MenuItem("Help")
};

TextArea textArea = new TextArea();
String fileName = "NoName";
Toolkit toolKit = Toolkit.getDefaultToolkit();
Clipboard clipboard = toolKit.getSystemClipboard();

//opne and close message dialogs
private FileDialog openFileDialog =
new FileDialog(this,"Open File",FileDialog.LOAD);
private FileDialog saveFileDialog =
new FileDialog(this,"Save File",FileDialog.SAVE);

public static void main(String[] args) {
// TODO: Add your code here
MiniEdit MyEdit = new MiniEdit();
MyEdit.show();
}

/**
* Method MiniEdit
*
*
*/
public MiniEdit() {
// TODO: Add your code here
setTitle("MiniEdit");
setFont(new Font("Times New Roman",Font.PLAIN,15));
setBackground(Color.white);
setSize(500,500);

setMenuBar(menuBar);
menuBar.add(file);
menuBar.add(edit);
menuBar.add(help);
for(int i=0;i<4;i++)
{
file.add(menuItem[i]);
edit.add(menuItem[i+4]);
}
help.add(menuItem[8]);
add(textArea);

addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
e.getWindow().dispose();
System.exit(0);
}
});

//add actionListener
for(int i=0;i<menuItem.length;i++)
{
menuItem[i].addActionListener(this);
}

}

/**
* Method actionPerformed
*
*
* @param e
*
*/
public void actionPerformed(ActionEvent e) {
// TODO: Add your code here
Object eventSource = e.getSource();

if(eventSource == menuItem[0])//newItem
{
textArea.setText("");
}

else if(eventSource == menuItem[1])//OpenItem
{
openFileDialog.show();
fileName = openFileDialog.getDirectory()+openFileDialog.getFile();
if(fileName != null)
{
openFile(fileName);
}
}

else if(eventSource ==menuItem[2])//SaveItem
{
saveFileDialog.show();
fileName = saveFileDialog.getDirectory()+saveFileDialog.getFile();
if(fileName !=null)
{
writeFile(fileName);
}
}

else if(eventSource==menuItem[3])//exitItem
{
System.exit(0);
}

else if(eventSource == menuItem[4])//Select All
{
textArea.selectAll();
}
else if(eventSource == menuItem[5])//
{
String text = textArea.getSelectedText();
StringSelection selection= new StringSelection(text);

clipboard.setContents(selection,null);

}

else if(eventSource == menuItem[6])//cut
{
String text = textArea.getSelectedText();
StringSelection selection = new StringSelection(text);

clipboard.setContents(selection,null);
textArea.replaceText("",textArea.getSelectionStart(),
textArea.getSelectionEnd());
}

else if(eventSource == menuItem[7])//Paste
{
Transferable contents = clipboard.getContents(this);
if(contents==null)
return;
String text;
text="";
try{
text = (String)contents.getTransferData(DataFlavor.stringFlavor);

}catch(Exception ex){}
textArea.replaceText(text,
textArea.getSelectionStart(),textArea.getSelectionEnd());
}
else if(eventSource == menuItem[8])
{
// JOptionPane.showMessageDialog(null,"This is a MiniEdit.");
}

}

//Read file
public void openFile(String fileName){
try{
File file = new File(fileName);
FileReader readIn = new FileReader(file);
int size = (int)file.length();
int charsRead = 0;
char[] content = new char[size];
while(readIn.ready())
charsRead += readIn.read(content,charsRead,size-charsRead);
readIn.close();
textArea.setText(new String(content,0,charsRead));
}catch(Exception e)
{
System.out.println("Error opening file!");
}
}

//write file
public void writeFile(String fileName){
try{
File file = new File(fileName);
FileWriter write = new FileWriter(file);
write.write(textArea.getText());
write.close();
}catch(Exception e){
System.out.println("Error closing file!");
就這樣交,不會錯的

3. 記事本編程用的代碼有哪些啊怎麼用啊

記事本可以用來編寫所有的程序代碼,任何語言,但是編寫好後編譯必須使用與其語言相對應的編譯器進行編譯,這個記事本沒那功能.
還有就是記事本沒有那專業軟體的糾錯/語法檢測等功能,用於編寫程序比較容易出錯,所以一般不用記事本來編寫程序,而使用專業的軟體來編寫.

4. 簡易記事本代碼

'以下是讀記事本代碼,讀取後的數據存儲在數組hs()中:
Dim i As Long, hs() As String
i = 0
ReDim hs(0)
Open App.Path & "\1.txt" For Input As #1
Do While Not EOF(1)
ReDim Preserve hs(i)
Line Input #1, hs(i)
i = i + 1
Loop
Close #1
'以下是寫記事本代碼:
dim filename as string
filename = "這是第一行" & chr(13) & chr(10) & "這是第二行" & chr(13) & chr(10) & "這是第三行" & chr(13) & chr(10)
Open App.Path & "\2.txt" For Output As #1
Seek #1, 1
Print #1, filename
Close #1

5. 求記事本編程代碼!

你「開始」->「運行」->輸入「regedit」

按下ctrl+F,輸入「Intarnat Explrcr」,把找到的東西全部刪除。

同樣找出「360安全網址大全」,把找到的全部刪除。

你的桌面上 就不會有了。當然,如果這是由電腦中某個程序不斷生成的話,你必須找到那個程序,先把它刪了才行。

6. vb的簡單記事本的代碼

'窗體代碼

Option Explicit
Dim filename As String
Dim FileType As String
Dim FiType As String
Dim sFind As String
Dim result As String
Dim bWrap As Boolean
Dim ask As Boolean
Dim msgtext As String
Dim Flag As String

Private Sub Form_Load()
ask = False
RichText.Text = ""
filename = "無標題-記事本"
Form1.Caption = "無標題-記事本"
RichText.Height = Form1.ScaleHeight
RichText.Width = Form1.ScaleWidth
StatusBar1.Visible = False
StatusBar1.Panels(1).Text = Time
mnu.Enabled = False
mnucut.Enabled = False
mnufound.Enabled = False
mnufoundnext.Enabled = False
mnudel.Enabled = False
mnucancel.Enabled = False
mnuwordwrap.Checked = True
mnugoto.Enabled = False
If Clipboard.GetText <> "" Then
mnuplaster.Enabled = True
Else
mnuplaster.Enabled = False
End If
App.HelpFile = App.Path & "\notepad.chm"
End Sub

Private Sub Form_Resize()
RichText.Height = Form1.ScaleHeight
RichText.Width = Form1.ScaleWidth
End Sub

Private Sub Form_Unload(Cancel As Integer)
msgtext = "文件" & filename & "的文字已經改變。" & Chr(10) & Chr(13) & "想保存文件嗎?"
If ask = True Then
Flag = MsgBox(msgtext, 35, "記事本") ' 35=32+3
If Flag = vbYes Then mnusave_Click '選擇了確定則保存之
If Flag = vbCancel Then Cancel = True
If Flag = vbNo Then Unload Me
End If

End Sub

Private Sub mnuabout_Click()
MsgBox "記事本", vbOKOnly, "關於"
End Sub

Private Sub mnuall_Click()
RichText.SelStart = 0
RichText.SelLength = Len(RichText.Text)
End Sub

Private Sub mnucancel_Click()
MsgBox "請點擊滑鼠右鍵撤銷!", vbOKOnly, "提示"
End Sub

Private Sub mnu_Click()
Clipboard.Clear
Clipboard.SetText RichText.SelText
End Sub

Private Sub mnucut_Click()
Clipboard.Clear
Clipboard.SetText RichText.SelText
RichText.SelText = ""

End Sub

Private Sub mnudel_Click()
RichText.SelText = ""
End Sub

Private Sub mnuedit_Click()
If RichText.SelText <> "" Then
mnuopen.Enabled = True
mnucut.Enabled = True
mnudel.Enabled = True
mnu.Enabled = True
End If
If Len(RichText.Text) <> 0 Then
mnufound.Enabled = True
mnufoundnext.Enabled = True
End If
If ask = True Then mnucancel.Enabled = True
End Sub

Private Sub mnuexit_Click()
Unload Me
End Sub

Private Sub mnufont_Click()
On Error Resume Next
CommonDialog1.flags = &H3 Or &H1 Or &H2 Or &H100
CommonDialog1.Action = 4
RichText.Font.Name = CommonDialog1.FontName
RichText.Font.Size = CommonDialog1.FontSize
RichText.Font.Bold = CommonDialog1.FontBold
RichText.Font.Italic = CommonDialog1.FontItalic
RichText.Font.Underline = CommonDialog1.FontUnderline
RichText.SelColor = CommonDialog1.Color

End Sub

Private Sub mnufound_Click()
sFind = InputBox("請輸入要查找的字、詞:", "查找內容", sFind)
RichText.Find sFind
End Sub

Private Sub mnufoundnext_Click()
RichText.SelStart = RichText.SelStart + RichText.SelLength + 1
RichText.Find sFind, , Len(RichText)

End Sub

Private Sub mnuhelptopic_Click()
SendKeys "{F1}"
End Sub

Private Sub mnunewfile_Click()
On Error Resume Next
Dim n As Integer
msgtext = "文件" & filename & "的文字已經改變。" & Chr(10) & Chr(13) & "想保存文件嗎?"
If Len(RichText.Text) <> 0 Then
If filename = "無標題-記事本" Then
Flag = MsgBox(msgtext, 35, "記事本") '給予提示
If Flag = vbYes Then
mnusaveas_Click
RichText.Text = ""
Form1.Caption = "無標題-記事本"
filename = "無標題-記事本"
End If
If Flag = vbCancel Then Exit Sub
If Flag = vbNo Then
RichText.Text = ""
Form1.Caption = "無標題-記事本"
filename = "無標題-記事本"
End If
End If
End If
End Sub

Private Sub mnuopen_Click()
msgtext = "文件" & filename & "的文字已經改變。" & Chr(10) & Chr(13) & "想保存文件嗎?"
On Error Resume Next
If ask = True Then
Flag = MsgBox(msgtext, 35, "記事本") '給予提示
If Flag = vbYes Then mnusave_Click '選擇了確定則保存之
If Flag = vbCancel Then Exit Sub
If Flag = vbNo Then GoTo L1
End If
ask = False

L1: CommonDialog1.Filter = "文本文檔(*.txt)|*.txt|RTF文檔(*.rtf)|*.rtf|所有文件(*.*)|*.*"
CommonDialog1.ShowOpen
RichText.Text = "" '清空文本框
filename = CommonDialog1.filename
RichText.LoadFile filename
result = GetFileTitle(filename)
Me.Caption = "" & result & "-記事本"

End Sub

Private Sub mnupagesetup_Click()
psdlg.lStructSize = Len(psdlg)
psdlg.hwndOwner = hwnd
PageSetupDlg psdlg
End Sub

Private Sub mnuplaster_Click()
RichText.SelText = Clipboard.GetText(1)
End Sub

Private Sub mnuprint_Click()
Dim f As Integer, t As Integer
Dim i As Integer
CommonDialog1.CancelError = True
CommonDialog1.Max = 1000
CommonDialog1.Min = 1
On Error Resume Next
CommonDialog1.ShowPrinter

For f = CommonDialog1.FromPage To t = CommonDialog1.ToPage
Do While i < CommonDialog1.Copies + 1
Printer.Print RichText.Text
i = i + 1
Loop
Next
Printer.EndDoc
Cancel:
If Err.Number = 32755 Then
Exit Sub
End If
End Sub

Private Sub mnusave_Click()
CommonDialog1.Filter = "文本文檔(*.txt)|所有文件(*.*)|*.*"
On Error Resume Next
filename = CommonDialog1.filename '保存文件
If filename <> "" Then
RichText.SaveFile filename, rtfText
Else
mnusaveas_Click
End If
ask = False
End Sub

Private Sub mnusaveas_Click()
CommonDialog1.Filter = "文本文檔(*.txt)|所有文件(*.*)|*.*"
On Error Resume Next

CommonDialog1.ShowSave
filename = CommonDialog1.filename
RichText.SaveFile filename, rtfText

result = GetFileTitle(filename)
Me.Caption = "" & result & "-記事本"
ask = False
End Sub

Private Sub mnustatusbar_Click()
If mnustatusbar.Checked Then
StatusBar1.Visible = False
mnustatusbar.Checked = False
Else
StatusBar1.Visible = True
mnustatusbar.Checked = True
End If

End Sub

Private Sub mnutimedate_Click()
RichText.SelText = Format(Now, "h:mm ddddd")
End Sub

Private Sub mnuwordwrap_Click()
WrapTextLine RichText, bWrap
bWrap = Not bWrap
If mnuwordwrap.Checked = False Then
HScroll1.Enabled = True
mnuwordwrap.Checked = True

Else
HScroll1.Enabled = False
mnuwordwrap.Checked = False

End If

End Sub

Private Sub RichText_Change()
ask = True
End Sub

Private Sub Timer1_Timer()
If StatusBar1.Panels(1).Text <> CStr(Time) Then
StatusBar1.Panels(1).Text = Time
End If

End Sub

'模塊代碼

Option Explicit
Const WM_USER = &H400
Const EM_SETTARGETDEVICE = (WM_USER + 72)
Type POINTAPI
x As Long
y As Long
End Type
Type RECT
left As Long
right As Long
top As Long
bottom As Long
End Type
Public Type PageSetupDlg
lStructSize As Long
hwndOwner As Long
hDevMode As Long
hDevNames As Long
flags As Long
ptPaperSize As POINTAPI
rtMinMargin As RECT
rtMargin As RECT
hInstance As Long
lCustData As Long
lpfnPageSetupHook As Long
lpfnPagePaintHook As Long
lpPageSetupTemplateName As String
hPageSetupTemplate As Long
End Type
Public psdlg As PageSetupDlg
Declare Function PageSetupDlg Lib "comdlg32.dll" Alias "PageSetupDlgA" (pPagesetupdlg As PageSetupDlg) As Long

Public Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Dim bWrap As Boolean '// 換行標記'// 自定義一個換行的過程
Public Sub WrapTextLine(ByRef RichText As RichTextBox, ByVal bWrapSwitch As Boolean)
On Error Resume Next
If bWrapSwitch Then '// 設置 RichTextBox 自動換行
SendMessage RichText.hwnd, EM_SETTARGETDEVICE, GetDC(RichText.hwnd), RichText.Width / 15
RichText.RightMargin = IIf(RichText.RightMargin = 0, 1, 0)
Else
'// 設置 RichTextBox 不自動換行
SendMessage RichText.hwnd, EM_SETTARGETDEVICE, 0, 1
End If
End Sub
Function GetFileTitle(OldStr As String) As String

On Error Resume Next
Dim n As Integer, m As Integer '聲明字元串變數
Dim i As String, r As String
Dim p As Integer
i = "\" '要查找的指定字元
For n = 1 To Len(OldStr) '用Len函數計算已知字元串的位元組數
m = InStrRev(OldStr, i, -1) '"\"所在的位置(其中的-1是默認的)
Next n '找下去!

'截取最後一個"\"後面的字元串
r = right(OldStr, Len(OldStr) - m) '獲取Title
p = InStrRev(r, ".", -1) '"."所在位置
GetFileTitle = left(r, p - 1) '去掉後綴

End Function

7. 求助!有關記事本的代碼!

全幫你查好了,和微軟的記事本一模一樣。加分加分!
http://dev.csdn.net/article/08/08009.shtm
http://dev.csdn.net/article/08/08010.shtm
http://dev.csdn.net/article/08/08011.shtm
http://dev.csdn.net/article/08/08012.shtm
http://dev.csdn.net/article/08/08013.shtm

8. java簡單記事本代碼

以下代碼是一個完整的實現,你只要復制過去就可以了~~

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.text.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.undo.*;
import javax.swing.text.*;

public class Start
{
public static void main(String args[])
{
new TextPad();
}
}

class TextPad extends JFrame implements ActionListener
{

JTextArea jta=new JTextArea("小廖記事本:)",18,52);
JCheckBoxMenuItem mto1=new JCheckBoxMenuItem("自動換行",true);
String ss1=jta.getText();
UndoableEditListener ue=new UndoHander();
UndoManager undo = new UndoManager();
int StartFindPos=0,a=0,b=0;
GridBagConstraints gbc=new GridBagConstraints();
//Dimension dd=new Dimension();
// jta.getDocument().addUndoableEditListener(ue);
public TextPad()
{
//MyMenuListener ml=new MyMenuListener();
//JTextArea jta=new JTextArea("This is my textpad",18,52);

//System.out.println(dd.getHeight());
//System.out.println(dd.getWidth());

//System.out.println(this.getHeight());
//System.out.println(this.getWidth());
//System.out.println("OK");
this.setTitle("一個功能比較齊全的JAVA記事本");
this.setLocation(180,100);
jta.setLineWrap(true);
jta.setWrapStyleWord(true);
JPanel jp=new JPanel();
JScrollPane jsp=new JScrollPane(jta);

jp.add(jsp);
//Rectangle rt=new Rectangle(0,0,this.getWidth(),this.getHeight());
//jsp.setBounds(rt);
//System.out.println(this.getHeight());
//System.out.println(this.getWidth());
JMenu mf=new JMenu("文件(F)");
JMenuItem mtf1=new JMenuItem("新建");
mtf1.addActionListener(this);
JMenuItem mtf2=new JMenuItem("打開");
//mtf2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,InputEvent.CTRL_MASK));
mtf2.addActionListener(this);
JMenuItem mtf3=new JMenuItem("保存");
//mtf3.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK));
mtf3.addActionListener(this);
JMenuItem mtf4=new JMenuItem("另存為");
mtf4.addActionListener(this);
JMenuItem mtf5=new JMenuItem("退出");
mtf5.addActionListener(this);
JMenu me=new JMenu("編輯(E)");
JMenuItem mte1=new JMenuItem("撤消");
mte1.addActionListener(this);
jta.getDocument().addUndoableEditListener(ue);
if(undo.canUndo())
{
mte1.setEnabled(false);
}
JMenuItem mte2=new JMenuItem("剪切");
mte2.addActionListener(this);
JMenuItem mte3=new JMenuItem("復制");
mte3.addActionListener(this);
JMenuItem mte4=new JMenuItem("粘貼");
mte4.addActionListener(this);
//JMenuItem mte5=new JMenuItem("刪除");
//mte5.addActionListener(this);
JMenuItem mte6=new JMenuItem("查找");
mte6.addActionListener(this);
//JMenuItem mte7=new JMenuItem("查找下一個");
JMenuItem mte8=new JMenuItem("替換");
mte8.addActionListener(this);
//JMenuItem mte9=new JMenuItem("轉到");
JMenuItem mte10=new JMenuItem("全選");
mte10.addActionListener(this);
JMenuItem mte11=new JMenuItem("日期/時間");
mte11.addActionListener(this);
JMenu mo=new JMenu("格式(O)");
//JCheckBoxMenuItem mto1=new JCheckBoxMenuItem("自動換行(W)");
mto1.addActionListener(this);
JMenuItem mto2=new JMenuItem("字體");
mto2.addActionListener(this);
JMenu mv=new JMenu("查看(V)");
JMenuItem mtv1=new JMenuItem("狀態欄");
mtv1.setEnabled(false);
JMenu mh=new JMenu("幫助(H)");
JMenuItem mth1=new JMenuItem("關於記事本");
mth1.addActionListener(this);
JMenuBar mb=new JMenuBar();
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
);
mb.add(mf);
mb.add(me);
mb.add(mo);
mb.add(mv);
mb.add(mh);
this.setJMenuBar(mb);
mf.add(mtf1);
mf.add(mtf2);
mf.add(mtf3);
mf.add(mtf4);
mf.addSeparator();
mf.add(mtf5);
me.add(mte1);
me.addSeparator();
me.add(mte2);
me.add(mte3);
me.add(mte4);
//me.add(mte5);
me.addSeparator();
me.add(mte6);
//me.add(mte7);
me.add(mte8);
//me.add(mte9);
me.addSeparator();
me.add(mte10);
me.add(mte11);
mo.add(mto1);
mo.add(mto2);
mv.add(mtv1);
mh.add(mth1);
this.getContentPane().add(jsp);
this.setSize(600,400);
this.setResizable(true);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{

if(e.getActionCommand().equals("打開"))
{
try
{
Frame f=new Frame();
FileDialog fd=new FileDialog(f,"打開文件",FileDialog.LOAD);
fd.setVisible(true);
String fpath=fd.getDirectory();
String fname=fd.getFile();
BufferedReader br=new BufferedReader(new FileReader(fpath+fname));
jta.setText("");
String s=br.readLine();
while(s!=null)
{
jta.append(s+"\n");
s=br.readLine();
}
br.close();
}
catch(Exception ex)
{
}
}

if(e.getActionCommand().equals("保存"))
{
String fns=null;
Frame f=new Frame("保存");
FileDialog fd=new FileDialog(f,"保存文件",FileDialog.SAVE);
fd.setFile("*.txt");
fd.setVisible(true);
try
{
String savepath=fd.getDirectory();
String savename=fd.getFile();
if(savename!=null)
{
PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter(savepath+savename)));
pw.write(jta.getText(),0,jta.getText().length());
pw.flush();
}
}
catch(Exception esave)
{
}
}
if(e.getActionCommand().equals("新建"))
{
jta.setText("");
}
if(e.getActionCommand().equals("另存為"))
{
Frame f=new Frame("保存");
FileDialog fd=new FileDialog(f,"文件另存為",FileDialog.SAVE);
fd.setVisible(true);
try
{
String savepath=fd.getDirectory();
String savename=fd.getFile();
if(savename!=null)
{
PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter(savepath+savename)));
pw.write(jta.getText(),0,jta.getText().length());
pw.flush();
}
}
catch(Exception esave)
{
}
}
if(e.getActionCommand().equals("退出"))
{
String ss2=jta.getText();
if(!ss1.equals(ss2))
{
System.out.println("File is changed.");
}
System.exit(0);
}
if(e.getActionCommand().equals("撤消"))
{
try
{
undo.undo();
//System.out.println(undo.canUndo());
}
catch(Exception eundo)
{
}
}
if(e.getActionCommand().equals("剪切"))
{
jta.cut();
}
if(e.getActionCommand().equals("復制"))
{
jta.();
}
if(e.getActionCommand().equals("粘貼"))
{
jta.paste();
}
if(e.getActionCommand().equals("刪除"))
{

}
if(e.getActionCommand().equals("全選"))
{
jta.selectAll();
}
if(e.getActionCommand().equals("查找"))
{
try
{
final JDialog jd=new JDialog(this,"查找",true);
GridBagLayout gbl=new GridBagLayout();
GridBagConstraints gbc=new GridBagConstraints();
gbc.weightx=0.5;
gbc.weighty=0.5;
gbc.gridwidth=1;
gbc.gridheight=1;
jd.getContentPane().setLayout(gbl);
jd.setSize(380,100);
jd.setResizable(false);
//jd.(true);
final JTextField jtf=new JTextField(15);
JLabel jlFind=new JLabel("查找內容:");
jd.getContentPane().add(jlFind);
JButton jbFind=new JButton("查找");

jbFind.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent efind)
{
String strA=jta.getText();
String strB=jtf.getText();
if(a>=0)
{
a=strA.indexOf(strB,StartFindPos);

b=strB.length();
StartFindPos=a+b;
if(a==-1)
{
JOptionPane.showMessageDialog(null, "沒有您要查找的信息", "查找結果",1);
a=0;
StartFindPos=0;
}
jta.select(a,StartFindPos);
}
}
}
);
JButton jbCancel=new JButton("取消");
jbCancel.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ejb)
{
jd.dispose();
}
}
);
jd.getContentPane().add(jtf);
jd.getContentPane().add(jbFind);
jd.getContentPane().add(jbCancel);
//jd.setResizable(false);
jd.setLocation(240,200);
jd.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
jd.setVisible(true);
}
catch(Exception efind)
{
}
}
if(e.getActionCommand().equals("替換"))
{
final JDialog jd=new JDialog(this,"替換",true);
GridBagLayout gbl=new GridBagLayout();
GridBagConstraints gbc=new GridBagConstraints();
gbc.weightx=1;
gbc.weighty=1;
gbc.gridwidth=1;
gbc.gridheight=1;
JLabel jlFind=new JLabel("查找:");
JLabel jp=new JLabel("替換內容:");
final JTextField jtf=new JTextField(15);
final JTextField jtf1=new JTextField(15);
jd.getContentPane().setLayout(gbl);
jd.setSize(330,150);
jd.setResizable(false);
final JButton jbReplace=new JButton("替換");
final JButton jbReplaceAll=new JButton("替換所有");
final JButton jbCancel=new JButton("取消");
final JButton jbFind=new JButton("查找");
gbc.gridx=0;
gbc.gridy=0;
jd.getContentPane().add(jlFind,gbc);
gbc.gridx=1;
gbc.gridy=0;
jd.getContentPane().add(jtf1,gbc);
gbc.gridx=2;
gbc.gridy=0;
jd.getContentPane().add(jbFind,gbc);
gbc.gridx=0;
gbc.gridy=1;
jd.getContentPane().add(jp,gbc);
gbc.gridx=1;
gbc.gridy=1;
jd.getContentPane().add(jtf,gbc);
gbc.gridx=2;
gbc.gridy=1;
jd.getContentPane().add(jbReplace,gbc);
gbc.gridx=2;
gbc.gridy=2;
jd.getContentPane().add(jbReplaceAll,gbc);
gbc.gridx=2;
gbc.gridy=3;
jd.getContentPane().add(jbCancel,gbc);
jbFind.addActionListener(new ActionListener()
{

public void actionPerformed(ActionEvent efind)
{
String strA=jta.getText();
String strB=jtf1.getText();
if(a>=0)
{
a=strA.indexOf(strB,StartFindPos);
//System.out.println(a+b);
b=strB.length();
StartFindPos=a+b;
if(a==-1)
{
JOptionPane.showMessageDialog(null, "沒有您要查找的信息", "查找結果",1);
a=0;
StartFindPos=0;
}
jta.select(a,StartFindPos);
//System.out.println(StartFindPos);
}
}
}
);
jbReplace.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("替換"))
{
String strRepleace=jtf.getText();
jta.replaceSelection(strRepleace);
}
}
}
);
jbReplaceAll.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{

while(a>-1)
{
String strA=jta.getText();
String strB=jtf1.getText();
a=strA.indexOf(strB,StartFindPos);
if(a==-1)
{
break;
}
//System.out.println(a+b);
b=strB.length();
StartFindPos=a+b;
//System.out.println(StartFindPos);
jta.select(a,StartFindPos);
//System.out.println(StartFindPos);
String strRepleaceAll=jtf.getText();
jta.replaceSelection(strRepleaceAll);
StartFindPos=a+b;

}
JOptionPane.showMessageDialog(null, "全部替換完畢", "替換內容",1);
a=0;
StartFindPos=0;
}
}
);
jbCancel.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ejb)
{
jd.dispose();
}
}
);
jd.setLocation(240,200);
jd.setVisible(true);
jd.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
if(e.getActionCommand().equals("日期/時間"))
{
final JDialog jd=new JDialog(this,"插入日期");
JPanel jp1=new JPanel();
jp1.setLayout(new FlowLayout(FlowLayout.LEFT));
final JTextField jtf=new JTextField(10);
JButton jbOK=new JButton("確定");
JButton jbCancel=new JButton("取消");
//Calendar cl=Calendar.getInstance();
//DateFormat df=DateFormat.getInstance();
//String sdate1=df.format(cl.getTime());
//jtf.setText(sdate1);
jp1.add(jtf);
jp1.add(jbOK);
jp1.add(jbCancel);
jd.getContentPane().add(jp1,"North");
JPanel jp2=new JPanel();
jp2.setLayout(new FlowLayout(FlowLayout.LEFT));
final JCheckBox jcb1=new JCheckBox("格式一");
final JCheckBox jcb2=new JCheckBox("格式二");
final JCheckBox jcb3=new JCheckBox("格式三");
jp2.add(jcb1);
jp2.add(jcb2);
jp2.add(jcb3);
jd.getContentPane().add(jp2,"Center");
jd.setSize(220,120);
jd.setResizable(false);
jd.setLocation(240,200);
final SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
Calendar cl=Calendar.getInstance();
DateFormat df=DateFormat.getInstance();
final String sdate=df.format(cl.getTime());
jcb1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("格式一"))
{
if(jcb1.isSelected())
{
try
{
SimpleDateFormat sdf1=new SimpleDateFormat("yy年MM月dd日");
Date d=sdf.parse(sdate);
jtf.setText(sdf1.format(d));
jcb2.setEnabled(false);
jcb3.setEnabled(false);
}
catch(Exception estyle1)
{
estyle1.printStackTrace();
}
}
else
{
jcb2.setEnabled(true);
jcb3.setEnabled(true);
}
try
{
System.out.println(jta.getLineStartOffset(3));
//System.out.println(jta.getLineOfOffset(346));
}
catch(Exception eee)
{
}
}
}
}
);
jcb2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("格式二"))
{
if(jcb2.isSelected())
{
try
{
SimpleDateFormat sdf1=new SimpleDateFormat("yy/MM/dd");
Date d=sdf.parse(sdate);
jtf.setText(sdf1.format(d));
jcb1.setEnabled(false);
jcb3.setEnabled(false);
}
catch(Exception estyle2)
{
estyle2.printStackTrace();
}
}
else
{
jcb1.setEnabled(true);
jcb3.setEnabled(true);
}
//System.out.println(jcb1.isSelected());
}
}
}
);
jcb3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("格式三"))
{
if(jcb3.isSelected())
{
jtf.setText(sdate);
jcb1.setEnabled(false);
jcb2.setEnabled(false);
}
else
{
jcb1.setEnabled(true);
jcb2.setEnabled(true);
}
//System.out.println(jcb1.isSelected());
}
}
}
);
jbOK.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand().equals("確定"))
{
int pos=jta.getCaretPosition();
jta.insert(jtf.getText(),pos);
}
}
}
);
jbCancel.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ejb)
{
jd.dispose();
}
}
);
jd.setVisible(true);
jd.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
if(e.getActionCommand().equals("自動換行"))
{
if(mto1.getState())
{
jta.setLineWrap(true);
jta.setWrapStyleWord(true);
}
else
{
jta.setLineWrap(false);
jta.setWrapStyleWord(false);
}
//System.out.println("OK");
}
if(e.getActionCommand().equals("字體"))
{
final JDialog jd=new JDialog(this,"字體設置");
jd.setLocation(240,200);
//final JFrame jfontview=new JFrame();
GridBagLayout gbl=new GridBagLayout();
GridBagConstraints gbc=new GridBagConstraints();
JButton jbOK=new JButton("確定");
JButton jbCancel=new JButton("取消");
JTextField jtf1=new JTextField(6);
final JTextArea jtaview=new JTextArea(4,8);
//jfontview.getContentPane().add(jtaview);
final JTextField jtf2=new JTextField(6);
final JTextField jtf3=new JTextField(3);
JComboBox jcb1=new JComboBox();
final JComboBox jcb2=new JComboBox();
jcb2.addItem("BOLD");
jcb2.addItem("ITALIC");
jcb2.addItem("PLAIN");
//jcb2.addItem("BOLDITALIC");
jcb2.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
jtf2.setText((String)jcb2.getSelectedItem());
}
}
);
final JComboBox jcb3=new JComboBox();
jcb3.addItem("14");
jcb3.addItem("18");
jcb3.addItem("22");
jcb3.addItem("26");
jcb3.addItem("30");
jcb3.addItem("34");
jcb3.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
jtf3.setText((String)jcb3.getSelectedItem());
//jtaview.setText("SS");

// int fontsizeview=Integer.parseInt((String)jcb3.getSelectedItem());
//Font fontview=new Font("字體預覽",Font.BOLD,fontsizeview);
//jtaview.setFont(fontview);
//jtaview.setEditable(false);
}
}
);
gbc.gridheight=1;
gbc.gridwidth=1;
//gbc.gridx=1;
//gbc.gridy=0;
gbc.weightx=0.5;
gbc.weighty=0.5;
jd.getContentPane().setLayout(gbl);
//JLabel jl1=new JLabel("預覽:");
JLabel jl2=new JLabel("字型:");
JLabel jl3=new JLabel("大小:");
gbc.gridx=0;
gbc.gridy=0;
jd.getContentPane().add(jl2,gbc);
gbc.gridx=2;
gbc.gridy=0;
jd.getContentPane().add(jl3,gbc);
//gbc.gridx=4;
//gbc.gridy=0;
//jd.getContentPane().add(jl3,gbc);
gbc.gridx=0;
gbc.gridy=1;
jd.getContentPane().add(jtf2,gbc);
gbc.gridx=2;
gbc.gridy=1;
jd.getContentPane().add(jtf3,gbc);
//gbc.gridx=4;
// gbc.gridy=1;
//jd.getContentPane().add(jtf3,gbc);
gbc.gridx=0;
gbc.gridy=2;
jd.getContentPane().add(jcb2,gbc);
gbc.gridx=2;
gbc.gridy=2;
jd.getContentPane().add(jcb3,gbc);
//gbc.gridx=4;
//gbc.gridy=2;
//jd.getContentPane().add(jcb3,gbc);
gbc.gridx=4;
gbc.gridy=1;
jd.getContentPane().add(jbOK,gbc);
gbc.gridx=4;
gbc.gridy=2;
jd.getContentPane().add(jbCancel,gbc);
jbOK.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(jtf2.getText().equals("PLAIN"))
{
int fontsize=Integer.parseInt(jtf3.getText());
int fontstyle=0;
Font f=new Font("字體設置",fontstyle,fontsize);
jta.setFont(f);

// System.out.println(f.getFont("楷體_GB2312").getFontName());
}
if(jtf2.getText().equals("BOLD"))
{
int fontsize=Integer.parseInt(jtf3.getText());
int fontstyle=1;
Font f=new Font("字體設置",fontstyle,fontsize);
jta.setFont(f);
}
if(jtf2.getText().equals("ITALIC"))
{
int fontsize=Integer.parseInt(jtf3.getText());
int fontstyle=2;
Font f=new Font("字體設置",fontstyle,fontsize);
jta.setFont(f);
}
jd.dispose();
//System.out.println(fontstyle);
}
}
);
jbCancel.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
jd.dispose();
}
}
);
jd.setSize(200,120);
jd.setResizable(false);
jd.setVisible(true);
jd.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}
if(e.getActionCommand().equals("關於記事本"))
{
JOptionPane jop=new JOptionPane(null,JOptionPane.INFORMATION_MESSAGE);
jop.showMessageDialog(null,"小廖記事本","關於記事本",JOptionPane.OK_OPTION);
//System.out.println("OK");
}

}
class UndoHander implements UndoableEditListener
{
public void undoableEditHappened(UndoableEditEvent eundo)
{
undo.addEdit(eundo.getEdit());
}

}
}

9. java簡單記事本源代碼 帶解釋

自己寫的,有問題可以hi:
import java.awt.BorderLayout;
import java.awt.FileDialog;
import java.awt.Font;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.border.TitledBorder;

/*因為根據個人的電腦路徑可能有所偏差,沒有源路徑的情況下,設置默認保存路徑為D盤根目錄下
* 若要選擇保存其他地方,可以選擇 另存為*/

public class TestDemo extends JFrame {
private static final long serialVersionUID = -5355432125621015300L;
private String url = null;//文件路徑
private String str=null;//復制或剪切 的字元串
private StringSelection stringSelection=null;
private Clipboard clipboard=new Clipboard(str);
private Transferable transferable=null;
private DataFlavor flavor=null;
public TestDemo() {
init();
}

private void init() {
setTitle("我的記事本");
setSize(500, 600);
setContentPane(createContentPane());//添加主面板
}

/*創建主面板*/
private JPanel createContentPane() {
JPanel pane = new JPanel(new BorderLayout());

pane.add(BorderLayout.NORTH, createChocePane());//添加菜單欄
pane.add(createAreaPane());//添加文本編輯區域

return pane;
}

/*創建菜單欄,以及實現功能*/
private JPanel createChocePane() {
JPanel pane = new JPanel();
JMenuBar menuBar1 = new JMenuBar();
JMenu menu = new JMenu("文件");
menuBar1.add(menu);
JMenuItem menuIt1 = new JMenuItem("新建");
JMenuItem menuIt2 = new JMenuItem("打開");
JMenuItem menuIt3 = new JMenuItem("保存");
JMenuItem menuIt4 = new JMenuItem("另存為");
menu.add(menuIt1);
menu.add(menuIt2);
menu.add(menuIt3);
menu.add(menuIt4);

JMenuBar menuBar2 = new JMenuBar();
JMenu menu2 = new JMenu("編輯");
menuBar2.add(menu2);
JMenuItem menuIt5 = new JMenuItem("復制");
JMenuItem menuIt6 = new JMenuItem("剪切");
JMenuItem menuIt7 = new JMenuItem("粘帖");
menu2.add(menuIt5);
menu2.add(menuIt6);
menu2.add(menuIt7);

JMenuBar menuBar3 = new JMenuBar();
JMenu menu3 = new JMenu("幫助");
menuBar3.add(menu3);
JMenuItem menuIt8 = new JMenuItem("關於記事本");
menu3.add(menuIt8);

pane.add(menuBar1);
pane.add(menuBar2);
pane.add(menuBar3);

menuIt1.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {
testArea.setText(null);
}
});

menuIt2.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0) {

final FileDialog fd = new FileDialog(new JFrame(), "查找文件",
FileDialog.LOAD);
fd.setVisible(true);

if (fd.getDirectory() != null && fd.getFile() != null) {
testArea.setText(null);
url = fd.getDirectory() + fd.getFile();
try {
BufferedReader in = new BufferedReader(new FileReader(
url));
for (int i = 0;; i++) {
testArea.append(in.readLine());
if (in.read() == -1) {
break;
} else
continue;
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}

});

menuIt3.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {
if (url==null) {
url="D:\\新建 文本文檔.txt";
}

File f = new File(url);
BufferedWriter out = null;
try {
out = new BufferedWriter(new FileWriter(url));
f.createNewFile();
out.append(testArea.getText());
out.flush();

} catch (IOException e1) {
e1.printStackTrace();
} finally {
try {
out.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}

}
});

menuIt4.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0) {
FileDialog fd = new FileDialog(new JFrame(), "保存文本",
FileDialog.SAVE);
fd.setVisible(true);
if (url!=null) {
File f = new File(url);
BufferedWriter out = null;
try {
f.createNewFile();
out = new BufferedWriter(new FileWriter(url));
out.append(testArea.getText());
out.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
});

menuIt5.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {
str=testArea.getSelectedText();
stringSelection=new StringSelection(str);
clipboard.setContents(stringSelection, null);
}
});

menuIt6.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0) {
str=testArea.getSelectedText();
stringSelection=new StringSelection(str);
clipboard.setContents(stringSelection, null);
int start=testArea.getSelectionStart();
int end=testArea.getSelectionEnd();
testArea.replaceRange( null,start,end);

}
});

menuIt7.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {
transferable=clipboard.getContents(this);
flavor=DataFlavor.stringFlavor;
if (transferable.isDataFlavorSupported(flavor)) {
int start=testArea.getSelectionStart();
int end=testArea.getSelectionEnd();
testArea.replaceRange( null,start,end);
int pos=testArea.getCaretPosition();
try {
str=(String)transferable.getTransferData(flavor);
testArea.insert(str, pos);
} catch (UnsupportedFlavorException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}

}
}
});

menuIt8.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null,"功能簡單,絕對原創 ");
}
});

return pane;
}

JTextArea testArea;

private JScrollPane createAreaPane() {
JScrollPane pane = new JScrollPane();
pane.setBorder(new TitledBorder("編輯區域"));
testArea = new JTextArea();
testArea.setFont(new Font("宋體", Font.BOLD, 13));
testArea.setLineWrap(true);
pane.getViewport().add(testArea);
return pane;
}

public static void main(String[] args) {
TestDemo td = new TestDemo();
td.setVisible(true);
}

}