Gillian Miller Java Teacher Workshop :  Macquarie University 1Contents Advanced OO – Inheritance The Java API and documentation Strings Swing The Java.

Slides:



Advertisements
Similar presentations
1 Graphical User Interface (GUI) Applications Abstract Windowing Toolkit (AWT) Events Handling Applets.
Advertisements

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.
Web Design & Development Lecture 19. Java Graphics 2.
CSE 1341 Honors Professor Mark Fontenot Southern Methodist University Note Set 21.
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.
LAB SESSION 7 Graphical user interface Applet fundamentals Methods in applets Execution of an applet Graphics class.
Applets Graphical Java programs Run inside web browser Platform-neutral Easy deployment--loads when needed Secure.
Java Applet & JavaScript SNU OOPSLA Lab. October 2005.
Graphics Programming With Applets Feb 23, Applets There are three different types of executable java code. –Standalone application, which has main()
Lecture 24 Applets. Introduction to Applets Applets should NOT have main method but rather init, stop, paint etc They should be run through javac compiler.
Review of Java Applets Vijayan Sugumaran Decision and Information Sciences Oakland University.
1 Applets Chapter 1 To understand:  why applets are used to extend the capabilities of Web pages  how an applet is executed and know about the restrictions.
1 Recitation 11. Applet Applets. An applet is a Java program that is started by a browser (e.g. netscape or internet explorer) when an html file has a.
CS3157 Java UI Recitation. Material Covered: Overview of AWT components, Event Handling, creating applets, and sample UI. Not covered in recitation: Drawing,
26-Jun-15 Applets. 2 An applet is a Panel that allows interaction with a Java program A applet is typically embedded in a Web page and can be run from.
Graphical User Interfaces (GUI) Abstract Windows Toolkit (AWT): java.awt GUI elements: Primitive Button, Label, Checkbox, Scrollbar, etc. Container Panel,
Java GUI building with the AWT. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many.
Program Design With Methods And Graphics / Chapter 4 1 Abstract Window Toolkit.
Unit 11 Object-oriented programming: Graphical user interface Jin Sa.
Java Programming, 2E Introductory Concepts and Techniques Chapter 2 Creating a Java Application and Applet.
Chapter 9: Applets Jim Burns Fall Outline Learn about applets Learn about applets Write an HTML doc to host an applet Write an HTML doc to host.
Applets, AWTS CompSci 230 Software Construction.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Applets Chapter 17.  Java’s big splash onto the scene came in the mid 90’s. The people at Sun Microsystems had managed to work java programs into Web.
JAPPLET.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
JAVA, JAVA, JAVA Object-Oriented Problem Solving Ralph Morelli Trinity College Hartford, CT presentation slides for published by Prentice Hall Second Edition.
Chapter 17: Applets, Images, and Sound. Objectives Learn about applets Write an HTML document to host an applet Use the init() method Work with JApplet.
Introduction to Java Applet Programs Section 1.3Intro. to Java Applet Programs: a Greeter Applet Section 3.7Graphical/Internet Java: Applet: An Einstein.
Chapter 34 Java Technology for Active Web Documents methods used to provide continuous Web updates to browser – Server push – Active documents.
Graphical User Interface CSI 1101 N. El Kadri. Plan - agenda Graphical components Model-View-Controller Observer/Observable.
Java Applets. 2 Introduction to Java Applet Programs  Applications are stand alone programs executed with Java interpreter executed with Java interpreter.
Object Oriented Programming Examples: C++, Java Advantages: 1. reusibility of code 2. ability to adapt (extend) previously written code.
CS 3131 Introduction to Programming in Java Rich Maclin Computer Science Department.
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.
CSC 205 – Java Programming II Applet. Types of Java Programs Applets Applications Console applications Graphics applications Applications are stand-alone.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
MSc Workshop - © S. Kamin, U. ReddyLect 3 - GUI -1 Lecture 3 - Graphical User Interfaces r GUI toolkits in Java API r JFrame r GUI components.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
Applets and Frames. Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L14: GUI Slide 2 Applets Usually.
Applets Yong Choi School of Business CSU, Bakersfield.
Java Programming Applets. Topics Write an HTML document to host an applet Understand simple applets Use Labels with simple AWT applets Write a simple.
Chapter 14 Applets and Advanced GUI  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets F.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Introduction to Java Applet Programs Section 1.3Intro. to Java Applet Programs: a Greeter Applet Section 3.7Graphical/Internet Java: Applet: An Einstein.
Csc Basic Graphical User Interface (GUI) Components.
Creating Graphics in Java CSE301 University of Sunderland Harry R Erwin, PhD.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
CSI 3125, Preliminaries, page 1 AWT. CSI 3125, Preliminaries, page 2 AWT Java AWT (Abstract Windowing Toolkit) is an API to develop GUI or window-based.
Creating a Java Application and Applet
CSI 3125, Preliminaries, page 1 Applet. CSI 3125, Preliminaries, page 2 Applet An applet is a Java program that runs in a Web browser. An applet can be.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Applets. 9/04/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved L12: Applets Slide 2 Applets Usually.
1 Applets Programming. Introduction Java programs are divided into two main categories, applets and applications. An application is an ordinary Java program.
AWT Vs SWING. 2 AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many applications Uses.
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.
CSC 205 Programming II Lecture 5 AWT - I.
Applications Active Web Documents Active Web Documents.
Lecture 09 Applets.
Ellen Walker Hiram College
UNIT-5.
Java Applets.
GUI building with the AWT
Applet in Java.
Chap 1. Getting Started Objectives
GUI building with the AWT
Chap 4. Programming Fundamentals
JAVA APPLET PREPARED BY Mr. Jahanzaib Ahmed
G6DICP - Lecture 27 Java Applets.
Presentation transcript:

Gillian Miller Java Teacher Workshop :  Macquarie University 1Contents Advanced OO – Inheritance The Java API and documentation Strings Swing The Java Virtual Machine Applets Graphics Buttons, Frames and Panels

Gillian Miller Java Teacher Workshop :  Macquarie University 2 Object Think Design a system for BlackJack Think of 5 classes and some related attributes and methods How are classes associated ?

Gillian Miller Java Teacher Workshop :  Macquarie University 3 Class Association - BlackJack Class Player AttributesMethods hand name kitty showHand getAction receiveCash dealHand

Gillian Miller Java Teacher Workshop :  Macquarie University 4Inheritance When Object Classes are similar common shared characteristics of blueprint New sub class “specializes” or inherits from previous one Base class called super class Objects of subclass contain the signature of the superclass as well as their own signature eg base Person subclasses Student, Staff, Lecturer We say Class Student extend Person { …

Gillian Miller Java Teacher Workshop :  Macquarie University 5

Gillian Miller Java Teacher Workshop :  Macquarie University 6 Methods may also overridden

Gillian Miller Java Teacher Workshop :  Macquarie University 7Polymorphism void doStuff(Shape s) { s.erase(); //... s.draw(); } Circle c = new Circle(); Triangle t = new Triangle(); Square s = new Square (); doStuff(c); doStuff(t); doStuff(s); Determines which method to use depending on the specific class that object is – done by system at runtime Saves lots of if statements

Gillian Miller Java Teacher Workshop :  Macquarie University 8API Application Programming Interface Framework for specific functionality for the application programmer Set of classes (and interfaces) Implementation details hidden In Java the application programmer creates or extends objects from the API classes uses public methods and properties to achieve goals Examples - awt, applet, swing, jdbc, …

Gillian Miller Java Teacher Workshop :  Macquarie University 9

Gillian Miller Java Teacher Workshop :  Macquarie University 10 Java API Document A daunting but valuable resource Your task : Go to the above link Can you find String – Does String support a substring operation ? Find the Maths documentation (java.lang.maths) Can you find class Object. How does Object related to the other classes ?

Gillian Miller Java Teacher Workshop :  Macquarie University 11Strings Java provided class Strings are objects of class String String name; String lecName = “Gillian Miller”; String name1 = “Joan”; String name2 = “JOAN”; String name3 = “ xyz “; if (name1.equals (name2)) ….. if (name1.equalsIgnoreCase (name2)).. int j = name3.trim().length(); String methods equals (String val) length() charAt( int pos) trim() toLowerCase() toUpperCase() substring(int from, int len);

Gillian Miller Java Teacher Workshop :  Macquarie University 12 Java is Portable One of the main reasons for Java’s success ? Java is portable - ubiquitous Java sits on top of Java Virtual Machine – A JVM needs only to be written once for each major platform – So for Program code

Gillian Miller Java Teacher Workshop :  Macquarie University 13 Java Compilation System Library classes Compile Java Source filename.java Java Byte Codes filename.class Java Virtual Machine Interprets and executes byte code Can transfer bytecodes to another computer

Gillian Miller Java Teacher Workshop :  Macquarie University 14SWING Build StandAlone Applications in Java Windows, Dialog Boxes Components – text area, …. Different layouts Responding to events such as clicking boxes

Gillian Miller Java Teacher Workshop :  Macquarie University 15 Dialog Frame Top Level Containers - the top of the Swing Hierarchy Containers may contain other components and containers Top Level Containers add (Component comp) setSize( …) setLayout ( …)

Gillian Miller Java Teacher Workshop :  Macquarie University 16 Layout Managers

Gillian Miller Java Teacher Workshop :  Macquarie University 17Components

Gillian Miller Java Teacher Workshop :  Macquarie University 18COMPONENT GUI Components + Applets Examples - classes Label, TextField, TextArea, Button, Panel METHODS setBackground (Color col) setForeground (Color col) setText(String) String getText()

Gillian Miller Java Teacher Workshop :  Macquarie University 19 import java.awt.*; public class buttonDir extends JPanelApplet { public void init() { setLayout(new BorderLayout()); add(new Button("North"), BorderLayout.NORTH); add(new Button("South"), BorderLayout.SOUTH); add(new Button("East"), BorderLayout.EAST); add(new Button("West"), BorderLayout.WEST); add(new Button("Center"), BorderLayout.CENTER) ; } } Border Layout

Gillian Miller Java Teacher Workshop :  Macquarie University 20 register implements actionPerformed getSource ()

Gillian Miller Java Teacher Workshop :  Macquarie University 21Applets Java Byte code that can work inside a browser One of the reasons that Java took off with such Hype Applets are still fun Java also has a comprehensive set of tools for GUI stand alone applications Most graphical, dynamic effects on the Web these days are being done with JavaScript (which is not Java !) and dynamic HTML

Gillian Miller Java Teacher Workshop :  Macquarie University 22 c:\jdk1.3.1_01\demo\jfc\Java2D.html

Gillian Miller Java Teacher Workshop :  Macquarie University 23Applets Use of the Java API – applets, awt Applies inheritance and interfaces Object-driven programming at work Applets invoke from within HTML Issues with browser wars Plug-ins available from Sun, or you can run an Applet Viewer

Gillian Miller Java Teacher Workshop :  Macquarie University 24 My First Applet Build an applet to say “Hello World”

Gillian Miller Java Teacher Workshop :  Macquarie University 25

Gillian Miller Java Teacher Workshop :  Macquarie University 26Applet public static void init () called when applet created public static void start () called whenever applet refreshed useful for animations and threads public static void stop () whenever applet stopped PLUS methods of Panel, Component, Container etc YOU DO NOT NEED A MAIN CLASS FOR APPLET

Gillian Miller Java Teacher Workshop :  Macquarie University 27 Java Applet Class Hierarchy Object Component Container Panel Applet YourAppletClass

Gillian Miller Java Teacher Workshop :  Macquarie University 28

Gillian Miller Java Teacher Workshop :  Macquarie University 29

Gillian Miller Java Teacher Workshop :  Macquarie University 30 Graph Methods drawLine (int x1, int y1, int x2, int y2) drawRect (int x, int y, int width, int height) drawOval (int x, int y, int width, int height) fillOval (int x, int y, int width, int height) fillRect (int x, int y, int width, int height) drawString (String s, int x, int y) drawArc (int x, int y, int width, int height, int startAngle, int arcAngle) clearRect (int x, int y, int width, int height) setFont (Font fnt) setColor (Color color) many others - RoundRect, 3DRect, Polygon, Image etc

Gillian Miller Java Teacher Workshop :  Macquarie University 31

Gillian Miller Java Teacher Workshop :  Macquarie University 32

Gillian Miller Java Teacher Workshop :  Macquarie University 33

Gillian Miller Java Teacher Workshop :  Macquarie University 34

Gillian Miller Java Teacher Workshop :  Macquarie University 35 Your Turn 1.Practical 3 2.Create a new folder called AppletPlay 3.Copy the applets n the sample code 4.Open in BlueJ. Compile, right mouse click to run Applet. 5.All are best viewed with a size of 300 X Play with saving as HTML then running in IE 7.Create a new applet in BlueJ 8.Play with all applets adding your own flair and touches.