Podsumowanie Nguyen Hung Son Uniwersytet Warszawski.

Slides:



Advertisements
Similar presentations
Custom Painting Gestione della Grafica customizzata Vedi anche:
Advertisements

J0 1 Marco Ronchetti - Basi di Dati Web e Distribuite – Laurea Specialitica in Informatica – Università di Trento.
1 Applets Programming Enabling Application Delivery Via the Web.
Applets and Graphics.
Engr 691 Special Topics in Engineering Science Software Architecture Spring Semester 2004 Lecture Notes.
Chapter 15 Graphics. To paint, you need to specify where to paint. Each component has its own coordinate system with the origin (0, 0) at the upper-left.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
2D Graphics Drawing Things. Graphics In your GUI, you might want to draw graphics E.g. draw lines, circles, shapes, draw strings etc The Graphics class.
Made with love, by Zachary Langley Applets The Graphics Presentation.
© 2007 Lawrenceville Press Slide 1 Chapter 5 The if Statement  Conditional control structure, also called a decision structure  Executes a set of statements.
Web Design & Development Lecture 19. Java Graphics 2.
Life Cycle of an Applet, along with response to mouse events and other simple features. (ps:only two possible examples for life circle of an Applet)
1 More on Applets Overview l Changing Colors l Changing Fonts & Styles l Applet Life-Cycle l Input using Dialog Window l Input using HTML parameters l.
Frame Windows A frame object is used to create a graphical frame window. This frame is used to show information in a graphical application. The JFrame.
CSE 1341 Honors Professor Mark Fontenot Southern Methodist University Note Set 21.
Xiaoying Gao Computer Science Victoria University of Wellington Copyright: Xiaoying Gao, Peter Andreae, Victoria University of Wellington Graphical Output,
Polymorphism Method overriding Method overloading Dynamic binding 1.
Chapter 2: Using Objects Part 2. Assume you wish to test the behaviour of some method. This is accomplished by providing a tester class: Supply a main.
Java Applets:. How Applets differ from application?: They do not use main method but init(), start() and paint() methods of the applet class They can.
Object Oriented Programming one of the main reasons we now teach Java instead of C++. C++ was designed to be backwardly compatible with the original.
Object Oriented Programming one of the main reasons we now teach Java instead of C++. C++ was designed to be backwardly compatible with the original.
Graphics Graphics Java Vectors Java Enumeration Graphical Spreadsheets
The Point Class public class Point { public double x; public double y; public Point(double x0, double y0) { x = x0; y = y0; } public double distance(Point.
 Specifies a set of methods (i.e., method headings) that any class that implements that interface must have.  An interface is a type (but is not a class).
Graohics CSC 171 FALL 2001 LECTURE 16. History: COBOL Conference on Data System Languages (CODASYL) - led by Joe Wegstein of NBS developed the.
Laboratory Study II October, Java Programming Assignment  Write a program to calculate and output the distance traveled by a car on a tank of.
Mouse Listeners We continue our examination of GUIs by looking at how to interact with the mouse –Just as Java creates Events when the user interacts with.
Graphics Chapter 16.  If you want to draw shapes such as a bar chart, a clock, or a stop sign, how do you do it?
PHY-102 SAPIntroductory GraphicsSlide 1 Introductory Graphics In this section we will learn how about how to draw graphics on the screen in Java:  Drawing.
LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class.
Craps. /* * file : Craps.java * file : Craps.java * author: george j. grevera, ph.d. * author: george j. grevera, ph.d. * desc. : program to simulate.
Public class ABC { private int information = 0; private char moreInformation = ‘ ‘; public ABC ( int newInfo, char moreNewInfo) { } public ABC () {} public.
CSE 341, S. Tanimoto Java-PolyDraw- 1 A Java Case Study: An Applet for Drawing Polygons Motivation -- See a number of AWT features integrated. Get ideas.
Applets Graphical Java programs Run inside web browser Platform-neutral Easy deployment--loads when needed Secure.
Lecture 15.1 Static Methods and Variables. © 2006 Pearson Addison-Wesley. All rights reserved Static Methods In Java it is possible to declare.
Chapter 5 Ch 1 – Introduction to Computers and Java Defining Classes and Methods 1.
Objects, Variables & Methods Java encapsulates data and action modules that access the data in one container, called an object. Object members that.
Computer Programming Lab 8.
Java Applets- Using SwingWorker Dave Price and Chris Loftus Computer Science Department University of Wales, Aberystwyth.
1 Fac.Scienze – Università di Trento Programmazione 2 - Marco Ronchetti Events Gestione degli eventi.
Jan Event Handling Yangjun Chen Dept. Business Computing University of Winnipeg.
For Computational Finance Java Applets and the AWT Jeff Stephenson (slides adapted from Manu Kumar)
Jan Event Handling -1.1 Yangjun Chen Dept. Business Computing University of Winnipeg.
Object Oriented Programming (OOP) LAB # 5 TA. Maram & TA. Mubaraka TA. Kholood & TA. Aamal.
Program Design With Methods And Graphics / Chapter 4 1 Abstract Window Toolkit.
This is an optional chapter in the AP Computer Science curriculum. The graphics concepts in this chapter and future input/output chapters will not be.
Agenda For Feb Discussion (Assignments & Rubric) 2. PowerPoint Presentation (Drawing Basic Shapes). 4.Read Unit 3 carefully (pages ) then.
Applets.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 9.
10/5: Primitives, the for loop Primitive data types –why we mention them Return to counter-controlled repetition.
Applets & Graphics. Applets programs that run inside a browser Java platform-independence makes applets possible security restrictions: –cannot read or.
7/3/00SEM107- © Kamin & ReddyClass 11 - Events - 1 Class 11 - Events r A couple of odds & ends m Component sizes  switch statement r Event types r Catching.
CSTP FS99CS423 (cotter)1 Java Graphics java.awt.*;
Lecture 8.3 The Use of JComponent. © 2006 Pearson Addison-Wesley. All rights reserved More About the Standard Drawing Classes java.awt.Container.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Java Applets 1. What is an applet? An applet is a small Java program that is typically embedded in a Web page and can be run using the applet viewer or.
12/5/00SEM107, Kamin & ReddyReview - 34 Events Event types Catching different event types Getting information from components and events Distinguishing.
Layout Managers Arranges and lays out the GUI components on a container.
CIS 3.5 Lecture 2.2 More programming with "Processing"
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Painting (Chapter 12) Java Certification Study Group January 25, 1999 Mark Roth.
A: A: double “4” A: “34” 4.
Chapter 6: Events in Java 1.0 Model –Event class –selecting component to handle –handleEvent method –helper methods (action, keyUp, mouseUp, etc.) 1.1.
Test Review. General Info. All tests will be comprehensive. You will be tested more on your understanding of code as opposed to your ability to write.
GUI Tutorial Day 4. More GUI action  adding a Mouse Listener  SimpleDots  Simple mouse listener  Draw an oval where the mouse is clicked  Box example.
Applet: An applet is a java program that is transmitted over the network from the server to client & executed within clients browser. Applets are used.
null, true, and false are also reserved.
An overview of Java, Data types and variables
More programming with "Processing"
Applet Fundamentals Applet are small applications that are accessed on an Internet server, transported over the Internet, automatically installed and run.
Presentation transcript:

Podsumowanie Nguyen Hung Son Uniwersytet Warszawski

Spis rzeczy Znacznik APPLET: Pobieranie parametrów dla Appletów Zdarzenia w Appletach Pisanie tekstów w Appletach Rysowanie: linii, owale, prostokątów i kolorawanie Wątki Interakcja z użytkownikiem: Myszka i Klawisze –Myszka: Java Doodle –Klawisze: TypeWriter

Znacznik APPLET import java.applet.Applet; import java.awt.Graphics; public class MyApplet extends Applet { String dane; public void init() { dane = getParameter(Powitanie"); } public void paint(Graphics g) { g.drawString(dane, 50, 25); }

Zdarzenia w Appletach import java.applet.Applet; import java.awt.*; public class EventTutor extends Applet { public void init() { System.out.println("init event"); } public void start() { System.out.println("start event"); } public void destroy() { System.out.println("destroy event"); } public void paint(Graphics g) { System.out.println("paint event"); } public void update(Graphics g) { System.out.println("update event"); } public boolean keyDown(Event e, int x) { System.out.println("The " + (char) x + " key was pressed."); return true; }

Zdarzenia public boolean mouseUp(Event e, int x, int y) { System.out.println("mouseUp event"); return false; } public boolean mouseDown(Event e, int x, int y) { System.out.println("mouseDown event"); return false; } public boolean mouseDrag(Event e, int x, int y) { System.out.println("mouseDrag event"); return false; } public boolean mouseMove(Event e, int x, int y) { System.out.println("mouseMove event"); return false; } public boolean mouseEnter(Event e, int x, int y) { System.out.println("mouseEnter event"); return false; } public boolean mouseExit(Event e, int x, int y) { System.out.println("mouseExit event"); return false; } public void getFocus() { System.out.println("getFocus event"); } public void gotFocus() { System.out.println("gotFocus event"); } public void lostFocus() { System.out.println("lostFocus event"); }

lOsO w a n iE W klasie java.lang.Math jest metoda Math.random(), która zwraca losową liczbę między 0.0 a 1.0 Funkcja losująca liczbę od 0 do range private int Randomize( int range ) { double rawResult; rawResult = Math.random(); return (int) (rawResult * range); }

Rysowanie import java.applet.Applet; import java.awt.*; public class abc extends Applet { int RectHeight, RectWidth, RectTop, RectLeft, AppletWidth, AppletHeight ; public void init() { Dimension d = size(); AppletHeight = d.height; AppletWidth = d.width; RectTop = Randomize(AppletHeight); RectLeft= Randomize(AppletWidth); RectHeight = Randomize(AppletHeight - RectTop); RectWidth = Randomize(AppletWidth - RectLeft); RectColor = new Color(Randomize(255),Randomize(255),Randomize(255)); repaint(); } public void paint(Graphics g) { g.setColor(RectColor); g.drawRect(0, 0, AppletWidth-1, AppletHeight-1); g.fillRect(RectLeft, RectTop, RectWidth-1, RectHeight-1); }

Rysowanie linii import java.applet.*; import java.awt.*; public class GraphApplet extends Applet { int x0, xN, y0, yN; public void init() { Dimension d = size(); x0 = 0; xN = d.width-1; y0=0; yN=d.height-1; } public void paint(Graphics g) { for (int x = x0; x < xN; x++) { g.drawLine(x,(int) (yN*Math.sin(x)),x+1, (int) (yN*Math.sin(x+1))); }

Wątki w akcji(w animacji) Przykład rysowania wielu prostokątów Przykład FlyingLines Zasada: –implementowanie interfejsu Runnable –Run –Start –Stop

Interakcja - przykład rysownika import java.applet.Applet; import java.awt.*; import java.util.Vector; public class Rysownik extends Applet { Vector points = new Vector(); public void paint(Graphics g) { int x1, y1, x2, y2; Point tempPoint; if (points.size() > 1) { tempPoint = (Point) points.elementAt(0); x1 = tempPoint.x; y1 = tempPoint.y; for (int i = 1; i < points.size(); i++) { tempPoint = (Point)points.elementAt(i); x2 = tempPoint.x; y2 = tempPoint.y; g.drawLine(x1, y1, x2, y2); x1 = x2; y1 = y2; } // end for } // end if } public boolean mouseDown(Event e, int x, int y) { points.addElement(new Point(x, y)); return true; } public boolean mouseDrag(Event e, int x, int y) { points.addElement(new Point(x, y)); repaint(); return true; } public boolean mouseUp(Event e, int x, int y) { points.addElement(new Point(x, y)); repaint(); return true; }

Interakcja - przykład TypeWriter import java.applet.Applet; import java.awt.Event; import java.awt.Graphics; public class typewriter extends Applet { int numcols = 80; int numrows = 25; int row = 0; int col = 0; char page[][] = new char[numrows][]; public void init() { for (int i = 0; i < numrows; i++) { page[i] = new char[numcols]; } for (int i = 0; i < numrows; i++) { for (int j = 0; j < numcols; j++) { page[i][j] = '\0'; } public void paint(Graphics g) { for (int i=0; i < numrows; i++) { String tempString = new String(page[i] g.drawString(tempString, 5, 15*(i+1)); } public boolean keyDown(Event e, int key) { char c = (char) key; switch (key) { case Event.HOME: row = 0; col = 0; break; case Event.END: row = numrows-1; col = numcols-1; break; case Event.UP: if (row > 0) row--;break;

TypeWriter case Event.DOWN: if (row < numrows-1) row++; break; case Event.LEFT: if (col > 0) col--; else if (col == 0 && row > 0) { row--; col=numcols-1; } break; case Event.RIGHT: if (col < numcols-1) col++; else if (col == numcols-1 && row < numrows-1) { row++; col=0; } break; default: if (c == '\n' || c == '\r') { row++; col = 0; } else if (row < numrows) { if (col >= numcols) { col = 0; row++; } page[row][col] = c; col++; } else { // row >= numrows col++; } repaint(); return true; }