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

Size: px
Start display at page:

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

Transcription

1 Java Programming in Java Java Applets

2 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 to be embedded inside another application. Ref.: Sun Microsystems

3 CGI - Common Gateway Interface Internet Applications HTML Browser CGI Application Program Operating System Client Application WebServer

4 Java Applications and Applets Internet Java Applications Java Applet HTML Browser Application Server CGI Application Program Operating System Client Application WebServer

5 Java Applications and Applets Applet: Java application that runs within a WWW-browser. Java AWT: Abstract Windowing Toolkit Advantages: Defined surface exists (window, graphic environment, event handling) Disadvantages (security): no file access; no communication with other computers; programs cannot be executed; native code cannot be loaded.

6 AWT vs. Swing APIs Java AWT (Abstract Windowing Toolkit) Package: java.awt GUI functionality (graphical user interface) Component libraries: labels, buttons, textfields, etc. (platform dependent) Helper classes: event handling, layout managers (window layouts), etc. The Swing APIs Package: javax.swing Greater platform independence - portable "look and feel" (buttons, etc.) AWT and Swing are part of the JFC (Java Foundation Classes) Easy upgrading using "J": Applet JApplet Button JButton

7 Viewing Applets Viewing Applets: a. using a (Java enabled) Browser: load HTML-file (*.html) that will call the applet-file (*.class) from local directory. b. Using the appletviewer (part of the java development kit): appletviewer name.html batch file: appletviewer %1.html

8 Classes, Packages Classes for Applet Programming java.awt.graphics java.awt.image java.awt.font java.awt.color java.awt.event java.net.url Importing Packages / Subpackages import java.awt.color; import java.awt.*; import java.awt.graphics; import java.awt.font;

9 Classes, Packages java.lang.object java.awt.component java.awt.container java.awt.panel java.applet.applet Component Container Panel Applet

10 Class JApplet java.lang.object java.awt.component java.awt.container java.awt.panel java.applet.applet javax.swing.japplet Class JApplet: An extended version of java.applet.applet that adds support for the JFC/Swing component architecture. Component Container Panel Applet JApplet

11 Classes, Packages Syntax: public class Name extends java.applet.applet {... } imported package class

12 Methods Java Applets Methods that are automatically called (implicit call) void init() void start() void paint(graphics g) void repaint() void stop() void destroy() Initialization: Set up colors, fonts, etc. when first loaded start the applet when loading HTML page (e.g. start animation) paint screen: display text, graphics repaint screen: call paint() for update stop the applet cleanup (before exiting)

13 Hello World Applet Example Source Program "Hello World" import java.awt.graphics; public class HelloWorldApp extends java.applet.applet { } public void paint (Graphics g) { g.drawstring("hello World!", 40, 20); } stored in: HelloWorldApp.java compiled with: javac HelloWorldApp.java

14 AWT The java.awt.graphics class Coordinate System: origin x y Unit: pixel

15 Hello World Applet Example Source Program "Hello World" <HTML> <HEAD> <TITLE>Hallo World Applet</TITLE> </HEAD> <BODY> <APPLET CODE= "HelloWorldApp.class" WIDTH = "210" HEIGHT = "50"> </APPLET> </BODY> </HTML>

16 Hello World Applet Object Tag: HTML 4 introduces the OBJECT element, which offers an all-purpose solution to generic object inclusion. The new OBJECT element thus subsumes some of the tasks carried out by existing elements: Type of inclusion Image Applet Another HTML document Specific element IMG APPLET (deprecated) IFRAME Generic element OBJECT OBJECT OBJECT The chart indicates that each type of inclusion has a specific and a general solution. The generic OBJECT element will serve as the solution for implementing future media types. <object codetype="application/java" classid="java:applet.class" width="200" height="250"> </object>

17 Hello World Applet Example import java.awt.graphics; import java.awt.font; import java.awt.color; public class HelloWorldApp2 extends java.applet.applet { String str = "Hello World 2"; int w = 300; int h = 80; Font f = new Font ("Arial", Font.BOLD + Font.ITALIC, 48); public void init() { resize(w,h); } } public void paint (Graphics g) { g.setfont(f); g.drawrect(0,0,w-1,h-1); g.setcolor(color.red); g.drawstring(str, 10, 50); } continued

18 Hello World Applet Example <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " <html xmlns=" <head> <title>hallo World Applet</title> </head> <body> <applet code= "HelloWorldApp2.class" width="350" height = "100"> </applet> </body> </html> Object

19 Hello World Applet Example using Swing import javax.swing.*; import java.awt.*; public class JHWApplet extends JApplet { String msg; } public void init() { msg = "Hello J-World"; } public void paint(graphics g) { g.drawstring(msg, 20, 30); }

20 Methods Further Methods boolean isactive() String getappletinfo() void showstatus(string msg) public String getparameter(string name) URL getcodebase() Image getimage(url url) AudioClip getaudioclip(url url) void play(url url) Determines if this applet is active. Returns information about this applet. Requests that the argument string be displayed in the "status window (bar)". Returns the value of the named parameter in the HTML tag. Gets the base URL. Returns an Image object that can then be painted on the screen. Returns the AudioClip object specified by the URL argument. Plays the audio clip at the specified absolute URL. Ref.: Sun Microsystems

21 Hello World Applet using Parameters Transfering Parameters from HTML to Applet <applet code <param name... </applet> = filename or URL> = "name" value = "value"> Check for Null Reference:... if (name == null)...

22 Applet using Parameters import java.awt.graphics; import java.awt.font; import java.awt.color; public class HelloWorldApp3 extends java.applet.applet { String text, fontsize; Font f; int w = 300; int h = 80; int thefontsize; public void init() { resize(w,h); this.text = getparameter("text"); if(this.text == null) this.text = "Hello World - Error!"; this.fontsize = getparameter("fontsize"); if (this.fontsize == null) this.thefontsize = 18; else this.thefontsize = Integer.parseInt(fontSize); } continued

23 Applet using Parameters } public void paint (Graphics g) { Font f = new Font("Arial", Font.BOLD + Font.ITALIC, this.thefontsize); g.setfont(f); g.drawrect(0,0,w-1,h-1); g.setcolor(color.red); g.drawstring(text, 10, 50); } continued

24 Applet using Parameters <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " <html xmlns=" <head> <title>hallo World Applet</title> </head> <body> <applet code= "HelloWorldApp3.class" width="600" height = "100"> <param name="text" value="hello World, Version 3" /> <param name="fontsize" value="48" /> </applet> </body> </html> With parameters Without parameters continued

25 Applet using Parameters with Parameter without Parameter

26 AWT Documentation Method drawline(int,int,int,int) drawrect(int,int,int,int) fillrect(int,int,int,int) drawroundrect(6*int) draw3drect(4*int, boolean) drawpolygon(int[],int[],int) drawoval(int,int,int,int) drawarc(6*int) fillarc(6*int) clearrect(int,int,int,int) copyarea(6*int) Description x/y-start to x/y-end x/y-upper left to lower right filled rectangle last 2 int for rounding 3D Rect. with shadow (y/n) x,y-coordinates, number Oval (including circle) Arc filled Arc rect. in background color x/y-translation

27 AWT - Example: Curve Plotting import java.awt.*; public class CurveApp extends java.applet.applet { int f(double x) { return (int) ((Math.cos(x/5) + Math.sin(x/7) + 2) * 50); } } public void paint (Graphics g) { for (int x = 0; x < 400; x++) g.drawline(x,f(x),x+1,f(x+1)); } continued

28 AWT - Example: Curve Plotting <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" " <html xmlns=" <head> <title>hallo World Applet</title> </head> <body> <applet code= "CurveApp.class" width="600" height = "200"> </applet> </body> </html>

29 Color Class: java.awt.color Standard colors are class variables RGB-Color: RED, GREEN, BLUE (16.7 million colors) Create New Colors: (Integer) Color name = new Color (int red, int green, int blue) (Float) Color name = new Color (float red, float green, float blue)

30 Color The class Color provides a series of static Color-objects that can be used directly: public static Color white public static Color lightgray public static Color gray public static Color darkgray public static Color black public static Color red public static Color blue public static Color green public static Color yellow public static Color magenta public static Color cyan public static Color orange public static Color pink Methods to determine the RGB-values of a color-object: public int getred() public int getgreen() public int getblue()

31 Color Methods Methods setcolor(color) setbackground (Color) setforeground (Color) Description Set the current color Set the background color Set the foreground color setcolor (new Color(1.0f, 0.0f, 0.0f)); Color c = new Color (0,255,0); setbackground (c); // RGB green setbackground(color.green); // Standard color green

32 Graphics g (lamp demo) import java.awt.*; public class Lamp extends java.applet.applet { public void init() { resize(300,300); } public void paint(graphics g) { // the moon g.drawarc (20,20,100,100,90,180); g.drawarc (40,20,60,100,90,180); // the table g.setcolor (Color.orange); g.filloval (0,220,300,100); g.setcolor (Color.black); continued

33 Graphics g (lamp demo) } // lamp cable g.drawrect (148,0,5,89); // upper arc of lamp g.drawarc (85,87,130,50,62,58); // two lines of the lamp g.drawline (215,177,181,90); g.drawline (85,177,119,90); // the lower oval g.setcolor (Color.yellow); g.filloval (85,157,130,50); // lamp pattern g.setcolor (Color.red); g.filloval (120,100,20,20); g.copyarea (120,100,20,20,40,-7); g.copyarea (120,100,20,20,30,30); g.copyarea (120,100,20,20,-15,35); g.copyarea (120,100,20,20,60,40); }

34 System Colors public final class SystemColor: A class to encapsulate symbolic colors representing the color of native GUI objects on a system. For systems which support the dynamic update of the system colors (when the user changes the colors) the actual RGB values of these symbolic colors will also change dynamically. In order to compare the "current" RGB value of a SystemColor object with a non-symbolic Color object, getrgb should be used rather than equals. Examples: SystemColor.desktop SystemColor.window SystemColor.control SystemColor.controlText SystemColor.scrollbar The color rendered for the background of the desktop. The color rendered for the background of interior regions inside windows. The color rendered for the background of control panels and control objects, such as pushbuttons. The color rendered for the text of control panels and control objects, such as pushbuttons. The color rendered for the background of scrollbars.

35 AWT Structure Types of classes and interfaces in package AWT Graphics Components (Windows, Menus) Layout Manager Event Handler Image Manipulation

36 AWT Structure java.awt.component partial listings Component Container Button Canvas Checkbox Label Window Panel ScrollPane java.awt Graphics Color Font Font Image FontMetrics CLASS extends ABSTRACT CLASS implements INTERFACE

37 Fonts Class: java.awt.font Font types: Courier; TimesRoman; Helvetica, Arial, etc. Font Styles: Font.PLAIN // = 0 Font.BOLD // = 1 Font.ITALIC // = 2 Size: in pixel

38 Fonts Font styles are constants that can be added: Example: Font.BOLD + Font.ITALIC // bold italic Creating Fonts, Examples: Font f = new Font("TimesRoman", Font.BOLD, 48) Method f.* getname() getsize() getstyle() isplain() isbold() isitalic() Description Return name of font as string Return current font size (int) Return current styles (0-3) Returns true if plain Returns true if bold Returns true if italic

39 Fonts Examples: Font f = new Font("TimesRoman", Font.PLAIN, 72); g.setfont(f); g.drawstring("this is size 72",10,100); Method g.* drawstring() setcolor() setfont() getfont() Description Draw a string Set color to be used Set font to be used Return current font object

40 FontMetrics FontMetrics (abstract class) Quality of text and font Method fm.* stringwidth(str) charwidth(c) getascent() getdescent() getleading() getheight() Description Return width of string str Width of char c Return the ascent of the font Return the descent of the font Returns the leading of the font Returns the total height of font 2D Text Tutorial

41 FontMetrics import java.awt.*; public class Center extends java.applet.applet { public void paint (Graphics g) { Font f = new Font ("TimesRoman", Font.PLAIN, 24); FontMetrics fm; g.setfont(f); fm = getfontmetrics(f); String str = "This text will be centered"; int x = (this.size().width - fm.stringwidth(str)) / 2; int y = (this.size().height - fm.getheight()) / 2; } } g.drawstring(str,x,y);

42 FontMetrics Demo import java.awt.*; import java.applet.*; public class DrawText extends Applet { public void paint (Graphics g) { // output strings byte byte_text[] = {'H','E','L','L','O'}; char char_text[] = {'h','e','l','l','o'}; String String_text = "\u00c4g"; // fonts Font Arial24 = new Font ("Arial", Font.PLAIN,24); Font Tmsrm72 = new Font ("TimesRoman", Font.PLAIN,72); // font metrics FontMetrics fm; int ascent, descent; int string_width; int char_width; int leading; continued

43 FontMetrics Demo // simple output methods g.drawbytes (byte_text,0,5,20,20); g.drawchars (char_text,0,5,20,40); g.drawstring ("A complete string",20,60); g.drawstring (Arial24.toString(),20,80); // selecting a font g.setfont (Arial24); g.drawstring ("Now using Arial 24",20,120); // translate origin g.translate (100,250); // select a large font g.setfont(tmsrm72); continued

44 FontMetrics Demo // font metrics fm = getfontmetrics (Tmsrm72); string_width = fm.stringwidth (String_text); char_width = fm.charwidth ('\u00c4'); ascent = fm.getascent (); descent = fm.getdescent (); leading = fm.getleading (); // draw vertical lines g.drawline (0, - ascent -10, 0, descent + 10); g.drawline (char_width, -ascent, char_width, descent + 10); g.drawline (string_width, - ascent -10, string_width, descent +10); } // draw horzontal lines g.drawline (-10, 0, string_width + 10, 0); g.drawline (-10, -ascent, string_width +10, -ascent); g.drawline (-10, descent, string_width + 10, descent); g.drawline (-10, descent + leading, string_width + 10, descent + leading); } continued

45 FontMetrics Demo

46 Applet Demo Karnaugh-Veitch Diagramm

47 Model-View-Controller MVC: Model-View-Controller-Architecture: Methodology / design pattern widely used in objectoriented programming. Relates the the user interface (UI) to the underlying data models. Used in program development with Java, Smalltalk, C, and C++.

48 Model-View-Controller The MVC pattern proposes three main components or objects to be used in software development: A Model: represents the underlying, logical structure of data in a software application and the high-level class associated with it. Does not contain information about the user interface. A View: collection of classes representing the elements in the user interface (visual display, possible user responses - buttons, display boxes, etc.) A Controller: represents the classes connecting the model and the view.

49 Model-View-Controller View Model Controller

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

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

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

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

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

Dr. Hikmat A. M. AbdelJaber

Dr. Hikmat A. M. AbdelJaber Dr. Hikmat A. M. AbdelJaber Portion of the Java class hierarchy that include basic graphics classes and Java 2D API classes and interfaces. java.lang.object Java.awt.Color Java.awt.Component Java.awt.Container

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

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

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

OBJECT ORIENTED PROGRAMMING. Course 8 Loredana STANCIU Room B613

OBJECT ORIENTED PROGRAMMING. Course 8 Loredana STANCIU Room B613 OBJECT ORIENTED PROGRAMMING Course 8 Loredana STANCIU loredana.stanciu@upt.ro Room B613 Applets A program written in the Java programming language that can be included in an HTML page A special kind of

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

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

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

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

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

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 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

CSD Univ. of Crete Fall Java Applets

CSD Univ. of Crete Fall Java Applets Java Applets 1 Applets An applet is a Panel that allows interaction with a Java program Typically embedded in a Web page and can be run from a browser You need special HTML in the Web page to tell the

More information

Java History. Java History (cont'd)

Java History. Java History (cont'd) Java History Created by James Gosling et. al. at Sun Microsystems in 1991 "The Green Team" Investigate "convergence" technologies Gosling created a processor-independent language for StarSeven, a 2-way

More information

Java Programming Lecture 6

Java Programming Lecture 6 Java Programming Lecture 6 Alice E. Fischer Feb 15, 2013 Java Programming - L6... 1/32 Dialog Boxes Class Derivation The First Swing Programs: Snow and Moving The Second Swing Program: Smile Swing Components

More information

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

Java How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved. Java How to Program, 9/e Copyright 1992-2012 by Pearson Education, Inc. All Rights Reserved. Overview capabilities for drawing two-dimensional shapes, controlling colors and controlling fonts. One of

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

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

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

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

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

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

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

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

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

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

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

Graphics in Swing. Engineering 5895 Faculty of Engineering & Applied Science Memorial University of Newfoundland Graphics in Swing Engineering 5895 Faculty of Engineering & Applied Science Memorial University of Newfoundland 1 paintcomponent and repaint Each Swing component has the following paint methods: void paintcomponent(

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

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

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

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

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

AWT COLOR CLASS. Introduction. Class declaration. Field

AWT COLOR CLASS. Introduction. Class declaration. Field http://www.tutorialspoint.com/awt/awt_color.htm AWT COLOR CLASS Copyright tutorialspoint.com Introduction The Color class states colors in the default srgb color space or colors in arbitrary color spaces

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

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

Introduction to Graphical Interface Programming in Java. Introduction to AWT and Swing

Introduction to Graphical Interface Programming in Java. Introduction to AWT and Swing Introduction to Graphical Interface Programming in Java Introduction to AWT and Swing GUI versus Graphics Programming Graphical User Interface (GUI) Graphics Programming Purpose is to display info and

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

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

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

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

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

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

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

Goals. Java - An Introduction. Java is Compiled and Interpreted. Architecture Neutral & Portable. Compiled Languages. Introduction to Java

Goals. Java - An Introduction. Java is Compiled and Interpreted. Architecture Neutral & Portable. Compiled Languages. Introduction to Java Goals Understand the basics of Java. Introduction to Java Write simple Java Programs. 1 2 Java - An Introduction Java is Compiled and Interpreted Java - The programming language from Sun Microsystems Programmer

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

Data Representation and Applets

Data Representation and Applets Data Representation and Applets CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Overview Binary representation Data types revisited

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

Introduction to Computer Science I

Introduction to Computer Science I Introduction to Computer Science I Graphics Janyl Jumadinova 7 February, 2018 Graphics Graphics can be simple or complex, but they are just data like a text document or sound. Java is pretty good at graphics,

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

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

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

The AWT Package, An Overview

The AWT Package, An Overview Richard G Baldwin (512) 223-4758, baldwin@austin.cc.tx.us, http://www2.austin.cc.tx.us/baldwin/ The AWT Package, An Overview Java Programming, Lecture Notes # 110, Revised 02/21/98. Preface Introduction

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

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

Data Representation and Applets

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

More information

Methods (Deitel chapter 6)

Methods (Deitel chapter 6) Methods (Deitel chapter 6) 1 Plan 2 Introduction Program Modules in Java Math-Class Methods Method Declarations Argument Promotion Java API Packages Random-Number Generation Scope of Declarations Methods

More information

Methods (Deitel chapter 6)

Methods (Deitel chapter 6) 1 Plan 2 Methods (Deitel chapter ) Introduction Program Modules in Java Math-Class Methods Method Declarations Argument Promotion Java API Packages Random-Number Generation Scope of Declarations Methods

More information

Data Representation and Applets

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

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

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

Part 3: Graphical User Interface (GUI) & Java Applets

Part 3: Graphical User Interface (GUI) & Java Applets 1,QWURGXFWLRQWR-DYD3URJUDPPLQJ (( Part 3: Graphical User Interface (GUI) & Java Applets EE905-GUI 7RSLFV Creating a Window Panels Event Handling Swing GUI Components ƒ Layout Management ƒ Text Field ƒ

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

Building Java Programs

Building Java Programs Building Java Programs Graphics Reading: Supplement 3G Objects (briefly) object: An entity that contains data and behavior. data: variables inside the object behavior: methods inside the object You interact

More information

1.00 Lecture 14. Lecture Preview

1.00 Lecture 14. Lecture Preview 1.00 Lecture 14 Introduction to the Swing Toolkit Lecture Preview Over the next 5 lectures, we will introduce you to the techniques necessary to build graphic user interfaces for your applications. Lecture

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

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

Java Applets This is not a Java course! (You re supposed to know about Java.) IT 3203 Introduction to Web Development Java and the Web IA and the Enterprise November 26 28 Study Abroad Spend July in Madrid Informational meeting: Wednesday, November 28 3:00 pm in Room J-308 http://spsumadrid08.blogspot.com/

More information

Graphic User Interfaces. - GUI concepts - Swing - AWT

Graphic User Interfaces. - GUI concepts - Swing - AWT Graphic User Interfaces - GUI concepts - Swing - AWT 1 What is GUI Graphic User Interfaces are used in programs to communicate more efficiently with computer users MacOS MS Windows X Windows etc 2 Considerations

More information

SNS COLLEGE OF ENGINEERING, Coimbatore

SNS COLLEGE OF ENGINEERING, Coimbatore SNS COLLEGE OF ENGINEERING, Coimbatore 641 107 Accredited by NAAC UGC with A Grade Approved by AICTE and Affiliated to Anna University, Chennai IT6503 WEB PROGRAMMING UNIT 04 APPLETS Java applets- Life

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

PROGRAMMING LANGUAGE 2

PROGRAMMING LANGUAGE 2 1 PROGRAMMING LANGUAGE 2 Lecture 13. Java Applets Outline 2 Applet Fundamentals Applet class Applet Fundamentals 3 Applets are small applications that are accessed on an Internet server, transported over

More information

Graphical User Interface (GUI)

Graphical User Interface (GUI) Graphical User Interface (GUI) An example of Inheritance and Sub-Typing 1 Java GUI Portability Problem Java loves the idea that your code produces the same results on any machine The underlying hardware

More information

CIS 162 Project 1 Business Card Section 04 (Kurmas)

CIS 162 Project 1 Business Card Section 04 (Kurmas) CIS 162 Project 1 Business Card Section 04 (Kurmas) Due Date at the start of lab on Monday, 17 September (be prepared to demo in lab) Before Starting the Project Read zybook chapter 1 and 3 Know how to

More information

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

CS 201 Advanced Object-Oriented Programming Lab 1 - Improving Your Image Due: Feb. 3/4, 11:30 PM CS 201 Advanced Object-Oriented Programming Lab 1 - Improving Your Image Due: Feb. 3/4, 11:30 PM Objectives The objectives of this assignment are: to refresh your Java programming to become familiar with

More information

DEMYSTIFYING PROGRAMMING: CHAPTER TEN REPETITION WITH WHILE-LOOP (TOC DETAILED)

DEMYSTIFYING PROGRAMMING: CHAPTER TEN REPETITION WITH WHILE-LOOP (TOC DETAILED) DEMYSTIFYING PROGRAMMING: CHAPTER TEN REPETITION WITH WHILE-LOOP (TOC DETAILED) Chapter Ten: Classes Revisited, Repetition with while... 1 Objectives... 1 10.1 Design... 1 Repetition process pseudocode...

More information

Class 14: Introduction to the Swing Toolkit

Class 14: Introduction to the Swing Toolkit Introduction to Computation and Problem Solving Class 14: Introduction to the Swing Toolkit Prof. Steven R. Lerman and Dr. V. Judson Harward 1 Class Preview Over the next 5 lectures, we will introduce

More information

CS 106A, Lecture 11 Graphics

CS 106A, Lecture 11 Graphics CS 106A, Lecture 11 Graphics reading: Art & Science of Java, 9.1-9.3 This document is copyright (C) Stanford Computer Science and Marty Stepp, licensed under Creative Commons Attribution 2.5 License. All

More information

Agenda. Programming Seminar. By: dr. Amal Khalifa. Coordinate systems Colors Fonts Drawing shapes Graphics2D API

Agenda. Programming Seminar. By: dr. Amal Khalifa. Coordinate systems Colors Fonts Drawing shapes Graphics2D API Agenda Coordinate systems Colors Fonts Drawing shapes Graphics2D API By: dr. Amal Khalifa 1 Programming Seminar @12:30 13:30 pm on Wednesday 9/4/2014 Location : 2.505.01 Painting components 2 Every component

More information

Chapter 12 GUI Basics

Chapter 12 GUI Basics Chapter 12 GUI Basics 1 Creating GUI Objects // Create a button with text OK JButton jbtok = new JButton("OK"); // Create a label with text "Enter your name: " JLabel jlblname = new JLabel("Enter your

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

Graphical User Interface (GUI)

Graphical User Interface (GUI) Graphical User Interface (GUI) An example of Inheritance and Sub-Typing 1 Java GUI Portability Problem Java loves the idea that your code produces the same results on any machine The underlying hardware

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

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

Introduction to Java

Introduction to Java Introduction to Java Module 1: Getting started, Java Basics 22/01/2010 Prepared by Chris Panayiotou for EPL 233 1 Lab Objectives o Objective: Learn how to write, compile and execute HelloWorld.java Learn

More information

CHAPTER 2. Java Overview

CHAPTER 2. Java Overview Networks and Internet Programming (0907522) CHAPTER 2 Java Overview Instructor: Dr. Khalid A. Darabkh Objectives The objectives of this chapter are: To discuss the classes present in the java.awt package

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

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

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

IS311 Programming Concepts. Abstract Window Toolkit (part 1: Drawing Simple Graphics)

IS311 Programming Concepts. Abstract Window Toolkit (part 1: Drawing Simple Graphics) 1 IS311 Programming Concepts Abstract Window Toolkit (part 1: Drawing Simple Graphics) 2 Abstract Window Toolkit The Abstract Window Toolkit (AWT) package contains all the classes for creating user interfaces

More information

Java. GUI building with the AWT

Java. GUI building with the AWT Java GUI building with the AWT AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many applications Uses the controls defined by your OS therefore

More information

Assignment 2. Application Development

Assignment 2. Application Development Application Development Assignment 2 Content Application Development Day 2 Lecture The lecture covers the key language elements of the Java programming language. You are introduced to numerical data and

More information

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 5: Will be an open-ended Swing project. "Programming Contest"

More information

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun! Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Why are we studying Swing? 1. Useful & fun! 2. Good application of OOP techniques

More information

Applets as front-ends to server-side programming

Applets as front-ends to server-side programming Applets as front-ends to server-side programming Objectives Introduce applets Examples of Java graphical programming How-to put an applet in a HTML page The HTML Applet tag and alternatives Applet communication

More information