Chapter 7 Applets. Answers

Similar documents

9. APPLETS AND APPLICATIONS

SIMPLE APPLET PROGRAM

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 9: Writing Java Applets. Introduction

Framework. Set of cooperating classes/interfaces. Example: Swing package is framework for problem domain of GUI programming

Road Map. Introduction to Java Applets Review applets that ship with JDK Make our own simple applets

CS 315 Software Design Homework 1 First Sip of Java Due: Sept. 10, 11:30 PM

TWO-DIMENSIONAL FIGURES

An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a

Summary. 962 Chapter 23 Applets and Java Web Start

Module 5 Applets About Applets Hierarchy of Applet Life Cycle of an Applet

PROGRAMMING LANGUAGE 2

Programming: You will have 6 files all need to be located in the dir. named PA4:

CSCI 053. Week 5 Java is like Alice not based on Joel Adams you may want to take notes. Rhys Price Jones. Introduction to Software Development

Unit 1- Java Applets. Applet Programming. Local Applet and Remote Applet ** Applet and Application

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

CSC 551: Web Programming. Fall 2001

CS 201 Advanced Object-Oriented Programming Lab 1 - Improving Your Image Due: Feb. 3/4, 11:30 PM

Graphics Applets. By Mr. Dave Clausen

1 Getting started with Processing

Java Applet Basics. Life cycle of an applet:

OBJECT ORIENTED PROGRAMMING. Course 8 Loredana STANCIU Room B613

Programming In Java Prof. Debasis Samanta Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

(Refer Slide Time: 02:01)

Java - Applets. public class Buttons extends Applet implements ActionListener

Java - Applets. C&G criteria: 1.2.2, 1.2.3, 1.2.4, 1.3.4, 1.2.4, 1.3.4, 1.3.5, 2.2.5, 2.4.5, 5.1.2, 5.2.1,

Java TM Applets. Rex Jaeschke

Page 1 of 7. public class EmployeeAryAppletEx extends JApplet

Lab 3: Work with data (IV)

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Chapter 3 - Introduction to Java Applets

Java How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved.

SNS COLLEGE OF ENGINEERING, Coimbatore

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

WebVisit User course

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java

Contents 8-1. Copyright (c) N. Afshartous

Lecture Static Methods and Variables. Static Methods

Lecture Static Methods and Variables. Static Methods

Introduction to Java Applets 12

Java Programming Lecture 6

Announcements. Java Graphics. Exceptions. Java Odds & Ends

UNIT -1 JAVA APPLETS

Unit 7: Event driven programming

Chapter 12 Advanced GUIs and Graphics

CS Problem Solving and Object-Oriented Programming

In order to teach you about computer programming, I am going to make several assumptions from the start:

HOW TO. In this section, you will find. miscellaneous handouts that explain. HOW TO do various things.

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 7, Name:

Object Oriented Programming with Java. Unit-1

Overview. Applets. A Java GUI inside your browser! Important methods Drawing images Playing audio Getting input parameters Double buffering

Outline. Announcements. Feedback. CS1007: Object Oriented Design and Programming in Java. Java beans Applets

Graphics Applets. By Mr. Dave Clausen

Introduction to Computers and Java

Drawing Graphics in C Sharp

CSE115 Lab 4 Fall 2016

Assignment 2. Application Development

cs Java: lecture #5

UNIT-2: CLASSES, INHERITANCE, EXCEPTIONS, APPLETS. To define a class, use the class keyword and the name of the class:

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

CT 229 Arrays in Java

Practice Midterm 1. Problem Points Score TOTAL 50

WebSign SDK (Java) Java(Client) - Java(Server) Developer s Guide

Dynamic code downloading using Java TM (Using the java.rmi.server.codebase Property)

Using the API: Introductory Graphics Java Programming 1 Lesson 8

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

CISC 1600, Lab 2.1: Processing

Graphics and Painting

AplusBug dude = new AplusBug(); A+ Computer Science -

Lecture 7 A First Graphic Program And Data Structures & Drawing

User interfaces and Swing

Graphics -- To be discussed

2. Registration You need to register an account before you can start using sft.pearson.com. You can do this either by

CS 209 Programming in Java #12 JAR Files: Creation and Use

Programmierpraktikum

CSC 160 LAB 8-1 DIGITAL PICTURE FRAME. 1. Introduction

Understanding How Java Programs Work

Using Methods. Methods that handle events. Mairead Meagher Dr. Siobhán Drohan. Produced by: Department of Computing and Mathematics

Painting your window

Java Applets This is not a Java course! (You re supposed to know about Java.)

PESIT Bangalore South Campus

Block I Unit 2. Basic Constructs in Java. AOU Beirut Computer Science M301 Block I, unit 2 1

Graphics in Swing. Engineering 5895 Faculty of Engineering & Applied Science Memorial University of Newfoundland

OTTOMAN ARCHIVE CBR SYSTEM USER MANUAL

Java Applet & its life Cycle. By Iqtidar Ali

Instructions for Crossword Assignment CS130

Higher National Diploma in Information Technology First Year, Second Semester Examination 2015

+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created.

CISC 1600, Lab 2.2: Interactivity in Processing

Chapter 14: Applets and More

CS 201 Advanced Object-Oriented Programming Lab 10 - Recursion Due: April 21/22, 11:30 PM

Java Mouse Actions. C&G criteria: 5.2.1, 5.4.1, 5.4.2,

Advanced Computer Programming

Introduction to the Java T M Language

Topic 7: Algebraic Data Types

AP CS Unit 12: Drawing and Mouse Events

The HOME Tab: Cut Copy Vertical Alignments

Programs, Statements, Variables

CS1004: Intro to CS in Java, Spring 2005

Chapter 14: Applets and More

Transcription:

Chapter 7 Applets Answers 1. D The drawoval(x, y, width, height) method of graphics draws an empty oval within a bounding box, and accepts 4 int parameters. The x and y coordinates of the left/top point of the bounding box are sent as the first 2 parameters to the drawoval method. The third and fourth parameters sent are the width and height of the bounding box. The oval drawn lies within the bounding box. In this example the left top point is 100,100, the width is 80 and the height is 40. Answer D is the only answer that describes this oval. 2. A,F The setcolor method of the graphics context sets the current color that will be used for the current graphics context. This setcolor method accepts 1 parameter, an instance of a Color object. The Color class has a number of static final variables that can be used to define a specific color for a Color object, and one of these static variables is red. Therefore answer A is correct, since it accesses this static variable through the Color class. Answer E is also correct since when specifying a Color with a string of colors, the last one in the line is used, and here the last one is red. Answer B is not correct because the static variable in the Color class for red is with all lowercase letters, and here uppercase letters are used (RED). Answers C and D are incorrect since they represent String objects, and the setcolor method accepts an object of type Color only. Anser E is incorrect since a variable called red is being passed here, and there is no constructor for the Color class that accepts something like this.

3. A Clipping is used to restrict the area that the Graphics context will modify. Every instance of a Graphics context has a clip region, which is by default the whole associated component. When the Graphics instance is passed to the paint method, it already has its clip region set, so the paint method knows which area to draw. 4. C When creating a new Font instance the main constructor of the Font class accepts 3 parameters. The first is the font name, expressed as a String. The second is the font style. The Font class has build in static final variables to describe the font style, and these should be used. The third parameter sent is the font size, which is expressed as an int. Answer C is the only answer in this list that calls this Font constructor correctly. 5. A The drawstring method accepts 3 parameters. The first is a String of the text to be drawn. The last 2 parameters are the x and y values for the bottom left point where the String is to be drawn, which is described in answer A. 6. A,B,C The method repaint calls the method update and then the method paint. The method update clears all of the elements that were previously drawn off the background, and redraws the current components that are to be drawn. The mousepressed method is called each time the user clicks the mouse, and here this event is setting the values of the x and y coordinates of the top left point of where the rectangle is to be drawn. Then repaint is called, and the new rectangle is drawn. Therefore each time the mouse is clicked a new rectangle is drawn,

so answer A is correct. Answer B is correct since the default update method clears away everything, as is mentioned above. If it is overridden then the previous items will not be erased when repaint is called, and just the new one will be drawn with paint. Answer C is correct since we already said that each time the user clicks the method repaint is called, and repaint calls update, which clears the screen and then redraws all including the new component. 7. E The drawline method of the Graphics class accepts 4 int parameters. The first two describe the first point (x, y coordinates) of where to start drawing the line. The last two describe the ending point (x, y coordinates) of where to finish drawing the line. Answer E is the only correct answer here since we know that the color of the line will be green, since that is what is sent to the setcolor method of the current Graphics object. The line drawn is a diagonal line, so answers B, C and D are incorrect. 8. B This example contains a class that extends Applet, and the html code that calls the applet. The html code sends to the applet a parameter called SIZE that holds the value Israel2000. The init method of the applet declares a String variable called str with an initial text of Israel. On the next line the parameter size is received with the getparameter method of the applet class. The String argument of the getparameter method is case insensitive, so sending the lowercase size is fine even though the HTML code defines the parameter as SIZE. The text Israel2000 is received from the getparameter method,

and it is then turned to be all uppercase letters with the touppercase method of the String class. A new String object is then created holding the text ISRAEL2000 and a reference to this object is placed into the str variable of the applet. 9. A As was seen in the Question 8, the case of the letter in the String that is passed to the getparameter method is not relevant. 10. B The getparameter method returns a String object and not a boolean value, therefore if the parameter is not found or the value is empty the String returned will contain null. 11. A The jar file can contain images or other classes that the applet class uses. 12. A The CODE attribute of the Applet tag in the HTML file holds the class name of the applet. The class name written for the CODE attribute must contain letters that are exactly the same case as the letters in the actual class file name. 13. B The PARAM tag is used to pass custom parameters to the applet. The NAME attribute in the PARAM tag defines the name of the parameter, and this value in the NAME is not case sensitive. 14. A This statement is true. 15. A If the applet class file resides in another folder or on another machine than the HTML file that is calling it then the CODEBASE

attribute is used to define where the applet class file is located, which can be a URL. 16. A The graphics instance comes from the browser, and gets passed to the paint method where the various Graphics drawing methods can be used. 17. B The init() method is the first method called for an applet. After this the start() method of the applet is called. 18. A, B, C The reason that applets are seen as being secure is that they cannot access any files or programs on the computer that they are running on. They can only communicate with the computer that their applet class file arrived from. 19. B An applet can run on any browser that has a JVM installed onto it, not just on the Internet Explorer browser. 20. A A JVM can be installed for the Internet Explorer browser, enablisng it to view any applet written with Java 2. 21. B In this example there is an applet class called Zapplet, which has an instance variable called num of type int. When the applet is created its constructor is called first, and the num variable is set to hold a value of 9. Then the init(0 method automatically is called, and the num value is increased by 1 to make it 10. Soon later the paint method is called and the value in num is printed.

22. A, B, C, D, E, F All of these answers are valid ways to set the color of the graphics context to be red. 23. A An applet can also be used as an application if it has a main method set for it. 24. F Answer F is the only answer here that defines the Color green that can be used for the graphics context.