来源(null)

import com.ms.wfc.app.*;
import com.ms.wfc.core.*;
import com.ms.wfc.ui.*;
import com.ms.wfc.io.*;
import com.ms.wfc.html.*;

/**
 * This class can take a variable number of parameters on the command
 * line. Program execution begins with the main() method. The class
 * constructor is not invoked unless an object of type 'MyNotepad' is
 * created in the main() method.
 */
public class MyNotepad extends Form
{
	private File currentDoc; // the I/O file stream
	private String fileName; // the most recently-used file name
	private boolean fileOpen=false; // set true after file opened
	
	public MyNotepad()
	{
		// Required for Visual J++ Form Designer support
		initForm();	
		this.setBounds(100,100,300,300);
		this.setText("Untitled - MyNotePad");

		// TODO: Add any constructor code after initForm call
	}

	/**
	 * MyNotepad overrides dispose so it can clean up the
	 * component list.
	 */
	public void dispose()
	{
		super.dispose();
		components.dispose();
	}

	private void HelpMenuAbout_click(Object source, Event e)
	{
		MessageBox.show("Version: Visual J++ 6.0","MyNotepad");
	}

	private void FileMenuNew_click(Object source, Event e)
	{
		// If edit control contains text,check if it should be saved
		if(EditBox.getText().length()!=0){
			// Open NewDialog class as a model dialog
			int result=new NewDialog().showDialog(this);
			// Retrieve result
			// If Yes botton was clicked open SaveAs Dialog box
			if(result==DialogResult.YES)
				this.FileMenuSaveAs_click(source,e);
			// If No Button was clicked clear edit control and set title
			else if(result==DialogResult.NO){
				EditBox.setText("");
				this.setText("Untitled - MyNotepad");
			}
		}
	}

	private void FileMenuOpen_click(Object source, Event e)
	{
		// Create an OpenFileDialog box
		OpenFileDialog ofd=new OpenFileDialog();
		// Set up filters and options
		ofd.setFilter("Text Docs(*.txt)|*.txt|All Files(*.*)|*.*");
		ofd.setDefaultExt("txt");
		// Run the open File Dialog box
		int OK=ofd.showDialog();
		// Check result of dialog box after it closes
		if(OK==DialogResult.OK){
			// Return the filename entered
			fileName=ofd.getFileName();
			// Oprn a File Stream on that filename
			currentDoc=File.open(fileName);
			// Retrieve length of file
			int ilength=(int)currentDoc.getLength();
			// Read in ANSI characters to edit buffer
			EditBox.setText(currentDoc.readStringCharsAnsi(ilength));
			// Close the file handle
			currentDoc.close();
			fileOpen=true;
			// Set the application'caption
			this.setText(File.getName(fileName)+" - MyNotepad");
		}
	}

	private void FileMenuSave_click(Object source, Event e)
	{
		// If there has been a file opened or saved
		if(fileOpen){
			// Open the furrent file again
			currentDoc=File.open(fileName);
			// Write edit control contents to file
			currentDoc.writeStringCharsAnsi(EditBox.getText());
			//Colse file handle
			currentDoc.close();
		} else
			this.FileMenuSaveAs_click(source,e);
	}

	private void FileMenuSaveAs_click(Object source, Event e)
	{
		SaveFileDialog sfd=new SaveFileDialog();
		// Set the options
		sfd.setFileName(fileName);
		sfd.setTitle("Save Text File");
		sfd.setTitle("Text Docs(*.txt)|*.txt|All Files(*.*)|*.*");
		sfd.setDefaultExt("txt");
			// Run the dialog box
			int result=sfd.showDialog();
			if(result==DialogResult.OK){
				// retrieve the filename entered in the dialog box
				fileName=sfd.getFileName();
				// Open a File stream with ability to create a file if needed
				currentDoc=new File(fileName,FileMode.OPEN_OR_CREATE);
				// Write the contents of the edit control to the file
				currentDoc.writeStringCharsAnsi(EditBox.getText());
				// Close the file handle
				currentDoc.close();
				fileOpen=true;
				// Set the app's caption using the filename minus its path
				this.setText(File.getName(fileName)+" - MyNotepad");
			}
	}

	private void FileMenuExit_click(Object source, Event e)
	{
		//Call the new file handler to invoke NewDialog
		//to ask if user want to save current data
		this.FileMenuNew_click(source,e);
		Application.exit();
	}

	/**
	 * NOTE: The following code is required by the Visual J++ form
	 * designer.  It can be modified using the form editor.  Do not
	 * modify it using the code editor.
	 */
	Container components = new Container();
	MainMenu Menu = new MainMenu();
	MenuItem FileMenu = new MenuItem();
	MenuItem FileMenuNew = new MenuItem();
	MenuItem FileMenuOpen = new MenuItem();
	MenuItem FileMenuSave = new MenuItem();
	MenuItem FileMenuSaveAs = new MenuItem();
	MenuItem FileMenuFg1 = new MenuItem();
	MenuItem FileMenuExit = new MenuItem();
	MenuItem HelpMenu = new MenuItem();
	MenuItem HelpMenuAbout = new MenuItem();
	Edit EditBox = new Edit();

	private void initForm()
	{
		FileMenuNew.setText("&New");
		FileMenuNew.addOnClick(new EventHandler(this.FileMenuNew_click));

		FileMenuOpen.setText("&Open");
		FileMenuOpen.addOnClick(new EventHandler(this.FileMenuOpen_click));

		FileMenuSave.setText("&Save");
		FileMenuSave.addOnClick(new EventHandler(this.FileMenuSave_click));

		FileMenuSaveAs.setText("Save&As");
		FileMenuSaveAs.addOnClick(new EventHandler(this.FileMenuSaveAs_click));

		FileMenuFg1.setText("-");

		FileMenuExit.setText("&Exit");
		FileMenuExit.addOnClick(new EventHandler(this.FileMenuExit_click));

		FileMenu.setMenuItems(new MenuItem[] {
							  FileMenuNew, 
							  FileMenuOpen, 
							  FileMenuSave, 
							  FileMenuSaveAs, 
							  FileMenuFg1, 
							  FileMenuExit});
		FileMenu.setText("&File");

		HelpMenuAbout.setText("&About");
		HelpMenuAbout.addOnClick(new EventHandler(this.HelpMenuAbout_click));

		HelpMenu.setMenuItems(new MenuItem[] {
							  HelpMenuAbout});
		HelpMenu.setText("&Help");

		Menu.setMenuItems(new MenuItem[] {
						  FileMenu, 
						  HelpMenu});
		/* @designTimeOnly Menu.setLocation(new Point(104, 112)); */

		this.setText("MyNotepad");
		this.setAutoScaleBaseSize(new Point(6, 12));
		this.setClientSize(new Point(292, 273));
		this.setMenu(Menu);

		EditBox.setFont(new Font("Fixedsys", 12.0f, FontSize.CHARACTERHEIGHT, FontWeight.NORMAL, false, false, false, CharacterSet.DEFAULT, 0));
		EditBox.setLocation(new Point(8, 8));
		EditBox.setSize(new Point(272, 256));
		EditBox.setTabIndex(1);
		EditBox.setText("");
		EditBox.setMultiline(true);
		EditBox.setScrollBars(ScrollBars.VERTICAL);

		this.setNewControls(new Control[] {
							EditBox});
	}

	/**
	 * The main entry point for the application. 
	 *
	 * @param args Array of parameters passed to the application
	 * via the command line.
	 */
	public static void main(String args[])
	{
		Application.run(new MyNotepad());
	}
}


Link: http://www.asm32.net/article_details.aspx?id=96