Presentation is loading. Please wait.

Presentation is loading. Please wait.

19-Sep-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming Design Topic : Applets Maj Joel Young

Similar presentations


Presentation on theme: "19-Sep-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming Design Topic : Applets Maj Joel Young"— Presentation transcript:

1 19-Sep-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming Design Topic : Applets Maj Joel Young Joel.Young@afit.edu Maj Joel Young

2 Air Force Institute of Technology Electrical and Computer Engineering 19-Sep-152 Object-Oriented Programming Design Applet Enables Java code to be downloaded and run from a Web browser

3 Air Force Institute of Technology Electrical and Computer Engineering 19-Sep-153 Object-Oriented Programming Design Applet Security Restricted execution environment – “sandbox” Rules –Can never run local executables –Cannot communicate with any host other than the server from which they are downloaded –Cannot read or write to local computer –Cannot find information about the local computer –Windows that pop up in an applet carry a warning Implementation –Code interpreted by Java virtual machine, not executed directly –Security manager checks all sensitive operations –Applets can be signed to identify their origin

4 Air Force Institute of Technology Electrical and Computer Engineering 19-Sep-154 Object-Oriented Programming Design Converting applications to applets Make an HTML page with an APPLET tag Derive the class from J Applet, not from J Frame Eliminate the main method in the application Replace the constructor with a method called init Eliminate any calls to setSize or setTitle Remove call to setDefaultCloseOperation Don’t call show

5 Air Force Institute of Technology Electrical and Computer Engineering 19-Sep-155 Object-Oriented Programming Design Application class NotHelloWorld extends JFrame { public NotHelloWorld() { setTitle("NotHelloWorld"); setSize(300, 100); Container contentPane = getContentPane(); JLabel label = new JLabel("Not a Hello, World application", SwingConstants.CENTER); contentPane.add(label); } public static void main(String[] args) { NotHelloWorld frame = new NotHelloWorld(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.show(); }

6 Air Force Institute of Technology Electrical and Computer Engineering 19-Sep-156 Object-Oriented Programming Design Applet public class NotHelloWorldApplet extends JApplet { public void init() { Container contentPane = getContentPane(); JLabel label = new JLabel("Not a Hello, World applet", SwingConstants.CENTER); contentPane.add(label); }

7 Air Force Institute of Technology Electrical and Computer Engineering 19-Sep-157 Object-Oriented Programming Design Viewing applets Requires HTML file with the following line View with –appletviewer program from JDK –Java enabled browser –Not well supported by Microsoft so plugin adaptor needed (part of JRE) –Convert html files for plugin with HTML Converter

8 Air Force Institute of Technology Electrical and Computer Engineering 19-Sep-158 Object-Oriented Programming Design Life cycle of an applet init method -- called when applet is first started start method -- called after init or when user returns to the page to restart the applet stop method -- called when user moves off of page destroy method -- called when browser shuts down normally


Download ppt "19-Sep-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming Design Topic : Applets Maj Joel Young"

Similar presentations


Ads by Google