OBJECT ORIENTED PROGRAMMING. Course 8 Loredana STANCIU Room B613

Size: px
Start display at page:

Download "OBJECT ORIENTED PROGRAMMING. Course 8 Loredana STANCIU Room B613"

Transcription

1 OBJECT ORIENTED PROGRAMMING Course 8 Loredana STANCIU loredana.stanciu@upt.ro Room B613

2 Applets A program written in the Java programming language that can be included in an HTML page A special kind of Java program that a browser enabled with Java technology can download from the internet and run Embedded inside a web page and runs in the context of a browser Extends the java.applet.applet class

3 Defining an applet import java.awt.*; import java.applet.*; { } public class MyApplet extends Applet public void paint (Graphics g){ } g.drawstring("hello World", 20, 20);

4 Methods for milestones Milestones are major events in an applet's life cycle init method: useful for one-time initialization that doesn't take very long contains the code that you would normally put into a constructor Keep the method short so that your applet can load quickly

5 Methods for milestones start method: starts the execution of an applet every applet that performs tasks after initialization must override this method It is good practice to return quickly from the start method stop method: should suspend the applet's execution, so that it doesn't take up system resources when the user isn't viewing the applet's page most applets that override the start should also override the stop method

6 Methods for milestones destroy method: available for applets that need to release additional resources many applets don't need to override the destroy method keep implementations of the destroy method as short as possible

7 Example import java.applet.applet; import java.awt.graphics; public class Simple extends Applet { StringBuffer buffer; public void init() { buffer = new StringBuffer(); additem("initializing... ");} public void start() { additem("starting... ");}

8 Example public void stop() { additem("stopping... ");} public void destroy() { additem("preparing for unloading...");} private void additem(string newword) { System.out.println(newWord); buffer.append(newword); repaint();}

9 Example public void paint(graphics g) { g.drawrect(0, 0, getwidth() - 1, getheight() - 1); } } g.drawstring(buffer.tostring(), 5, 15);

10 Life Cycle of an Applet An applet can react to major events in the following ways: It can initialize itself. It can start running. It can stop running. It can perform a final cleanup, in preparation for being unloaded.

11 Life Cycle of an Applet Loading an applet: An instance of the applet's controlling class (an Applet subclass) is created. The applet initializes itself. The applet starts running. Leaving and Returning to the Applet's Page: When leaving the page, the browser stops and destroys the applet. When returning to the page, the browser initializes and starts a new instance of the applet.

12 Life Cycle of an Applet Reloading an applet: The current instance of the applet is stopped and destroyed and a new instance is created. Quitting the browser: The applet has the opportunity to stop itself and perform a final cleanup before the browser exits.

13 Life Cycle of an Applet init(): intended for whatever initialization is needed for the applet start(): automatically called after init() and whenever user returns to the page containing the applet after visiting other pages stop(): automatically called whenever the user moves away from the page containing applets or to stop an animation destroy(): called when the browser shuts down normally.

14 Applet s execution environment An applet runs in the context of a browser The Java Plug-in software controls the launch and execution of applets JavaScript interpreter runs the JavaScript code on a web page Java Plug-in: creates a worker thread for every applet launches an applet in an instance of the Java Runtime Environment (JRE) software

15 Applet s execution environment

16 Loading Applets in a Web Page <applet code=appletworld.class width="200" height="200"> </applet> appletviewer AppletWorld.html when making changes to the applet's code while it is loaded in the browser, then recompile the applet and press the "Shift + Reload" button in the browser to load the new version

17 Converting Applications to Applets An application: a standalone program consisting of at least one class with a main method. Applets do not have a main method several methods are called at different points in the execution of an applet The difference between Java applets and applications lies in how they are run

18 Converting Applications to Applets Create a subclass of java.applet.applet and override the init method to initialize the applet's resources the same way the main method initializes the application's resources. init might be called more than once and should be designed accordingly. The top-level Panel needs to be added to the applet in init; usually it was added to a Frame in main.

19 Using the Paint Method Used to draw the applet's representation within a browser page public void paint(graphics g) { /*Draw a Rectangle around the applet's display area.*/ g.drawrect(0, 0, getwidth() - 1, getheight() - 1); /*Draw the current string inside the rectangle.*/ g.drawstring(buffer.tostring(), 5, 15); }

20 The Graphic class Is the abstract base class for all graphics contexts that allow an application to draw onto components that are realized on various devices A Graphics object encapsulates state information needed for the basic rendering operations that Java supports

21 The Graphic class This state information includes the following properties: The Component object on which to draw. A translation origin for rendering and clipping coordinates. The current clip. The current color. The current font. The current logical pixel operation function (XOR or Paint). The current XOR alternation color

22 The Graphic class All coordinates that appear as arguments to the methods of a Graphics object are considered relative to the translation origin of this Graphics object prior to the invocation of the method.

23 The Graphic class public void translate(int x, int y) Translates the origin of the graphics context to the point (x, y) in the current coordinate system public Color getcolor() Gets this graphics context's current color. public void setcolor(color c) Sets this graphics context's current color to the specified color. All subsequent graphics operations using this graphics context use this specified color.

24 The Graphic class public Font getfont() Gets the current font. public void setfont(font font) Sets this graphics context's font to the specified font. All subsequent text operations using this graphics context use this font. Public void drawline(int x1, int y1, int x2, int y2) Draws a line, using the current color, between the points (x1, y1) and (x2, y2) in this graphics context's coordinate system.

25 The Graphic class public void drawrect(int x, int y, int width, int height) Draws the outline of the specified rectangle. The rectangle is drawn using the graphics context's current color. public void clearrect(int x, int y, int width, int height) Clears the specified rectangle by filling it with the background color of the current drawing surface. This operation does not use the current paint mode.

26 The Graphic class public abstract void drawoval(int x, int y, int width, int height) Draws the outline of an oval. The result is a circle or ellipse that fits within the rectangle specified by the x, y, width, and height arguments. public abstract void drawarc(int x, int y, int width, int height, int startangle, int arcangle) Draws the outline of a circular or elliptical arc covering the specified rectangle. Angles are interpreted such that 0 degrees is at the 3 o'clock position

27 The Graphic class public void drawstring(string str, int x, int y) Draws the text given by the specified string, using this graphics context's current font and color. The baseline of the leftmost character is at position (x, y) in this graphics context's coordinate system. public abstract void drawpolygon (int[] xpoints, int[] ypoints, int npoints) Draws a closed polygon defined by arrays of x and y coordinates. Each pair of (x, y) coordinates defines a point.

28 The Color class Used encapsulate colors in the default s RGB color space Predefined values for colors: BLACK, BLUE, CYAN, DARK GREY, GREY, GREEN, LIGHT GREY, MAGENTA, ORANGE, PINK, RED, WHITE, YELLOW,

29 The Applet class Must be the superclass of any applet that is to be embedded in a Web page or viewed by the Java Applet Viewer Provides a standard interface between applets and their environment. More on /java/applet/applet.html

30 The Applet tag <APPLET CODEBASE = codebaseurl ARCHIVE = archivelist CODE = appletfile...or... OBJECT = serializedapplet ALT = alternatetext NAME = appletinstancename WIDTH = pixels HEIGHT = pixels ALIGN = alignment VSPACE = pixels HSPACE = pixels > <PARAM NAME = appletattribute1 VALUE = value> <PARAM NAME = appletattribute2 VALUE = value>... alternatehtml </APPLET>

31 The Applet tag CODEBASE = codebaseurl OPTIONAL attribute specifies the base URL of the applet the directory that contains the applet's code. If this attribute is not specified, then the document's URL is used. ARCHIVE = archivelist OPTIONAL attribute describes one or more archives containing classes and other resources that will be "preloaded". The classes are loaded using an instance of an AppletClassLoader with the given CODEBASE.

32 The Applet tag CODE = appletfile REQUIRED attribute gives the name of the file that contains the applet's compiled Applet subclass. This file is relative to the base URL of the applet. The value appletfile can be of the form classname.class or of the form packagename.classname.class. ALT = alternatetext OPTIONAL attribute specifies any text that should be displayed if the browser understands the APPLET tag but can't run Java applets.

33 The Applet tag NAME = appletinstancename OPTIONAL attribute specifies a name for the applet instance, which makes it possible for applets on the same page to find (and communicate with) each other. WIDTH = pixels HEIGHT = pixels REQUIRED attributes give the initial width and height (in pixels) of the applet display area, not counting any windows or dialogs that the applet brings up.

34 The Applet tag ALIGN = alignment OPTIONAL attribute specifies the alignment of the applet. The possible values of this attribute are: left, right, top, texttop, middle, absmiddle, baseline, bottom, absbottom. VSPACE = pixels HSPACE = pixels OPTIONAL attributes specify the number of pixels above and below the applet (VSPACE) and on each side of the applet (HSPACE). <PARAM NAME = appletattribute1 VALUE = value> The only way to specify an applet-specific attribute. Applets access their attributes with the getparameter() method.

35 Example Drawing lines import java.applet.*; import java.awt.*; public class DrawingLines extends Applet { int width, height; public void init() { width = getsize().width; height = getsize().height; setbackground( Color.black ); } public void paint( Graphics g ) { g.setcolor( Color.green ); for ( int i = 0; i < 10; ++i ) { g.drawline( width, height, i * width / 10, 0 ); } } }

36 Example Drawing lines <applet width=300 height=300 code="drawinglines.class"> </applet>

37 Example Drawing Other Stuff import java.applet.*; import java.awt.*; public class DrawingLines extends Applet { int width, height; public void init() { width = getsize().width; height = getsize().height; setbackground( Color.black ); } public void paint( Graphics g ) { g.setcolor( Color.red ); g.drawrect( 10, 20, 100, 15 ); g.setcolor( Color.pink ); g.fillrect( 240, 160, 40, 110 );

38 Example Drawing Other Stuff g.setcolor( Color.blue ); g.drawoval( 50, 225, 100, 50 ); g.setcolor( Color.orange ); g.filloval( 225, 37, 50, 25 ); g.setcolor( Color.yellow ); g.drawarc( 10, 110, 80, 80, 90, 180 ); g.setcolor( Color.cyan ); g.fillarc( 140, 40, 120, 120, 90, 45 );

39 Example Drawing Other Stuff g.setcolor( Color.magenta ); g.fillarc( 150, 150, 100, 100, 90, 90 ); g.setcolor( Color.black ); g.fillarc( 160, 160, 80, 80, 90, 90 ); g.setcolor( Color.green ); g.drawstring( "Groovy!", 50, 150 ); } }

40 Example Drawing Other Stuff The output:

41 Example Mouse Input import java.applet.*; import java.awt.*; import java.awt.event.*; import java.util.*; public class Mouse3 extends Applet implements MouseListener, MouseMotionListener { int width, height; int mx, my; public void init() { width = getsize().width; height = getsize().height; setbackground( Color.black ); mx = width/2; my = height/2; addmouselistener(this); addmousemotionlistener( this ); }

42 Example Mouse Input public void mouseentered( MouseEvent e ) { // the pointer enters the applet's rectangular area } public void mouseexited( MouseEvent e ) { // the pointer leaves the applet's rectangular area } public void mouseclicked( MouseEvent e ) { // a press and release of a mouse button with no motion in between}

43 Example Mouse Input public void mousepressed( MouseEvent e ){ // called after a button is pressed down isbuttonpressed = true; setbackground( Color.gray ); repaint(); e.consume(); } public void mousereleased( MouseEvent e ) { // a button is released isbuttonpressed = false; setbackground( Color.black ); repaint(); e.consume(); }

44 Example Mouse Input public void mousemoved( MouseEvent e ) { // during motion when no buttons are down mx = e.getx(); my = e.gety(); showstatus( "Mouse at (" + mx + "," + my + ")" ); repaint(); e.consume(); } public void mousedragged( MouseEvent e ) { // during motion with buttons down mx = e.getx(); my = e.gety(); showstatus( "Mouse at (" + mx + "," + my + ")" ); repaint(); e.consume(); }

45 Example Mouse Input public void paint( Graphics g ) { if ( isbuttonpressed ) { g.setcolor( Color.black ); } else { g.setcolor( Color.gray ); } g.fillrect( mx-20, my-20, 40, 40 ); } }

46 Example Keyboard Input import java.applet.*; import java.awt.*; import java.awt.event.*; public class Keyboard1 extends Applet implements KeyListener, MouseListener { int width, height; int x, y; String s = ""; public void init() { width = getsize().width; height = getsize().height; setbackground( Color.black ); x = width/2; y = height/2; addkeylistener( this ); addmouselistener( this ); }

47 Example Keyboard Input public void keypressed( KeyEvent e ) { } public void keyreleased( KeyEvent e ) { } public void keytyped( KeyEvent e ) { char c = e.getkeychar(); if ( c!= KeyEvent.CHAR_UNDEFINED ) { s = s + c; repaint(); e.consume(); } } public void mouseentered( MouseEvent e ) { } public void mouseexited( MouseEvent e ) { } public void mousepressed( MouseEvent e ) { } public void mousereleased( MouseEvent e ) { }

48 Example Keyboard Input public void mouseclicked( MouseEvent e ) { x = e.getx(); y = e.gety(); s = ""; repaint(); e.consume(); } public void paint( Graphics g ) { g.setcolor( Color.gray ); g.drawline( x, y, x, y-10 ); g.drawline( x, y, x+10, y ); g.setcolor( Color.green ); g.drawstring( s, x, y ); } }

49 References rial/deployment/applet/index.html uff/learn/java/

Graphics Applets. By Mr. Dave Clausen

Graphics Applets. By Mr. Dave Clausen Graphics Applets By Mr. Dave Clausen Applets A Java application is a stand-alone program with a main method (like the ones we've seen so far) A Java applet is a program that is intended to transported

More information

PESIT Bangalore South Campus

PESIT Bangalore South Campus INTERNAL ASSESSMENT TEST II Date : 20-09-2016 Max Marks: 50 Subject & Code: JAVA & J2EE (10IS752) Section : A & B Name of faculty: Sreenath M V Time : 8.30-10.00 AM Note: Answer all five questions 1) a)

More information

CSC System Development with Java Introduction to Java Applets Budditha Hettige

CSC System Development with Java Introduction to Java Applets Budditha Hettige CSC 308 2.0 System Development with Java Introduction to Java Applets Budditha Hettige Department of Statistics and Computer Science What is an applet? applet: a Java program that can be inserted into

More information

Java Applet Basics. Life cycle of an applet:

Java Applet Basics. Life cycle of an applet: Java Applet Basics Applet is a Java program that can be embedded into a web page. It runs inside the web browser and works at client side. Applet is embedded in a HTML page using the APPLET or OBJECT tag

More information

SIMPLE APPLET PROGRAM

SIMPLE APPLET PROGRAM APPLETS Applets are small applications that are accessed on Internet Server, transported over Internet, automatically installed and run as a part of web- browser Applet Basics : - All applets are subclasses

More information

Graphics Applets. By Mr. Dave Clausen

Graphics Applets. By Mr. Dave Clausen Graphics Applets By Mr. Dave Clausen Applets A Java application is a stand-alone program with a main method (like the ones we've seen so far) A Java applet is a program that is intended to transported

More information

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

Module 5 Applets About Applets Hierarchy of Applet Life Cycle of an Applet About Applets Module 5 Applets An applet is a little application. Prior to the World Wide Web, the built-in writing and drawing programs that came with Windows were sometimes called "applets." On the Web,

More information

CSIS 10A Assignment 14 SOLUTIONS

CSIS 10A Assignment 14 SOLUTIONS CSIS 10A Assignment 14 SOLUTIONS Read: Chapter 14 Choose and complete any 10 points from the problems below, which are all included in the download file on the website. Use BlueJ to complete the assignment,

More information

Programmierpraktikum

Programmierpraktikum Programmierpraktikum Claudius Gros, SS2012 Institut für theoretische Physik Goethe-University Frankfurt a.m. 1 of 18 17/01/13 11:46 Java Applets 2 of 18 17/01/13 11:46 Java applets embedding Java applications

More information

9. APPLETS AND APPLICATIONS

9. APPLETS AND APPLICATIONS 9. APPLETS AND APPLICATIONS JAVA PROGRAMMING(2350703) The Applet class What is an Applet? An applet is a Java program that embedded with web content(html) and runs in a Web browser. It runs inside the

More information

Introduction to Java Applets 12

Introduction to Java Applets 12 Introduction to Java Applets 12 Course Map This module discusses the support for applets by the JDK, and how applets differ from applications in terms of program form, operating context, and how they are

More information

TWO-DIMENSIONAL FIGURES

TWO-DIMENSIONAL FIGURES TWO-DIMENSIONAL FIGURES Two-dimensional (D) figures can be rendered by a graphics context. Here are the Graphics methods for drawing draw common figures: java.awt.graphics Methods to Draw Lines, Rectangles

More information

public static void main(string[] args) { GTest mywindow = new GTest(); // Title This program creates the following window and makes it visible:

public static void main(string[] args) { GTest mywindow = new GTest(); // Title This program creates the following window and makes it visible: Basics of Drawing Lines, Shapes, Reading Images To draw some simple graphics, we first need to create a window. The easiest way to do this in the current version of Java is to create a JFrame object which

More information

AP CS Unit 12: Drawing and Mouse Events

AP CS Unit 12: Drawing and Mouse Events AP CS Unit 12: Drawing and Mouse Events A JPanel object can be used as a container for other objects. It can also be used as an object that we can draw on. The first example demonstrates how to do that.

More information

Appendix F: Java Graphics

Appendix F: Java Graphics Appendix F: Java Graphics CS 121 Department of Computer Science College of Engineering Boise State University August 21, 2017 Appendix F: Java Graphics CS 121 1 / 15 Topics Graphics and Images Coordinate

More information

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

Unit 1- Java Applets. Applet Programming. Local Applet and Remote Applet ** Applet and Application Applet Programming Applets are small Java applications that can be accessed on an Internet server, transported over Internet, and can be automatically installed and run as a part of a web document. An

More information

Appendix F: Java Graphics

Appendix F: Java Graphics Appendix F: Java Graphics CS 121 Department of Computer Science College of Engineering Boise State University August 21, 2017 Appendix F: Java Graphics CS 121 1 / 1 Topics Graphics and Images Coordinate

More information

Advanced Internet Programming CSY3020

Advanced Internet Programming CSY3020 Advanced Internet Programming CSY3020 Java Applets The three Java Applet examples produce a very rudimentary drawing applet. An Applet is compiled Java which is normally run within a browser. Java applets

More information

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

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 CBOP3203 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 page. When you use a Java technology-enabled

More information

G51PRG: Introduction to Programming Second semester Applets and graphics

G51PRG: Introduction to Programming Second semester Applets and graphics G51PRG: Introduction to Programming Second semester Applets and graphics Natasha Alechina School of Computer Science & IT nza@cs.nott.ac.uk Previous two lectures AWT and Swing Creating components and putting

More information

Unit 7: Event driven programming

Unit 7: Event driven programming Faculty of Computer Science Programming Language 2 Object oriented design using JAVA Dr. Ayman Ezzat Email: ayman@fcih.net Web: www.fcih.net/ayman Unit 7: Event driven programming 1 1. Introduction 2.

More information

Java TM Applets. Rex Jaeschke

Java TM Applets. Rex Jaeschke Java TM Applets Rex Jaeschke Java Applets 1997 1998, 2009 Rex Jaeschke. All rights reserved. Edition: 3.0 (matches JDK1.6/Java 2) All rights reserved. No part of this publication may be reproduced, stored

More information

cs Java: lecture #5

cs Java: lecture #5 cs3101-003 Java: lecture #5 news: homework #4 due today homework #5 out today today s topics: applets, networks, html graphics, drawing, handling images graphical user interfaces (GUIs) event handling

More information

UNIT -1 JAVA APPLETS

UNIT -1 JAVA APPLETS UNIT -1 JAVA APPLETS TOPICS TO BE COVERED 1.1 Concept of Applet Programming Local and Remote applets Difference between applet and application Preparing to write applets Building applet code Applet life

More information

Chapter 7 Applets. Answers

Chapter 7 Applets. Answers 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

More information

NITI NITI I PRIORITET

NITI NITI I PRIORITET NITI public class ThreadsTest { public static void main(string args[]) { BytePrinter bp1 = new BytePrinter(); BytePrinter bp2 = new BytePrinter(); BytePrinter bp3 = new BytePrinter(); bp1.start(); bp2.start();

More information

@Override public void start(stage primarystage) throws Exception { Group root = new Group(); Scene scene = new Scene(root);

@Override public void start(stage primarystage) throws Exception { Group root = new Group(); Scene scene = new Scene(root); Intro to Drawing Graphics To draw some simple graphics, we first need to create a window. The easiest way to do this in the current version of Java is to create a JavaFX application. Previous versions

More information

public void mouseexited (MouseEvent e) setminute(getminute()+increment); 11.2 public void mouseclicked (MouseEvent e) int x = e.getx(), y = e.gety();

public void mouseexited (MouseEvent e) setminute(getminute()+increment); 11.2 public void mouseclicked (MouseEvent e) int x = e.getx(), y = e.gety(); 11 The Jav aawt Part I: Mouse Events 11.1 public void mouseentered (MouseEvent e) setminute(getminute()+increment); 53 public void mouseexited (MouseEvent e) setminute(getminute()+increment); 11.2 public

More information

An applet is called from within an HTML script with the APPLET tag, such as: <applet code="test.class" width=200 height=300></applet>

An applet is called from within an HTML script with the APPLET tag, such as: <applet code=test.class width=200 height=300></applet> 6 Java Applets 6.1 Introduction As has been previously discussed a Java program can either be run as an applet within a WWW browser (such as Microsoft Internet Explorer or Netscape Communicator) or can

More information

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

Road Map. Introduction to Java Applets Review applets that ship with JDK Make our own simple applets Java Applets Road Map Introduction to Java Applets Review applets that ship with JDK Make our own simple applets Introduce inheritance Introduce the applet environment html needed for applets Reading:

More information

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

UNIT-2: CLASSES, INHERITANCE, EXCEPTIONS, APPLETS. To define a class, use the class keyword and the name of the class: UNIT-2: CLASSES, INHERITANCE, EXCEPTIONS, APPLETS 1. Defining Classes, Class Name To define a class, use the class keyword and the name of the class: class MyClassName {... If this class is a subclass

More information

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

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 9: Writing Java Applets. Introduction INTRODUCTION TO COMPUTER PROGRAMMING Richard Pierse Class 9: Writing Java Applets Introduction Applets are Java programs that execute within HTML pages. There are three stages to creating a working Java

More information

Object Oriented Programming Concepts-15CS45

Object Oriented Programming Concepts-15CS45 Module 05 Chethan Raj C Assistant Professor Dept. of CSE APPLET: 1. Introduction 2. Two types of Applets 3. Applet basics 4. Applet Architecture 5. An Applet skeleton 6. Simple Applet display methods 7.

More information

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

Programming: You will have 6 files all need to be located in the dir. named PA4: PROGRAMMING ASSIGNMENT 4: Read Savitch: Chapter 7 and class notes Programming: You will have 6 files all need to be located in the dir. named PA4: PA4.java ShapeP4.java PointP4.java CircleP4.java RectangleP4.java

More information

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

Contents 8-1. Copyright (c) N. Afshartous Contents 1. Classes and Objects 2. Inheritance 3. Interfaces 4. Exceptions and Error Handling 5. Intro to Concurrency 6. Concurrency in Java 7. Graphics and Animation 8. Applets 8-1 Chapter 8: Applets

More information

11/7/12. Discussion of Roulette Assignment. Objectives. Compiler s Names of Classes. GUI Review. Window Events

11/7/12. Discussion of Roulette Assignment. Objectives. Compiler s Names of Classes. GUI Review. Window Events Objectives Event Handling Animation Discussion of Roulette Assignment How easy/difficult to refactor for extensibility? Was it easier to add to your refactored code? Ø What would your refactored classes

More information

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Graphics & Applets CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/ Back to Chapter

More information

Applet which displays a simulated trackball in the upper half of its window.

Applet which displays a simulated trackball in the upper half of its window. Example: Applet which displays a simulated trackball in the upper half of its window. By dragging the trackball using the mouse, you change its state, given by its x-y position relative to the window boundaries,

More information

Chapter 14: Applets and More

Chapter 14: Applets and More Chapter 14: Applets and More Starting Out with Java: From Control Structures through Objects Fifth Edition by Tony Gaddis Chapter Topics Chapter 14 discusses the following main topics: Introduction to

More information

8/23/2014. Chapter Topics. Introduction to Applets. Introduction to Applets. Introduction to Applets. Applet Limitations. Chapter 14: Applets and More

8/23/2014. Chapter Topics. Introduction to Applets. Introduction to Applets. Introduction to Applets. Applet Limitations. Chapter 14: Applets and More Chapter 14: Applets and More Starting Out with Java: From Control Structures through Objects Fifth Edition by Tony Gaddis Chapter Topics Chapter 14 discusses the following main topics: Introduction to

More information

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

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani Module 5 The Applet Class, Swings OOC 4 th Sem, B Div 2016-17 Prof. Mouna M. Naravani The HTML APPLET Tag An applet viewer will execute each APPLET tag that it finds in a separate window, while web browsers

More information

Using the API: Introductory Graphics Java Programming 1 Lesson 8

Using the API: Introductory Graphics Java Programming 1 Lesson 8 Using the API: Introductory Graphics Java Programming 1 Lesson 8 Using Java Provided Classes In this lesson we'll focus on using the Graphics class and its capabilities. This will serve two purposes: first

More information

Chapter 14: Applets and More

Chapter 14: Applets and More Chapter 14: Applets and More Starting Out with Java: From Control Structures through Objects Fourth Edition by Tony Gaddis Addison Wesley is an imprint of 2010 Pearson Addison-Wesley. All rights reserved.

More information

Event Driven Programming

Event Driven Programming Event Driven Programming 1. Objectives... 2 2. Definitions... 2 3. Event-Driven Style of Programming... 2 4. Event Polling Model... 3 5. Java's Event Delegation Model... 5 6. How to Implement an Event

More information

AP Computer Science Unit 13. Still More Graphics and Animation.

AP Computer Science Unit 13. Still More Graphics and Animation. AP Computer Science Unit 13. Still More Graphics and Animation. In this unit you ll learn about the following: Mouse Motion Listener Suggestions for designing better graphical programs Simple game with

More information

Graphics -- To be discussed

Graphics -- To be discussed Graphics -- To be discussed 1 Canvas Class... 1 2 Graphics Class... 1 3 Painting... 1 4 Color Models... 4 5 Animation's Worst Enemy: Flicker... 4 6 Working with Java Images... 5 6.1 Image Loading Chain

More information

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

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani Module 5 The Applet Class, Swings OOC 4 th Sem, B Div 2017-18 Prof. Mouna M. Naravani The Applet Class Types of Applets (Abstract Window Toolkit) Offers richer and easy to use interface than AWT. An Applet

More information

Here is a list of a few of the components located in the AWT and Swing packages:

Here is a list of a few of the components located in the AWT and Swing packages: Inheritance Inheritance is the capability of a class to use the properties and methods of another class while adding its own functionality. Programming In A Graphical Environment Java is specifically designed

More information

Java Coordinate System

Java Coordinate System Java Graphics Drawing shapes in Java such as lines, rectangles, 3-D rectangles, a bar chart, or a clock utilize the Graphics class Drawing Strings Drawing Lines Drawing Rectangles Drawing Ovals Drawing

More information

Exam: Applet, Graphics, Events: Mouse, Key, and Focus

Exam: Applet, Graphics, Events: Mouse, Key, and Focus Exam: Applet, Graphics, Events: Mouse, Key, and Focus Name Period A. Vocabulary: Complete the Answer(s) Column. Avoid ambiguous terms such as class, object, component, and container. Term(s) Question(s)

More information

Using Graphics. Building Java Programs Supplement 3G

Using Graphics. Building Java Programs Supplement 3G Using Graphics Building Java Programs Supplement 3G Introduction So far, you have learned how to: output to the console break classes/programs into static methods store and use data with variables write

More information

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

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 CSCI 053 Introduction to Software Development Rhys Price Jones Week 5 Java is like Alice not based on Joel Adams you may want to take notes Objectives Learn to use the Eclipse IDE Integrated Development

More information

User interfaces and Swing

User interfaces and Swing User interfaces and Swing Overview, applets, drawing, action listening, layout managers. APIs: java.awt.*, javax.swing.*, classes names start with a J. Java Lectures 1 2 Applets public class Simple extends

More information

GUI 4.1 GUI GUI MouseTest.java import javax.swing.*; import java.awt.*; import java.awt.event.*; /* 1 */

GUI 4.1 GUI GUI MouseTest.java import javax.swing.*; import java.awt.*; import java.awt.event.*; /* 1 */ 25 4 GUI GUI GUI 4.1 4.1.1 MouseTest.java /* 1 */ public class MouseTest extends JApplet implements MouseListener /* 2 */ { int x=50, y=20; addmouselistener(this); /* 3 */ super.paint(g); /* 4 */ g.drawstring("hello

More information

Method Of Key Event Key Listener must implement three methods, keypressed(), keyreleased() & keytyped(). 1) keypressed() : will run whenever a key is

Method Of Key Event Key Listener must implement three methods, keypressed(), keyreleased() & keytyped(). 1) keypressed() : will run whenever a key is INDEX Event Handling. Key Event. Methods Of Key Event. Example Of Key Event. Mouse Event. Method Of Mouse Event. Mouse Motion Listener. Example of Mouse Event. Event Handling One of the key concept in

More information

Windows and Events. created originally by Brian Bailey

Windows and Events. created originally by Brian Bailey Windows and Events created originally by Brian Bailey Announcements Review next time Midterm next Friday UI Architecture Applications UI Builders and Runtimes Frameworks Toolkits Windowing System Operating

More information

Building Java Programs

Building Java Programs Building Java Programs Supplement 3G: Graphics 1 drawing 2D graphics Chapter outline DrawingPanel and Graphics objects drawing and filling shapes coordinate system colors drawing with loops drawing with

More information

Building Java Programs

Building Java Programs Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2 Objects (briefly) object: An entity that contains data and behavior. data: variables inside the object behavior: methods inside

More information

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

Framework. Set of cooperating classes/interfaces. Example: Swing package is framework for problem domain of GUI programming Frameworks 1 Framework Set of cooperating classes/interfaces Structure essential mechanisms of a problem domain Programmer can extend framework classes, creating new functionality Example: Swing package

More information

Computer Science II - Test 2

Computer Science II - Test 2 Computer Science II - Test 2 Question 1. (15 points) The MouseListener interface requires methods for mouseclicked, mouseentered, mouseexited, mousepressed, and mousereleased. Java s MouseAdapter implements

More information

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

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani Module 5 The Applet Class, Swings OOC 4 th Sem, B Div 2016-17 Prof. Mouna M. Naravani The Applet Class Types of Applets (Abstract Window Toolkit) Offers richer and easy to use interface than AWT. An Applet

More information

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

Java Mouse Actions. C&G criteria: 5.2.1, 5.4.1, 5.4.2, Java Mouse Actions C&G criteria: 5.2.1, 5.4.1, 5.4.2, 5.6.2. The events so far have depended on creating Objects and detecting when they receive the event. The position of the mouse on the screen can also

More information

Java Applet & its life Cycle. By Iqtidar Ali

Java Applet & its life Cycle. By Iqtidar Ali Java Applet & its life Cycle By Iqtidar Ali Java Applet Basic An applet is a java program that runs in a Web browser. An applet can be said as a fully functional java application. When browsing the Web,

More information

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

CS 201 Advanced Object-Oriented Programming Lab 10 - Recursion Due: April 21/22, 11:30 PM CS 201 Advanced Object-Oriented Programming Lab 10 - Recursion Due: April 21/22, 11:30 PM Introduction to the Assignment In this assignment, you will get practice with recursion. There are three parts

More information

(listener)... MouseListener, ActionLister. (adapter)... MouseAdapter, ActionAdapter. java.awt AWT Abstract Window Toolkit GUI

(listener)... MouseListener, ActionLister. (adapter)... MouseAdapter, ActionAdapter. java.awt AWT Abstract Window Toolkit GUI 51 6!! GUI(Graphical User Interface) java.awt javax.swing (component) GUI... (container) (listener)... MouseListener, ActionLister (adapter)... MouseAdapter, ActionAdapter 6.1 GUI(Graphics User Interface

More information

HTML Links Tutorials http://www.htmlcodetutorial.com/ http://www.w3.org/markup/guide/ Quick Reference http://werbach.com/barebones/barebones.html Applets A Java application is a stand-alone program with

More information

Java Applets / Flash

Java Applets / Flash Java Applets / Flash Java Applet vs. Flash political problems with Microsoft highly portable more difficult development not a problem less so excellent visual development tool Applet / Flash good for:

More information

Graphics and Java2D. Objectives

Graphics and Java2D. Objectives jhtp5_12.fm Page 569 Sunday, November 24, 2002 11:59 AM 12 Graphics and Java2D Objectives To understand graphics contexts and graphics objects. To understand and be able to manipulate colors. To understand

More information

Java - Applets. public class Buttons extends Applet implements ActionListener

Java - Applets. public class Buttons extends Applet implements ActionListener Java - Applets Java code here will not use swing but will support the 1.1 event model. Legacy code from the 1.0 event model will not be used. This code sets up a button to be pushed: import java.applet.*;

More information

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics Topic 9: Swing Outline Swing = Java's GUI library Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 7: Expand moving shapes from Assignment 4 into game. "Programming

More information

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

Graphics. Lecture 18 COP 3252 Summer June 6, 2017 Graphics Lecture 18 COP 3252 Summer 2017 June 6, 2017 Graphics classes In the original version of Java, graphics components were in the AWT library (Abstract Windows Toolkit) Was okay for developing simple

More information

Some classes and interfaces used in this chapter from Java s original graphics capabilities and from the Java2D API.

Some classes and interfaces used in this chapter from Java s original graphics capabilities and from the Java2D API. CHAPTER 11 513 11 java.lang.object java.awt.color java.awt.component Key class interface java.awt.font java.awt.fontmetrics java.awt.graphics java.awt.polygon Classes and interfaces from the Java2D API

More information

CT 229 Arrays in Java

CT 229 Arrays in Java CT 229 Arrays in Java 27/10/2006 CT229 Next Weeks Lecture Cancelled Lectures on Friday 3 rd of Nov Cancelled Lab and Tutorials go ahead as normal Lectures will resume on Friday the 10 th of Nov 27/10/2006

More information

Graphics and Painting

Graphics and Painting Graphics and Painting Lecture 17 CGS 3416 Fall 2015 November 30, 2015 paint() methods Lightweight Swing components that extend class JComponent have a method called paintcomponent, with this prototype:

More information

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 - 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 - 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, 5.3.2. Java is not confined to a DOS environment. It can run with buttons and boxes in a Windows

More information

Building Java Programs

Building Java Programs Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2 Objects (briefly) object: An entity that contains data and behavior. data: Variables inside the object. behavior: Methods inside

More information

Topic 8 Graphics. Margaret Hamilton

Topic 8 Graphics. Margaret Hamilton Topic 8 Graphics When the computer crashed during the execution of your program, there was no hiding. Lights would be flashing, bells would be ringing and everyone would come running to find out whose

More information

Advanced Java Unit 6: Review of Graphics and Events

Advanced Java Unit 6: Review of Graphics and Events Advanced Java Unit 6: Review of Graphics and Events This is a review of the basics of writing a java program that has a graphical interface. To keep things simple, all of the graphics programs will follow

More information

Mobile Systeme Grundlagen und Anwendungen standortbezogener Dienste. Location Based Services in the Context of Web 2.0

Mobile Systeme Grundlagen und Anwendungen standortbezogener Dienste. Location Based Services in the Context of Web 2.0 Mobile Systeme Grundlagen und Anwendungen standortbezogener Dienste Location Based Services in the Context of Web 2.0 Department of Informatics - MIN Faculty - University of Hamburg Lecture Summer Term

More information

Command-Line Applications. GUI Libraries GUI-related classes are defined primarily in the java.awt and the javax.swing packages.

Command-Line Applications. GUI Libraries GUI-related classes are defined primarily in the java.awt and the javax.swing packages. 1 CS257 Computer Science I Kevin Sahr, PhD Lecture 14: Graphical User Interfaces Command-Line Applications 2 The programs we've explored thus far have been text-based applications A Java application is

More information

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011 GUI DYNAMICS Lecture July 26 CS2110 Summer 2011 GUI Statics and GUI Dynamics 2 Statics: what s drawn on the screen Components buttons, labels, lists, sliders, menus,... Containers: components that contain

More information

Programming graphics

Programming graphics Programming graphics Need a window javax.swing.jframe Several essential steps to use (necessary plumbing ): Set the size width and height in pixels Set a title (optional), and a close operation Make it

More information

CS2110. GUIS: Listening to Events

CS2110. GUIS: Listening to Events CS2110. GUIS: Listening to Events Also anonymous classes Download the demo zip file from course website and look at the demos of GUI things: sliders, scroll bars, combobox listener, etc 1 mainbox boardbox

More information

Which of the following syntax used to attach an input stream to console?

Which of the following syntax used to attach an input stream to console? Which of the following syntax used to attach an input stream to console? FileReader fr = new FileReader( input.txt ); FileReader fr = new FileReader(FileDescriptor.in); FileReader fr = new FileReader(FileDescriptor);

More information

Java Applets. Last Time. Java Applets. Java Applets. First Java Applet. Java Applets. v We created our first Java application

Java Applets. Last Time. Java Applets. Java Applets. First Java Applet. Java Applets. v We created our first Java application Last Time v We created our first Java application v What are the components of a basic Java application? v What GUI component did we use in the examples? v How do we write to the standard output? v An

More information

Lab 10: Inheritance (I)

Lab 10: Inheritance (I) CS2370.03 Java Programming Spring 2005 Dr. Zhizhang Shen Background Lab 10: Inheritance (I) In this lab, we will try to understand the concept of inheritance, and its relation to polymorphism, better;

More information

China Jiliang University Java. Programming in Java. Java Applets. Java Web Applications, Helmut Dispert

China Jiliang University Java. Programming in Java. Java Applets. Java Web Applications, Helmut Dispert Java Programming in Java Java Applets Java Applets applet = app = application snippet = (German: Anwendungsschnipsel) An applet is a small program that is intended not to be run on its own, but rather

More information

Chapter 3 - Introduction to Java Applets

Chapter 3 - Introduction to Java Applets 1 Chapter 3 - Introduction to Java Applets 2 Introduction Applet Program that runs in appletviewer (test utility for applets) Web browser (IE, Communicator) Executes when HTML (Hypertext Markup Language)

More information

The init() Method. Browser Calling Applet Methods

The init() Method. Browser Calling Applet Methods Chapter 12 Applets and Advanced GUI The Applet Class The HTML Tag Passing Parameters to Applets Conversions Between Applications and Applets Running a Program as an Applet and as an Application

More information

Topic 8 graphics. -mgrimes, Graphics problem report 134

Topic 8 graphics. -mgrimes, Graphics problem report 134 Topic 8 graphics "What makes the situation worse is that the highest level CS course I've ever taken is cs4, and quotes from the graphics group startup readme like 'these paths are abstracted as being

More information

Lecture 7 A First Graphic Program And Data Structures & Drawing

Lecture 7 A First Graphic Program And Data Structures & Drawing Lecture 7 A First Graphic Program And Data Structures & Drawing Objective The objective is that you will understand: How to program the generation of 2D and 3D images. How to manipulate those images through

More information

Garfield AP CS. Graphics

Garfield AP CS. Graphics Garfield AP CS Graphics Assignment 3 Working in pairs Conditions: I set pairs, you have to show me a design before you code You have until tomorrow morning to tell me if you want to work alone Cumulative

More information

Applets and the Graphics class

Applets and the Graphics class Applets and the Graphics class CSC 2014 Java Bootcamp Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Some slides in this presentation are adapted from the slides accompanying

More information

1 Getting started with Processing

1 Getting started with Processing cisc3665, fall 2011, lab I.1 / prof sklar. 1 Getting started with Processing Processing is a sketch programming tool designed for use by non-technical people (e.g., artists, designers, musicians). For

More information

Chapter 3: Inheritance and Polymorphism

Chapter 3: Inheritance and Polymorphism Chapter 3: Inheritance and Polymorphism Overview Inheritance is when a child class, or a subclass, inherits, or gets, all the data (properties) and methods from the parent class, or superclass. Just like

More information

CISC 1600, Lab 2.2: Interactivity in Processing

CISC 1600, Lab 2.2: Interactivity in Processing CISC 1600, Lab 2.2: Interactivity in Processing Prof Michael Mandel 1 Getting set up For this lab, we will again be using Sketchpad, a site for building processing sketches online using processing.js.

More information

Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how to paint graphics on GUI components

Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how to paint graphics on GUI components CS112-Section2 Hakan Guldas Burcin Ozcan Meltem Kaya Muge Celiktas Notes of 6-8 May Graphics Previously, we have seen GUI components, their relationships, containers, layout managers. Now we will see how

More information

G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY

G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY G.PULLAIAH COLLEGE OF ENGINEERING AND TECHNOLOGY Kurnool 518002 DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Lecture notes of OBJECT ORIENTED PROGRAMMING USING THROUGH JAVA Prepared by: P. Rama Rao,

More information

Graphics and Java 2D Introduction OBJECTIVES. One picture is worth ten thousand words.

Graphics and Java 2D Introduction OBJECTIVES. One picture is worth ten thousand words. 1 2 12 Graphics and Java 2D One picture is worth ten thousand words. Chinese proverb Treat nature in terms of the cylinder, the sphere, the cone, all in perspective. Paul Cézanne Colors, like features,

More information