Creating Applets. What is an applet? What is an applet? A Java program that runs in a web browser. A Java program that runs in a web browser. An applet.

Slides:



Advertisements
Similar presentations
Learn about Java applets. Know the differences between Java applets and applications. Designing and using Java applets Running Java applets. Security.
Advertisements

Dept. of Computer Science - SSBN Java Applets Vishnuvardhan.M.
CMSC 341 Building Java GUIs. 09/26/2007 CMSC 341 GUI 2 Why Java GUI Development? Course is about Data Structures, not GUIs. We are giving you the opportunity.
Things to mention public static void main(String [] args) –The starting point for a free-standing Java application (i.e. one not run from the DrJava interactions.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 20, 2005.
Slides prepared by Rose Williams, Binghamton University Mouse Events + Chapter 17: Applets.
Applets. The Applet Class public class MyApplet extends java.applet.Applet {... /** The no-arg constructor is called by the browser when the Web page.
Review of Java Applets Vijayan Sugumaran Decision and Information Sciences Oakland University.
COMP 14 Introduction to Programming Miguel A. Otaduy June 8, 2004.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 16 Applets.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 21, 2005.
Slides prepared by Rose Williams, Binghamton University Chapter 18 Applets.
1 Applets Chapter 1 To understand:  why applets are used to extend the capabilities of Web pages  how an applet is executed and know about the restrictions.
Java Applets. Lecture Objectives Learn about Java applets. Know the differences between Java applets and applications. Designing and using Java applets.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 14 Applets, Images,
28-Jun-15 Applets. 2 An applet is a program that is typically embedded in a Web page and can be run from a browser You need special HTML in the Web page.
COMP 14 Introduction to Programming Miguel A. Otaduy June 7, 2004.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved COS240 Object-Oriented Languages.
Chapter 13: Advanced GUIs and Graphics J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L05 (Chapter 16) Applets.
Applets, HTML and GUI’s Recitation – 04/11/2008 CS 180 Department of Computer Science, Purdue University.
Java Applets. Lecture Objectives  Learn about Java applets.  Know the differences between Java applets and applications.  Designing and using Java.
Applets Java API.
Chapter 12 Applets and Advanced Graphics  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets.
Chapter 13 Advanced GUIs and Graphics. Chapter Objectives Learn about applets Explore the class Graphics Learn about the class Font Explore the class.
19-Sep-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming Design Topic : Applets Maj Joel Young
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Applets Chapter 17.  Java’s big splash onto the scene came in the mid 90’s. The people at Sun Microsystems had managed to work java programs into Web.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Using the Netbeans GUI Builder. The Netbeans IDE provides a utility called the GUI Builder that assists you with creating Windows applications. The Netbeans.
JAPPLET.
Learn about the types of Graphics that are available Develop a basic Graphics applet Develop a basic Graphics application Review the Java API and use.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
1 INF160 IS Development Environments AUBG, COS dept Lecture 04 Title: Computer Applications (Extract from Syllabus)
Chapter 17: Applets, Images, and Sound. Objectives Learn about applets Write an HTML document to host an applet Use the init() method Work with JApplet.
Putting Applets into Web Pages.  Two things are involved in the process of putting applets onto web pages ◦ The.class files of the applet ◦ The html.
GUI programming Graphical user interface-based programming.
Chapter 12 Applets and Advanced GUI  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets F.
Chapter 13Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 13 l HTML l Applets Applets and HTML.
Chapter 10: Applets and Advanced Graphics The Applet Class The Applet Class The HTML Tag The HTML Tag Passing Parameters to Applets Passing Parameters.
Applets. What is an applet? Why create applets instead of applications? – Applets are Java programs that can be embedded in an HTML document – In contrast,
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved COS240 O-O Languages AUBG,
Pravin Yannawar, DOCS, NMU Jalgaon Basic Java : Applets 2 Objectives of This Session Identify the need for Applets Distinguish between Applets and Applications.
MSc Workshop - © S. Kamin, U. ReddyLect 3 - GUI -1 Lecture 3 - Graphical User Interfaces r GUI toolkits in Java API r JFrame r GUI components.
1 University of Utah – School of Computing Computer Science 1021 "Applets and Applications"
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
Creating Windows. How can we use Java to create programs that use windows (GUI applications)? How can we use Java to create programs that use windows.
Chapter 14 Applets and Advanced GUI  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets F.
1 Applets. 2 Design of Applets 3 Sun wrote Java to be executable within a hosting application browser The applications are applets. An applet is downloaded.
CIS Intro to JAVA Lecture Notes Set 8 9-June-05.
1 Applications & Applets Standalone applications & Java applets Peter Mozelius DSV/UCSC.
Chapter 131 Applets and HTML Chapter Objectives learn how to write applets learn to write a simple HTML document learn how to embed an applet in.
Applets Java code is compiled into byte code instead of machine language –Languages like C, C++, Pascal and others are compiled into machine language so.
Basics of GUI Programming Chapter 11 and Chapter 22.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Lesson 28: More on the GUI button, frame and actions.
Graphical User Interface (GUI)
Advanced Topics on Graphical User Interfaces CardLayout JTabbedPane JFrame.
1 Applets Programming. Introduction Java programs are divided into two main categories, applets and applications. An application is an ordinary Java program.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 17 : Applets King Fahd University of Petroleum & Minerals College of Computer Science.
Chapter 14 Applets. Applets: Introduction Java programs are divided into two main categories, applets and applications An application is an ordinary Java.
Java Applets.
Java Applets.
Chapter 13: Advanced GUIs and Graphics
30 Java Applets.
Graphical user interface-based programming
Applets.
UNIT-5.
Introduction to Computing Using Java
Advanced GUIs and Graphics
Presentation transcript:

Creating Applets

What is an applet? What is an applet? A Java program that runs in a web browser. A Java program that runs in a web browser. An applet is a GUI application. An applet is a GUI application. Think of an applet as a GUI program that runs under the control of a web browser instead of a window. Think of an applet as a GUI program that runs under the control of a web browser instead of a window. If you know how to create a GUI application using the JFrame class, it is easy to create an applet. If you know how to create a GUI application using the JFrame class, it is easy to create an applet.

To create an applet you must: To create an applet you must: Step 1. Create your applet. Step 1. Create your applet. Step 2. Create a web page that displays the applet. Step 2. Create a web page that displays the applet.

Step 1 – Creating an Applet. Step 1 – Creating an Applet. Creating an applet is easy. Creating an applet is easy. All we have to do is take a GUI application and convert it. All we have to do is take a GUI application and convert it. Before we do that, however, we have to know the differences between a GUI app and an applet. Before we do that, however, we have to know the differences between a GUI app and an applet.

Differences Between GUI Windows and Applets: Differences Between GUI Windows and Applets: GUI Window Applications Applets -Uses the JFrame class -Uses the JApplet class -Uses a constructor to build the GUI components -Uses the init( ) method to build the GUI components. You don’t need a constructor -Uses a static main method to create an instance of the class. -The web browser automatically creates an instance of the class. -The following methods are usually used with a constructor: -setTitle -setTitle -setSize -setSize -set DefaultCloseOperation -set DefaultCloseOperation -setVisible -setVisible -You don’t have to use those methods because the web browser: -already has a title. -already has a title. -and HTML file set the size of an applet. -and HTML file set the size of an applet. -provides an exit button. -provides an exit button. -makes the applet visible. -makes the applet visible.

To convert a GUI application to an applet: To convert a GUI application to an applet: Change “extends JFrame” to “extends JApplet” Change “extends JFrame” to “extends JApplet” Get rid of your Exit Button and the Event Listener for the Exit Button. Get rid of your Exit Button and the Event Listener for the Exit Button. Get rid of the application’s dimensions (the Height and Width). Get rid of the application’s dimensions (the Height and Width). Change the Constructor to the init( ) method. Change the Constructor to the init( ) method. Get rid of the setTitle( ) method, the setSize( ) method, the SetDefaultCloseOperation( ) method, and the setVisible( ) method. Get rid of the setTitle( ) method, the setSize( ) method, the SetDefaultCloseOperation( ) method, and the setVisible( ) method. Get rid of your public static main( ) method. Get rid of your public static main( ) method.

public Countdown( ) { //Set the window title. setTitle("Countdown Calculator"); //Set the size of the window setSize(WINDOW_WIDTH, WINDOW_HEIGHT); //Specify what happens when the close button is clicked setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Build the panel and add it to the frame. //This is a method in this class buildPanel(); //Add the panel to the frame's content pane add(panel); //Display the window setVisible(true); } Before: After: public void init( ) { //You don't set the window title for an Applet. //setTitle("Countdown Calculator"); //You don't do the following because the web page sets the size //setSize(WINDOW_WIDTH, WINDOW_HEIGHT); //You don't do the following because an applet does not close //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Build the panel and add it to the frame. //This is a method in this class buildPanel(); //Add the panel to the frame's content pane add(panel); //You do not have to set the applet to visible //setVisible(true); }

Step 2 – Creating a Web Page that displays an applet. Step 2 – Creating a Web Page that displays an applet. To display an applet, we need to create a web page. To display an applet, we need to create a web page. Creating a simple web page is easy: Creating a simple web page is easy: Create a notepad file. Create a notepad file. Change the filename extention from “.txt” to “.html” Change the filename extention from “.txt” to “.html” Put the code in the next slide in the HTML file…. Put the code in the next slide in the HTML file….

Simple HTML Page Java Applet! The following is a java applet:

Simple HTML Page Java Applet! The following is a java applet: This is the line of code in your HTML file that calls the “.class” file. Here is where you set the width and the height of your applet.

Remember, we have to compile our source file (Countdown.java) to create a “.class” file. When compiled, an applet may have more than one class file. Remember, we have to compile our source file (Countdown.java) to create a “.class” file. When compiled, an applet may have more than one class file. For example, our demo for Countdown.java created 3 files: For example, our demo for Countdown.java created 3 files: Countdown$1.class Countdown$1.class Countdown$CalcButtonListener.class Countdown$CalcButtonListener.class Countdown.class Countdown.class These files usually go into a folder called “classes.” These files usually go into a folder called “classes.” You must tell the HTML file where: You must tell the HTML file where: The main class file is  “Coundown.class” The main class file is  “Coundown.class” The directory for all of the class files  “classes” The directory for all of the class files  “classes”

In Netbeans, an HTML file will be created for you in the project’s “build” folder. This HTML file will reference classes inside the “classes” folder. In Netbeans, an HTML file will be created for you in the project’s “build” folder. This HTML file will reference classes inside the “classes” folder.

The Netbean’s HTML file default width is 350 and the default height is 200. You will need to CHANGE those to ensure that your Applet is formatted correctly. The Netbean’s HTML file default width is 350 and the default height is 200. You will need to CHANGE those to ensure that your Applet is formatted correctly.

Misc: Misc: Sorry, but you can’t create programs using the Netbeans GUI Builder and then convert them into Applets. Bummer! Sorry, but you can’t create programs using the Netbeans GUI Builder and then convert them into Applets. Bummer!