Applets & Applications CSC 171 FALL 2001 LECTURE 15.

Slides:



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

Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
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.
Web Design & Development Lecture 19. Java Graphics 2.
Basic Java – Interface design. Understand: How to use TextPad for Java How to define classes and objects How to create a GUI interface How event-driven.
CS18000: Problem Solving and Object-Oriented Programming.
Unit 3 Graphical User Interface (GUI) Dr. Magdi AMER.
Graphic User Interfaces Layout Managers Event Handling.
Multithreading : animation. slide 5.2 Animation Animation shows different objects moving or changing as time progresses. Thread programming is useful.
Chapter 5 Programming Graphics. Chapter Goals To be able to write applications with simple graphical user interfaces To display graphical shapes such.
Java Applets- Using SwingWorker Dave Price and Chris Loftus Computer Science Department University of Wales, Aberystwyth.
Introduction to Java Classes, events, GUI’s. Understand: How to use TextPad How to define a class or object How to create a GUI interface How event-driven.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Event Handling Events and Listeners Timers and Animation.
GUI and Event-Driven Programming Recitation – 3/6/2009 CS 180 Department of Computer Science, Purdue University.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 14 GUI and Event-Driven Programming.
Carnegie Mellon University, MISM1 Java GUI programming and Java Threads GUI example taken from “Computing Concepts with Java 2” by Cay Horstmann Thread.
Object Oriented Programming Java 1 GUI example taken from “Computing Concepts with Java 2” by Cay Horstmann GUI Programming.
Layout Mangers CSC 171 FALL 2001 LECTURE 14. History: The Transistor William Shockley, John Bardeen, and Walter Brattain invent the transfer resistance.
CS 112 GUI 06 May 2008 Bilkent. Java GUI API Containers: ◦ contain other GUI components. E.g, Window, Panel, Applet, Frame Dialog. Components: ◦ Buttons,
14-Jul-15 Model-View-Controller. 2 Design Patterns The hard problem in O-O programming is deciding what objects to have, and what their responsibilities.
Java Review Structure of a graphics program. Computer Graphics and User Interfaces Java is Object-Oriented A program uses objects to model the solution.
Applets Java API.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
ACM/JETT Workshop - August 4-5, ExceptionHandling and User Interfaces (Event Delegation, Inner classes) using Swing.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 20.1 Test-Driving the Screen Saver Application.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
Lab 6: Shapes & Picture Extended Ellipse & Rectangle Classes Stand-Alone GUI Applications.
Adding Graphics to a Frame Application Applets: Can generate drawings by overriding paint Frame: Do not draw directly on a frame. Draw graphics on a JPanel.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
1 Why layout managers Can we perform layout without them? –Yes. A container’s layout property can be set to null. Absolute positioning: specify size and.
LAB 1CSIS04021 Briefing on Assignment One & RMI Programming February 13, 2007.
CS 112 Department of Computer Science George Mason University CS 112 Department of Computer Science George Mason University Writing Graphic Applications.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
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.
CSC 205 – Java Programming II Applet. Types of Java Programs Applets Applications Console applications Graphics applications Applications are stand-alone.
Program that runs in appletviewer (test utility for applets) Web browser (IE, Communicator) Executes when HTML (Hypertext Markup Language) document containing.
Copyright © 2002, Systems and Computer Engineering, Carleton University c-Gui3.ppt * Object-Oriented Software Development Part 18-c Building.
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.
Swing GUI Components You can create graphics components to place on your applet using classes available in the Swing package ( javax.swing ) Class names.
Chapter 12 1 TOPIC 13B l Buttons and Action Listeners Window Interfaces Using Swing Objects.
MSc Workshop - © S. Kamin, U.Reddy Lect 4 - Events - 1 Lecture 4 – Event Handling r Painting r Event types r Catching different event types.
Swing Differences between Swing and AWT Naming Conventions All Swing components begin with a capital J -- JPanel, JButton, JScrollBar, JApplet, etc..
An Introduction to Programming and Object Oriented Design using Java 3 rd Edition. Dec 2007 Jaime Niño Frederick Hosch Chapter 18 Integrating user interface.
Concurrent Programming and Threads Threads Blocking a User Interface.
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.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 21.1 Test-Driving the Painter Application.
(C) 2010 Pearson Education, Inc. All rights reserved.  Class Graphics (from package java.awt) provides various methods for drawing text and shapes onto.
Java GUI. Graphical User Interface (GUI) a list a button a text field a label combo box checkbox.
Creating Applets. What is an applet? What is an applet? A Java program that runs in a web browser. A Java program that runs in a web browser. An applet.
Field Trip #23 Hangman By Keith Lynn. JApplet A JApplet is a top-level container An applet is a small Java program that is executed by another program.
Introduction to Java Chapter 9 - Graphical User Interfaces and Applets1 Chapter 9 Graphical User Interfaces and Applets.
GUI DYNAMICS Lecture 11 CS2110 – Fall GUI Statics and GUI Dynamics  Statics: what’s drawn on the screen  Components buttons, labels, lists, sliders,
1 Applets. 2 Design of Applets 3 Sun wrote Java to be executable within a hosting application browser The applications are applets. An applet is downloaded.
Review_6 AWT, Swing, ActionListener, and Graphics.
Applets Java code is compiled into byte code instead of machine language –Languages like C, C++, Pascal and others are compiled into machine language so.
Basics of GUI Programming Chapter 11 and Chapter 22.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 27.1 Test-Driving the Drawing Shapes Application.
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.
1 Layout Managers Layout managers –Provided for arranging GUI components –Provide basic layout capabilities –Processes layout details –Programmer can concentrate.
Graphical User Interface (GUI)
CPCS 391 Computer Graphics Lab One. Computer Graphics Using Java What is Computer Graphics: Computer graphics are graphics created using computers and,
Java Applet What is a Java Applet? How is applet compiled?
GUI AND GRAPHICS.
Applets & Applications
4.14 GUI and Graphics Case Study: Creating Simple Drawings (Cont.)
Introduction to Event Handling
Applets.
JAVA APPLET PREPARED BY Mr. Jahanzaib Ahmed
Presentation transcript:

Applets & Applications CSC 171 FALL 2001 LECTURE 15

History: Grace Hooper 1952 Grace Hopper working on the UNIVAC, "The Education of a Computer", (Proc. ACM Conference) The use of selected pre- written code segments to be assembled into programs written in a high level language The concept of a compiler, and the general concept of language translation.

Applets & Applications Applets – Generally run over networks – Code download – Client side execution – Extend Applet Applications – Generally run on hosts – Resident host – Local host execution – Extend Frame

GUIs in general Sometimes, it is useful to have a program that runs as either an applet or an application

Applet/App Architecture DrawShapes Applet init() setWidth() setHeight() main() Button Handler DrawPanel actionPerformed() actionListener JPanel paintComponent() setcurrentchoice()

Relationships DrawShapes – is-a Applet – has-a Jframe (inside of main) – Has-a DrawPanel – Has-a ButtonHandler DrawPanel is-a Jpanel ButtonHandler implements ActionListener

What Happens In an Applet? JVM calls DrawShapes.init() – Builds DrawPanel – Builds ButtonHandler – BuildsButtons – Adds components

What Happens In an Application? JVM calls DrawShapes.main() – Builds Jframe application window – Builds DrawShapes Applet (see previous) – Calls DrawShapes.init() – Calls DrawShapes.start. – Adds applet to application window I.E. (har) : Frame takes place of browser

Using Command Line Args public static void main( String args[] ){ int width, height; // check for command-line arguments if ( args.length != 2 ) { width = 300; height = 200; } else { width = Integer.parseInt( args[ 0 ] ); height = Integer.parseInt( args[ 1 ] ); }

Build the Application // create window in which applet will execute JFrame applicationWindow = new JFrame( "An applet running as an application"); applicationWindow.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

Build the applet from the application // create one applet instance DrawShapes appletObject = new DrawShapes(); appletObject.setWidth( width ); appletObject.setHeight( height ); // call applet's init and start methods appletObject.init(); appletObject.start();

Get it going // attach applet to center of window applicationWindow.getContentPane().add( appletObject ); //note nested method calls applicationWindow.setSize( width, height ); applicationWindow.setVisible( true );

Architecture of Applet Separate class for button handler Separtae class for drawing region Separate button panel & Draw panel – Applet is in BorderLayout NORTH –Panel containing grid layout with 3 buttons CENTER –Drawing region

ButtonHandler private class ButtonHandler implements ActionListener { // can access choices because it is an inner class public void actionPerformed( ActionEvent event ) { for ( int count = 0; count < choices.length; count++ ) if ( event.getSource() == choices[ count ] ) { drawingPanel.setCurrentChoice( count ); break; } } // end private inner class ButtonHandler

DrawPanel Using a separate panel allows painting without interfering with other components Loosely coupled with Applet – No shared data

When ButtonHandler invokes setCurrentChoice() // specify current shape choice and repaint public void setCurrentChoice( int choice ) { currentChoice = choice; repaint(); }

DrawPanel public void paintComponent( Graphics g ) { super.paintComponent( g ); switch( currentChoice ) { case 0: g.drawLine( randomX(), randomY(), randomX(), randomY() ); break; //etc.... } } // end method paintComponent