1 / 10

Java Unit 5: Applets and Graphics

Java Unit 5: Applets and Graphics. Putting Applets into Web Pages. Classes and HTMLs. Two things are involved in the process of putting applets onto web pages The .class files of the applet The html file of the page

Download Presentation

Java Unit 5: Applets and Graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java Unit 5: Applets and Graphics Putting Applets into Web Pages

  2. Classes and HTMLs. • Two things are involved in the process of putting applets onto web pages • The .class files of the applet • The html file of the page • Remember: any Java source file that compiles correctly will produce a .class file.

  3. Finding the .class files • Compiled .class files for Java source code should be found: • C:/UserName/workspace/NameOfProject/bin • It may also be found in • C:/UserName/Android/workspace/NameOfProject/bin

  4. Creating the HTML • The HTML file should be created inside the same folder as the .class files for the applet. • This is to reduce complexity in defining the path to the applet class in the HTML file. • You could start creating an HTML file in Notepad by: • Starting a new text file, and adding your code from there • When it comes time to save, remove the *.txt extension, and add ‘.html’ to the end of the file instead. (Ex: MyHtmlPage.html)

  5. HTML Code <html><applet code=“MyJavaApplet.class” width=“500” height=“500”></applet></html>

  6. HTML Code • HTML is a markup language, using a system of tags to define elements of a document. • <html> is a tag that denotes a start of an html file, while </html> denotes the end. • Likewise, <applet> and </applet> are used in the same way.

  7. HTML Code • You’ll notice inside the first applet tag, there are attributes assigned inside it (code, width, height) • ‘code’ is the directory where the HTML file would be able to find the main .class entry point for the applet. • ‘width’ and ‘height’ define the size as it appears on the web page. • Note that the values assigned to these attributes are defined in double quotes.

  8. A couple of other notes • If you have to change a line in the source code of the Java files and recompile, you should replace the .class file in the html directory with the new one. • When running Java applets, the user must have the Java Runtime Environment installed. • For security or other reasons, some systems may not run Java content through web pages.

  9. Passing Security • With the newest version of Java, unsigned applets are not allowed to run on any machine. • This means that if we try running our applet through an html page we created, the applet will not run at all, because it is considered a security risk. • Therefore, we’ll need to create an exception for this.

  10. Passing Security • Open the Java Control Panel • On Windows start, search for “Configure Java” • Java\jre7\bin\javacpl.exe • Go to the Security tab, and click the “Edit Site List…” button. • In the blank space on the dialog, type in the file or html location of the html file you want to run. • Ex: http://math.uaa.alaska.edu/~android/java/unit5/unit5applet • Click Add, then OK on both dialogs. You should be able to run that applet now.

More Related