2012年3月22日星期四

How to Create a Web Page Containing an Applet That Works Like a Simple Text Editor Using Java

Developing a simple text editor in Java and embedding it right into a web site as a Java applet is a simple procedure, since all of the functionality required has already been contained in only two classes from the Java standard library. All that is required would be to put them together and produce a mention of the the resulting class in your HTML file.


Produce a file named \"EditorApplet. java\" using whether text editor or perhaps a Java built-in development environment (IDE). Open the file and import both classes you'll need from the Java library: the JApplet class and the JEditorPane. For instance: <br /><br />import javax. swing. JApplet<br />GO<br />import javax. swing. JEditorPane; Create an EditorApplet class with the addition of the next code: <br /><br />/**<br /> * This applet will serve as an easy text editor inside a web site. <br /> * @author Kevin Walker<br /> */<br />public class EditorApplet extends JApplet <br /> // All other code will go here.<br /> Put in a JEditorPane to the applet with this command: <br /><br />JEditorPane editor = new JEditorPane(); Put in a constructor to the applet such that it knows steps to start up when the webpage loads it. You only have to do a couple of things for this to work--add the JEditorPane to the consumer interface and make the applet visible: <br /><br /> public EditorApplet() <br /> this.add(editor)<br />GO<br /> this.setVisible(true)<br />GO<br /> Compile the applet code right into a working applet by typing the next to the command prompt: <br /><br />javac EditorApplet. java<br /> <br />This will create a file named \"EditorApplet. class. \" This is actually the file your online page will connect to in the applet tag. Create an HTML file named \"editorAppletPage. html. \" <br /><br />Paste the next inside: <br /><br /><html><br /> <head><br /> <title></title><br /> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><br /> </head><br /> <body><br /> <applet code=\"EditorApplet. class\" height=\"200\" width=\"200\"/><br /> </body><br /></html><br /><br />The most significant line may be the \"applet\" tag. The \"code\" parameter will give you the URL, relative to the present web site, that the user's browser will find the applet \"class\" file. The height and width define the height and width of the applet within the browser.



没有评论:

发表评论