DOC PREVIEW
LETU COSC 2103 - Chapter 3 - Introduction to Java Applets

This preview shows page 1-2-3-23-24-25-26-47-48-49 out of 49 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 49 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 49 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 49 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 49 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 49 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 49 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 49 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 49 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 49 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 49 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 49 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Chapter 3 - Introduction to Java Applets3.1 Introduction3.2 Sample Applets from the Java 2 Software Development Kit3.2 Sample Applets from the Java 2 Software Development KitSlide 5Slide 6Slide 73.3 Simple Java Applet: Drawing a StringJava applet Program OutputSlide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 203.4 Drawing Strings and LinesWelcomeApplet2.java 1. import 2. Class WelcomeApplet2 (extends JApplet) 3. paint 3.1 drawString 3.2 drawString on same x coordinate, but 15 pixels downHTML file Program OutputWelcomeLines.java 2. Class WelcomeLines (extends JApplet) 3. paint 3.1 drawLine 3.2 drawLine 3.3 drawString Program OutputHTML fileSlide 263.5 Adding Floating-Point NumbersAdditionApplet.java 1. import 2. Class AdditionApplet (extends JApplet) 3. Fields 4. init 4.1 Declare variables 4.2 showInputDialog 4.3 parseDouble5. Draw applet contents 5.1 Draw a rectangle 5.2 Draw the results HTML fileProgram OutputSlide 31Slide 32Slide 33Slide 34Slide 35Slide 36Slide 37Slide 38Slide 393.6 Java Applet Internet and World Wide Web Resources3.7 (Optional Case Study) Thinking About Objects: Identifying the Classes in a Problem StatementSlide 423.7 (Optional Case Study) Thinking About Objects: Identifying the Classes in a Problem StatementSlide 44Slide 45Slide 46Slide 47Slide 48Slide 49 2003 Prentice Hall, Inc. All rights reserved.1Chapter 3 - Introduction to Java AppletsOutline3.1 Introduction3.2 Sample Applets from the Java 2 Software Development Kit 3.3 Simple Java Applet: Drawing a String 3.4 Drawing Strings and Lines 3.5 Adding Floating-Point Numbers 3.6 Java Applet Internet and World Wide Web Resources 3.7 (Optional Case Study) Thinking About Objects: Identifying the Classes in a Problem Statement 2003 Prentice Hall, Inc. All rights reserved.23.1 Introduction•Applet–Program that runs in •appletviewer (test utility for applets)•Web browser (IE, Communicator)–Executes when HTML (Hypertext Markup Language) document containing applet is opened and downloaded–Applications run in command windows•Notes–Mimic several features of Chapter 2 to reinforce them–Focus on fundamental programming concepts first•Explanations will come later 2003 Prentice Hall, Inc. All rights reserved.33.2 Sample Applets from the Java 2 Software Development Kit •Sample Applets–Provided in Java 2 Software Development Kit (J2SDK)–Source code included (.java files)•Study and mimic source code to learn new features•All programmers begin by mimicking existing programs–Located in demo directory of J2SDK install–Can download demos and J2SDK fromjava.sun.com/j2se/1.4.1/ 2003 Prentice Hall, Inc. All rights reserved.43.2 Sample Applets from the Java 2 Software Development Kit•Running applets–In command prompt, change to demo subdirectory of appletcd c:\j2sdk1.4.1\demo\applets cd appletDirectoryName–There will be an HTML file used to execute applet–Type appletviewer example1.html•appletviewer loads the html file specified as its command-line argument•From the HTML file, determines which applet to load (more section 3.3)–Applet will run, Reload and Quit commands under Applet menu 2003 Prentice Hall, Inc. All rights reserved.53.2 Sample Applets from the Java 2 Software Development Kit•You start as player "X"Fig. 3.2 Sample execution of applet TicTacToe. 2003 Prentice Hall, Inc. All rights reserved.63.2 Sample Applets from the Java 2 Software Development KitFig. 3.4 Sample execution of applet DrawTest. Drag the mouse pointer in the white area to draw.Select the drawing color by clicking the circle for the color you want. These GUI components are commonly known as radio buttons.Select the shape to draw by clicking the down arrow, then clicking Lines or Points. This GUI component is commonly known as a combo box, choice or drop-down list. 2003 Prentice Hall, Inc. All rights reserved.73.2 Sample Applets from the Java 2 Software Development Kit•Demonstrates 2D drawing capabilities built into Java2Click a tab to select a two-dimensional graphics demo.Try changing the options to see their effect on the demonstration. 2003 Prentice Hall, Inc. All rights reserved.83.3 Simple Java Applet: Drawing a String•Now, create applets of our own–Take a while before we can write applets like in the demos–Cover many of same techniques•Upcoming program–Create an applet to display "Welcome to Java Programming!"–Show applet and HTML file, then discuss them line by line 2003 Prentice Hall, Inc.All rights reserved.Outline9Java appletProgram Output1 // Fig. 3.6: WelcomeApplet.java2 // A first applet in Java.3 4 // Java packages 5 import java.awt.Graphics; // import class Graphics6 import javax.swing.JApplet; // import class JApplet 7 8 public class WelcomeApplet extends JApplet { 9 10 // draw text on applet’s background 11 public void paint( Graphics g ) 12 { 13 // call superclass version of method paint 14 super.paint( g ); 15 16 // draw a String at x-coordinate 25 and y-coordinate 2517 g.drawString( "Welcome to Java Programming!", 25, 25 );18 19 } // end method paint 20 21 } // end class WelcomeAppletimport allows us to use predefined classes (allowing us to use applets and graphics, in this case).extends allows us to inherit the capabilities of class JApplet.Method paint is guaranteed to be called in all applets. Its first line must be defined as above. 2003 Prentice Hall, Inc. All rights reserved.103.3 Simple Java Applet: Drawing a String–Comments•Name of source code and description of applet–Import predefined classes grouped into packages•import declarations tell compiler where to locate classes used•When you create applets, import the JApplet class (package javax.swing)•import the Graphics class (package java.awt) to draw graphics –Can draw lines, rectangles ovals, strings of characters•import specifies directory structure5 import java.awt.Graphics; // import class Graphics6 import javax.swing.JApplet; // import class JApplet 1 // Fig. 3.6: WelcomeApplet.java2 // A first applet in Java. 2003 Prentice Hall, Inc. All rights reserved.113.3 Simple Java Applet: Drawing a String–Applets have at least one class declaration


View Full Document

LETU COSC 2103 - Chapter 3 - Introduction to Java Applets

Documents in this Course
Arrays

Arrays

16 pages

Templates

Templates

17 pages

Methods

Methods

22 pages

Methods

Methods

22 pages

Arrays

Arrays

11 pages

Load more
Download Chapter 3 - Introduction to Java Applets
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Chapter 3 - Introduction to Java Applets and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Chapter 3 - Introduction to Java Applets 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?