Download ppt

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Structured programming wikipedia , lookup

Abstraction (computer science) wikipedia , lookup

C Sharp (programming language) wikipedia , lookup

Object-oriented programming wikipedia , lookup

Transcript
Air Force Institute of Technology
Electrical and Computer Engineering
Object-Oriented Programming Design
Topic :
Applets
Maj Joel Young
[email protected]
24-May-17
Maj Joel Young
Object-Oriented
Programming
Design
Applet
Enables Java code to be downloaded
and run from a Web browser
24-May-17
Air Force Institute of Technology
Electrical and Computer Engineering
2
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
24-May-17
Air Force Institute of Technology
Electrical and Computer Engineering
3
Object-Oriented
Programming
Design
•
•
•
•
•
•
•
24-May-17
Converting applications to applets
Make an HTML page with an APPLET tag
Derive the class from JApplet, not from JFrame
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
Air Force Institute of Technology
Electrical and Computer Engineering
4
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();
}
}
24-May-17
Air Force Institute of Technology
Electrical and Computer Engineering
5
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);
}
}
24-May-17
Air Force Institute of Technology
Electrical and Computer Engineering
6
Object-Oriented
Programming
Design
Viewing applets
• Requires HTML file with the following line
<APPLET CODE="NotHelloWorldApplet.class" WIDTH=300 HEIGHT=100>
</APPLET>
• 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
24-May-17
Air Force Institute of Technology
Electrical and Computer Engineering
7
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
24-May-17
Air Force Institute of Technology
Electrical and Computer Engineering
8