Mathematics for Computer Graphics - Lecture 13

Size: px
Start display at page:

Download "Mathematics for Computer Graphics - Lecture 13"

Transcription

1 Mathematics for Computer Graphics - Lecture 13 Dr. Philippe B. Laval Kennesaw State University October 10, 2003 Abstract This document is about creating Java Applets as they relate to the project we are developing in class. 1 Java2D As we have mentioned many times, our goal is to develop a java applet which will represent 3D objects on a 2D screen. Though the Java language does a lot of this for us, we will develop almost everything ourselves. We will only use a few of the methods Java provides. These methods are included in the Graphics or Graphics2D package. This package comes with the Java distribution, so nothing extra has to be installed. See the section entitled "Drawing" below, to see the list of the methods we will borrow from Java to do our job. To explain how one can draw in an applet, I have written java code for the skeleton of an applet. This applet uses some of the components you are most likely to use in your assignment. The applet is not entirely done. It just contains the code which draws the various components on the applet. As an assignment, you will have to finish coding the applet. Let us now go through the code of the applet and explain it, line by line. As you read this document, you should follow the code with line numbers for the applet which is available on my site. This applet is called AppletSample, it written using the AWT toolkit. The applets we talked about in the previous lecture were written using Swing. This way, you will have been exposed to both technologies. 1.1 Basics of a Java Applet (AWT) All AWT applets are subclasses of the class Applet. Java applets are not executed like a standard application. Instead, they must run inside a java enabled browser. Each applet must be accompanied by an html file which will be used to launch the applet. It defines an area on a web page, then puts various components the user will interact with. A Java applet is event driven. This means 1

2 that after the applet has been drawn, it waits for the user to interact with it. As the user interacts with the applet, events are triggered. The code of the applet handles the events as they are being triggered. When writing an applet, one must know the following: 1. What components can be drawn on an applet, how are they drawn? 2. What are the events each component can trigger? 3. How are these events caught? How are they handled? To better understand how an applet functions and how to write one, it helps to think of a java applet as having two states. 1. The initial state, how the applet appears when it starts. 2. The working state, what the applet becomes as the user is working with it. Each applet must contain at least two methods, which correspond to the two states: 1. public void init() This method is executed automatically when the applet starts. It is executed only once during the life of the applet. It is the method which draws the applet in its initial state. In this method, you should put all the code which has to be executed before the applet is used. It should contain the following: (a) Code to set up the various components which go in the applet. If youlookattheinitmethodofappletsample, this is what it does. (b) Anything which must be done before the applet starts. This includes initializing variables. 2. public void paint(graphics g) The argument passed with this method is called a "Graphics context". It is needed to use any of the routines provided by the Graphics or Graphics2D packages. We will talk more about this below, in the section called "Drawing". This method should contain the code which changes the applet after its initial state. 1.2 HTML file to launch an applet. Thecodetolaunchanappletisverysimple.Thecodebelowistheentirehtml file used to launch the AppletSample applet. 2

3 <HTML> <HEAD> <TITLE>Sample Applet HTML</TITLE> </HEAD> <BODY> <APPLET CODE="AppletSample.class" WIDTH=605 HEIGHT=450></APPLET> </BODY> </HTML> Most of this code is actually part of every html file. The only line which launches the applet is the line containing the tag "APPLET CODE" The name of the applet must be specified, as well as the size of the area on the web page the applet will use. 1.3 Components of a Java Applet (AWT) This section will not list all the possible components. Neither will it list everything there is to know about each component. Only the most used components are listed, so you will know they are available. The code in AppletSample will show you how to set most of them up, and how to work with them. The idea is that once you know they exist, if you want to use them, come ask me. I ll explain you how to use them. Going over each component in details is done in a CS class, not a math class Button This class creates a labeled button. The application can cause some action to happen when the button is pushed. When a button is pressed and released, AWT sends an instance of Action- Event to the button, by calling processevent on the button. The button s processevent method receives all events for the button; it passes an action event along by calling its own processactionevent method. The latter method passes the action event on to any action listeners that have registered an interest in action events generated by this button. If an application wants to perform some action based on a button being pressed and released, it should implement ActionListener and register the new listener to receive events from this button, by calling the button s addactionlistener method. The application can make use of the button s action command as a messaging protocol. The applet AppletSample contains a button. Line 194 declares the button, it is called buttonreset. Lines define the button. They tell the applet how to draw it. Buttons respond to an actionperformed event. Such an event is declared on line 172. Line 173 registers the event listener with the button. Lines contain the code for the event listener. You should not change 3

4 it. Lines contain the code for the event handler. This is where you put your code which will perform the action you want to perform when the button is pressed Check Box A check box is a graphical component that can be in either an "on" (true) or "off" (false) state. Clicking on a check box changes its state from "on" to "off," or from "off" to "on." The applet AppletSample contains two check boxes. They are declared on lines 186 and 199. Lines and define the button. They tell the applet how to draw it. CheckBoxes respond to the ItemStateChanged event. Such an event is declared on line 159. Lines 160 and 161 registers the event listeners for this event with each checkbox. Lines define the code for the event listener. You should not change it. Lines contain the code for the event handler. This is where you put your code which will perform the action you wanttoperform whenthecheckboxisclicked on. The method public boolean getstate() can be used to see if the check box is checked or not. Ifit returns true, it is checked. Otherwise, it will return false. The method public void setstate(boolean state) sets the state of this check box Choice The Choice class presents a pop-up menu of choices. The current choice is displayed as the title of the menu. The applet AppletSample contains a choice list. Line 193 declares the choice list, it is called choicecolor. Lines define choicecolor. They tell theapplethow to draw it. Achoicelistresponds toanitemstatechanged event. Suchanevent is declared on line 159. Line 171 registers the event listener with the button. Lines contain the code for the event listener. You should not change it. Lines contain the code for the event handler. This is where you put your code which will perform the action you want to perform whenachoiceismade from that list. The method public int getselectedindex() returns the index of the selected item. Like arrays, the first item has index 0. The method public void select(int pos) sets the selected item at the given position Label A Label object is a component for placing text in a container. A label displays a single line of read-only text. The text can be changed by the application, but a user cannot edit it directly. The applet AppletSample contains several labels. Lines 182, 185, 188, 192, and 196 declares them. Toseehow one is drawn, look at lines

5 There is no interaction with this item Panel Panel is the simplest container class. A panel provides space in which an application can attach any other component, including other panels. The applet AppletSample contains three panels. They are declared on lines 180, 181, 184. To see how one is drawn, look at lines Panels can be configured to monitor events. The code would be similar to the code mentioned above for other components Scroll Bar The Scrollbar class embodies a scroll bar, a familiar user-interface object. A scroll bar provides a convenient means for allowingausertoselectfrom a range ofvalues. A scroll bars could be used as slider controls: Alternatively, a scroll bar can represent a range of values. For example, if a scroll bar is used for scrolling through text, the width of the "bubble" or "thumb" can represent the amount of text that is visible. Scrollbars can be vertical or horizontal. They are not used in the applet AppletSample. Ifyou decide touseone, either look at a java book, or come see me Text Area A TextArea object is a multi-line region that displays text. It can be set to allow editing or to be read-only. The applet AppletSample contains one text area, on the Messages panel. It isdeclared on line 183. Lines 68, 69 define it. They tell the applet how and where to draw it. This item in this applet does not respond to any messages. However, it could monitor events like the other components. If you want to enable such events, look in a java book, or come see me. The method public void append(string s) can be used to append text at the end of thetextalready in this component. The method public void insert(string s, int pos) canbeused to insert text at the specified position in this component. The method public String gettext() canbeused to get the text of this component. The method public void settext(string s) canbeused to set the text of this component. The are many more methods, see me if you feel you need them Text Field A TextField object is a text component that allows for the editing of asingle line of text. 5

6 The applet AppletSample contains several text fields. They are declared on lines 187, , 195, 197, 198 and 200. To see how one is drawn, look at lines 108, 109. Text areas can be set to monitor various events (see me for a complete list). The one you are likely to use is the focus event (loose or gain). Suchanevent is declared on line 162. Lines declare the listeners for this event for each component for which it is enabled. The code for the event listener can be found on lines You should not change this code. The handlers for this event, for each component for which it is enabled can be found on lines This is where you put your code tohandle this event. The method public String gettext() canbeused to get the text of this component. The method public void settext(string s) canbeused to set the text of this component. The are many more methods, see me if you feel you need them. 2 Drawing 2.1 More on the paint method Its format is public void paint(graphics g). This method is called each time the applet s output must be redrawn. This can occur for several reasons. The window where the applet is may have been hidden, then brought back to focus. The applet window may have been minimized, or resized. The applet may have been internally modified. The code in the applet may have drawn additional objects. Paint is also called every time the applet starts. There is a paint method for the applet as well as for every component on the applet. The paint method of a component only redraws the components it contains. For example, the paint method of the AppletSample applet only redraws whatitcontains, that is the three panels. When each panel is being redrawn, it, in turns, calls the paint method of each of the components it contains. And so on. Each component has its own paint method predefined. You do not need to worry about it. Each predefined component knows how to draw itself. The only we have changed is the paint method of the graph panel. This panel will be drawn by us. There is no way the applet would know how to redraw it. To redefine it, we had to override the paint method of the panel class. For this, we declared a new class, called mypanel (see line 180). This new class is defined on lines The keyword "extends" means that it is a copy of the class it extends, that is Panel. Only the methods we redefine in this new class will 6

7 override the methods of the same name in the Panel class. We could also, if we need to, add new methods. The only method we want to override is paint. This is what we did. In the paint method of this class, you should put the code which will draw the various objects in the panel. 2.2 Requesting Repainting As a general rule, an applet writes to its window only when its paint method is called. Even if you ask the applet to draw astringoraline, the line will not be drawn until paint is called. There are instances when the applet will know it has to redraw itself. For example, if it regains focus, the windowing system will send it a message telling it to redraw itself. The applet will then invoke its paint method. There are times when the applet will not know. For example, if the user has changed the coordinates of a corner of the a rectangle, the applet does not know that the corner is related to a rectangle. In such a case, the applet hastobetold to redraw itself. The simplest way to accomplish this is to use the repaint method. Its signature is public void repaint(). When this method is called, it will cause the whole applet to be redrawn. Each component also has a repaint method. When it is called, only that component will be redrawn. To call it, use the name of the component. For example, to call the repaint method of panelgraph, use panelgraph.repaint(). 2.3 Simple Drawing Methods The methods you will need to finish the AppletSample applet are: void drawstring(string s, int x, int y) Draws the string s starting at the specified location. How big the drawn object is depends onthetext, its font and the size of the font. There are also methods to find this information. void drawline(int x 1,inty 1,intx 2,inty 2 ) Draws a line between (x 1,y 1 ) and (x 2,y 2 ).These are coordinates in pixels. void drawrect(int x, int y, int width, int height). Drawsarectanglewhose upper left corner is (x, y) with the specifiedwidth and hieght. Color getcolor() returns the current color. void setcolor(color newcolor) sets the current color. There are several colors predefined in the Color class you can use. They include Color.black,Color.blue,Color.darkGray, Color.gray, Color.lightGray, Color.green, Color.orange, Color.red, Color.white, Color.yellow. Remark 1 The coordinates specified are always with respect to the component of the Graphics context. If we are in the paint method of the applet, then all 7

8 coordinates are with respect to the area of the applet. If we are in the paint method of the panelgraph, then the coordinates are with respect to this panel. This is another advantage of having overridden the paint method of panelgraph. (0, 0) corresponds to the upper left corner of that component. 3 Assignment Please, feel freetocomeseemeasoften as you need. I will help you with the code I am asking you to write. The goal of this assignment is for you to understand how a java appletisprogrammed. You are to do thefollowing: Complete the code for the applet discussed in class (you can download the skeleton from my site) so that the applet does the following: When the applet starts, besides drawing itself, it should also set all the field, choices and check boxes to default values. I will let you pick the default values. When the user clicks on the various components, write the code to make each component respond. For example, if the state of a check box changes, redraw the applet accordingly. If the color used to draw is changed, redraw the applet accordingly. If the value in one of the text fields is changed, redraw theappletaccordingly. When the user clicks on any of the components, have a description saying what the component does and how to use it in the message area. When the RESET button is pressed, all the fields should be reset to their default values. You will give methejava files, the html file and the class file. This is due on Wednesday October Resources Thisisalistof books and other resources I used to compile these notes. References [BG1] Burger, Peter, and Gillies, Duncan, Interactive Computer Graphics, Addison-Wesley, [DD1] Deitel, H.M., and Deitel, P. J., Java, How to Program, Prentice Hall, [DP1] Dunn, Fletcher and Parberry, Ian, 3D Math Primer for Graphics and Game Development, Wordware Publishing, Inc.,

9 [FD1] Foley, J.D., Van Dam, A., Feiner, S.K., and Hughes, J.F., Computer Graphics, Principles and Practices, Addison-Wesley, [FD2] Foley, J.D., Van Dam, A., Feiner, S.K., Hughes, J.F., and Philipps, R.L., Introduction to Computer Graphics, Addison-Wesley, [H1] Hill, F.S. JR., Computer Graphics Using Open GL, Prentice Hall, [LE1] Lengyel, Eric, Mathematics for 3D Game Programming & Computer Graphics, Charles River Media, Inc., [SH1] Schildt, Herbert, Java2, The Complete Reference, McGraw-Hill, 2001 [SE1] Schneider, Philip J., and Eberly, David H., Geometric Tools for Computer Graphics, Morgan Kaufman, [SP1] Shirley, Peter, Fundamentals of Computer Graphics, A KPeters, [SJ1] Stewart, James, Calculus, Concepts and Contexts, second edition, Brooks/Cole, [WG1] Wall, David, and Griffith, Arthur, Graphics Programming with JFC, Wiley, [AW1] Watt, Alan, 3D Computer Graphics, Addison-Wesley, [AW2] Watt, Alan, The Computer Image, Addison-Wesley,

Mathematics for Computer Graphics - Ray Tracing III

Mathematics for Computer Graphics - Ray Tracing III Mathematics for Computer Graphics - Ray Tracing III Dr. Philippe B. Laval Kennesaw State University November 12, 2003 Abstract This document is a continuation of the previous documents on ray tracing.

More information

Mathematics for Computer Graphics - Lecture 8

Mathematics for Computer Graphics - Lecture 8 Mathematics for Computer Graphics - Lecture 8 Dr. Philippe B. Laval Kennesaw State University September 22, 2003 Abstract This document is about our rst project: the creation of a 3D vector class. It gives

More information

Mathematics for Computer Graphics - Lecture 12

Mathematics for Computer Graphics - Lecture 12 Mathematics for Computer Graphics - Lecture 12 Dr. Philippe B. Laval Kennesaw State University October 6, 2003 Abstract This document is about creating Java Applets as they relate to the project we are

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

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

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

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

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

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

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

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

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

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

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

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

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

Starting Out with Java: From Control Structures Through Objects Sixth Edition

Starting Out with Java: From Control Structures Through Objects Sixth Edition Starting Out with Java: From Control Structures Through Objects Sixth Edition Chapter 12 A First Look at GUI Applications Chapter Topics 12.1 Introduction 12.2 Creating Windows 12.3 Equipping GUI Classes

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

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

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

In this lecture we will briefly examine a few new controls, introduce the concept of scope, random numbers, and drawing simple graphics.

In this lecture we will briefly examine a few new controls, introduce the concept of scope, random numbers, and drawing simple graphics. Additional Controls, Scope, Random Numbers, and Graphics CS109 In this lecture we will briefly examine a few new controls, introduce the concept of scope, random numbers, and drawing simple graphics. Combo

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

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

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

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

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

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

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

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

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

@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

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

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

UI Software Organization

UI Software Organization UI Software Organization The user interface From previous class: Generally want to think of the UI as only one component of the system Deals with the user Separate from the functional core (AKA, the app

More information

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

Outline. Announcements. Feedback. CS1007: Object Oriented Design and Programming in Java. Java beans Applets Outline CS1007: Object Oriented Design and Programming in Java Lecture #16 Nov 22 Shlomo Hershkop shlomo@cs.columbia.edu Java beans Applets Reading: finish chapter 7, starting 8 Announcements 4 more lectures

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

(0,0) (600, 400) CS109. PictureBox and Timer Controls

(0,0) (600, 400) CS109. PictureBox and Timer Controls CS109 PictureBox and Timer Controls Let s take a little diversion and discuss how to draw some simple graphics. Graphics are not covered in the book, so you ll have to use these notes (or the built-in

More information

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

Block I Unit 2. Basic Constructs in Java. AOU Beirut Computer Science M301 Block I, unit 2 1 Block I Unit 2 Basic Constructs in Java M301 Block I, unit 2 1 Developing a Simple Java Program Objectives: Create a simple object using a constructor. Create and display a window frame. Paint a message

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 layout manager helps lay out the components held by this container. When you set a layout to null, you tell the

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

Sri Vidya College of Engineering & Technology

Sri Vidya College of Engineering & Technology UNIT-V TWO MARKS QUESTION & ANSWER 1. What is the difference between the Font and FontMetrics class? Font class is used to set or retrieve the screen fonts.the Font class maps the characters of the language

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

IT101. Graphical User Interface

IT101. Graphical User Interface IT101 Graphical User Interface Foundation Swing is a platform-independent set of Java classes used for user Graphical User Interface (GUI) programming. Abstract Window Toolkit (AWT) is an older Java GUI

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

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

DEMYSTIFYING PROGRAMMING: CHAPTER FOUR

DEMYSTIFYING PROGRAMMING: CHAPTER FOUR DEMYSTIFYING PROGRAMMING: CHAPTER FOUR Chapter Four: ACTION EVENT MODEL 1 Objectives 1 4.1 Additional GUI components 1 JLabel 1 JTextField 1 4.2 Inductive Pause 1 4.4 Events and Interaction 3 Establish

More information

CSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours:

CSE115 / CSE503 Introduction to Computer Science I. Dr. Carl Alphonce 343 Davis Hall Office hours: CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall alphonce@buffalo.edu Office hours: Thursday 12:00 PM 2:00 PM Friday 8:30 AM 10:30 AM OR request appointment via e-mail

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

GUI Components: Part 1

GUI Components: Part 1 1 2 11 GUI Components: Part 1 Do you think I can listen all day to such stuff? Lewis Carroll Even a minor event in the life of a child is an event of that child s world and thus a world event. Gaston Bachelard

More information

GUI Event Handlers (Part I)

GUI Event Handlers (Part I) GUI Event Handlers (Part I) 188230 Advanced Computer Programming Asst. Prof. Dr. Kanda Runapongsa Saikaew (krunapon@kku.ac.th) Department of Computer Engineering Khon Kaen University 1 Agenda General event

More information

Inheritance and Substitution (Budd chapter 8, 10)

Inheritance and Substitution (Budd chapter 8, 10) Inheritance and Substitution (Budd chapter 8, 10) 1 2 Plan The meaning of inheritance The syntax used to describe inheritance and overriding The idea of substitution of a child class for a parent The various

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

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

To gain experience using GUI components and listeners.

To gain experience using GUI components and listeners. Lab 5 Handout 7 CSCI 134: Fall, 2017 TextPlay Objective To gain experience using GUI components and listeners. Note 1: You may work with a partner on this lab. If you do, turn in only one lab with both

More information

CS 11 java track: lecture 3

CS 11 java track: lecture 3 CS 11 java track: lecture 3 This week: documentation (javadoc) exception handling more on object-oriented programming (OOP) inheritance and polymorphism abstract classes and interfaces graphical user interfaces

More information

8. Polymorphism and Inheritance

8. Polymorphism and Inheritance 8. Polymorphism and Inheritance Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich http://seal.ifi.uzh.ch/info1 Objectives Describe polymorphism and inheritance in general Define interfaces

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

Instructions for Crossword Assignment CS130

Instructions for Crossword Assignment CS130 Instructions for Crossword Assignment CS130 Purposes: Implement a keyboard interface. 1. The program you will build is meant to assist a person in preparing a crossword puzzle for publication. You have

More information

Chapter 1 GUI Applications

Chapter 1 GUI Applications Chapter 1 GUI Applications 1. GUI Applications So far we've seen GUI programs only in the context of Applets. But we can have GUI applications too. A GUI application will not have any of the security limitations

More information

PESIT Bangalore South Campus

PESIT Bangalore South Campus PESIT Bangalore South Campus 15CS45 : OBJECT ORIENTED CONCEPTS Faculty : Prof. Sajeevan K, Prof. Hanumanth Pujar Course Description: No of Sessions: 56 This course introduces computer programming using

More information

Graphical User Interfaces. Comp 152

Graphical User Interfaces. Comp 152 Graphical User Interfaces Comp 152 Procedural programming Execute line of code at a time Allowing for selection and repetition Call one function and then another. Can trace program execution on paper from

More information

CPS221 Lecture: Threads

CPS221 Lecture: Threads Objectives CPS221 Lecture: Threads 1. To introduce threads in the context of processes 2. To introduce UML Activity Diagrams last revised 9/5/12 Materials: 1. Diagram showing state of memory for a process

More information

CSE 331 Software Design & Implementation

CSE 331 Software Design & Implementation CSE 331 Software Design & Implementation Kevin Zatloukal Summer 2017 Java Graphics and GUIs (Based on slides by Mike Ernst, Dan Grossman, David Notkin, Hal Perkins, Zach Tatlock) Review: how to create

More information

SCHEME OF COURSE WORK

SCHEME OF COURSE WORK SCHEME OF COURSE WORK Course Details: Course Title Object oriented programming through JAVA Course Code 15CT1109 L T P C : 3 0 0 3 Program: B.Tech. Specialization: Information Technology Semester IV Prerequisites

More information

CSC 551: Web Programming. Fall 2001

CSC 551: Web Programming. Fall 2001 CSC 551: Web Programming Fall 2001 Java Applets! applets & HTML "default methods (init, paint, ) "APPLET & OBJECT tags, applet parameters & dimensions! graphical applets "Graphics object: drawstring, drawline,

More information

CISC 1600 Lecture 3.1 Introduction to Processing

CISC 1600 Lecture 3.1 Introduction to Processing CISC 1600 Lecture 3.1 Introduction to Processing Topics: Example sketches Drawing functions in Processing Colors in Processing General Processing syntax Processing is for sketching Designed to allow artists

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

About This Lecture. Data Abstraction - Interfaces and Implementations. Outline. Object Concepts. Object Class, Protocol and State.

About This Lecture. Data Abstraction - Interfaces and Implementations. Outline. Object Concepts. Object Class, Protocol and State. Revised 01/09/05 About This Lecture Slide # 2 Data Abstraction - Interfaces and Implementations In this lecture we will learn how Java objects and classes can be used to build abstract data types. CMPUT

More information

Example: Building a Java GUI

Example: Building a Java GUI Steven Zeil October 25, 2013 Contents 1 Develop the Model 2 2 Develop the layout of those elements 3 3 Add listeners to the elements 9 4 Implement custom drawing 12 1 The StringArt Program To illustrate

More information

1 Getting started with Processing

1 Getting started with Processing cis3.5, spring 2009, lab II.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

Example: Building a Java GUI

Example: Building a Java GUI Steven Zeil October 25, 2013 Contents 1 Develop the Model 3 2 Develop the layout of those elements 4 3 Add listeners to the elements 12 4 Implement custom drawing 15 1 The StringArt Program To illustrate

More information

DCS235 Software Engineering Exercise Sheet 2: Introducing GUI Programming

DCS235 Software Engineering Exercise Sheet 2: Introducing GUI Programming Prerequisites Aims DCS235 Software Engineering Exercise Sheet 2: Introducing GUI Programming Version 1.1, October 2003 You should be familiar with the basic Java, including the use of classes. The luej

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

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming

CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming CPS122 Lecture: Graphical User Interfaces and Event-Driven Programming Objectives: Last revised 1/15/10 1. To introduce the notion of a component and some basic Swing components (JLabel, JTextField, JTextArea,

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

The AWT Package, Graphics- Introduction to Images

The AWT Package, Graphics- Introduction to Images Richard G Baldwin (512) 223-4758, baldwin@austin.cc.tx.us, http://www2.austin.cc.tx.us/baldwin/ The AWT Package, Graphics- Introduction to Images Java Programming, Lecture Notes # 170, Revised 09/23/98.

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

CMPSCI 187: Programming With Data Structures. Lecture 6: The StringLog ADT David Mix Barrington 17 September 2012

CMPSCI 187: Programming With Data Structures. Lecture 6: The StringLog ADT David Mix Barrington 17 September 2012 CMPSCI 187: Programming With Data Structures Lecture 6: The StringLog ADT David Mix Barrington 17 September 2012 The StringLog ADT Data Abstraction Three Views of Data Java Interfaces Defining the StringLog

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

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

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling Frames, GUI and events Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling Introduction to Swing The Java AWT (Abstract Window Toolkit)

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

CS 4300 Computer Graphics

CS 4300 Computer Graphics CS 4300 Computer Graphics Prof. Harriet Fell Fall 2011 Lecture 8 September 22, 2011 GUIs GUIs in modern operating systems cross-platform GUI frameworks common GUI widgets event-driven programming Model-View-Controller

More information

Contents. Foreword. Examples of GeoGebra Applet Construction 1 A Straight Line Graph... 1 A Quadratic Graph... 6 The Scalar Product...

Contents. Foreword. Examples of GeoGebra Applet Construction 1 A Straight Line Graph... 1 A Quadratic Graph... 6 The Scalar Product... Contents Foreword ii Examples of GeoGebra Applet Construction 1 A Straight Line Graph............................... 1 A Quadratic Graph................................. 6 The Scalar Product.................................

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

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

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

Chapter 12 Advanced GUIs and Graphics

Chapter 12 Advanced GUIs and Graphics Chapter 12 Advanced GUIs and Graphics Chapter Objectives Learn about applets Explore the class Graphics Learn about the classfont Explore the classcolor Java Programming: From Problem Analysis to Program

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

2IS45 Programming

2IS45 Programming Course Website Assignment Goals 2IS45 Programming http://www.win.tue.nl/~wsinswan/programmeren_2is45/ Rectangles Learn to use existing Abstract Data Types based on their contract (class Rectangle in Rectangle.

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

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

Variables, Types, and Expressions

Variables, Types, and Expressions Variables, Types, and Expressions Announcements Karel the Robot due right now. Email: Due Sunday, January 22 at 11:59PM. Update to assignment due dates: Assignments 2 5 going out one day later. Contact

More information

MODULE 8p - Applets - Trials B

MODULE 8p - Applets - Trials B MODULE 8p - Applets - Trials B The applet to be developed in this series of trials is called AppletB. The first version is a simple modification of AppletA but should be saved in AppletB.java import java.applet.applet;

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

Lecture Static Methods and Variables. Static Methods

Lecture Static Methods and Variables. Static Methods Lecture 15.1 Static Methods and Variables Static Methods In Java it is possible to declare methods and variables to belong to a class rather than an object. This is done by declaring them to be static.

More information