1 Java and AWT CPS 470 Spring 1998 Laura Campbell.

Slides:



Advertisements
Similar presentations
GUI Elements Session 17. Memory Upload Layout Components Button TextField TextArea Label Choice Containers Panels The applet itself.
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.
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.
AWT Components. 2 Using AWT Components 4 Component –Canvas –Scrollbar –Button –Checkbox –Label –List –Choice –TextComponent –TextArea –TextField 4 Component.
Java Applet & JavaScript SNU OOPSLA Lab. October 2005.
Jan AWT Widgets Yangjun Chen Dept. Business Computing University of Winnipeg.
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.
Programming and Problem Solving With Java Copyright 1999, James M. Slack Applets What is an Applet? Applet Parameters Graphics in Applets Other Applet.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
June 1, 2000 Object Oriented Programming in Java (95-707) Advanced Topics 1 Lecture 9 Object Oriented Programming in Java Advanced Topics Abstract Windowing.
1 Simple Phone Applet Lab Mobile Phone Display Area Send, Menu and End Numbers 0-9 * and #
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.
18-Jun-15 Applets. 2 An applet is a program that is typically embedded in a Web page and can be run from a browser You need special HTML in the Web page.
CS3157 Java UI Recitation. Material Covered: Overview of AWT components, Event Handling, creating applets, and sample UI. Not covered in recitation: Drawing,
Jan Containers Yangjun Chen Dept. Business Computing University of Winnipeg.
Applets. 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 a browser You.
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.
28-Jun-15 Applets. 2 An applet is a program that is typically embedded in a Web page and can be run from a browser You need special HTML in the Web page.
Making Applets ICS 4C / 4U. GUI GUI stands for Graphical User Interface and means that the screen you see in front of you probably has graphics on it.
Io package as Java’s basic I/O system continue’d.
AWT Components (Chapter 9) Java Certification Study Group January 21, 1999 Mark Roth.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
Draw Shapes Introduction to simple graphics. What is a Component? A class that resides in the java.awt package Examples include: –Button, java.awt.Button.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 65 – Manipulating Data Using Methods – Java Applet.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 12 Advanced GUIs and Graphics.
Georgia Institute of Technology Workshop for Programming And Systems Management Teachers Chapter 9 Source File Anatomy.
JAPPLET.
Applets Life Cycle Drawing and Event Handling Methods for UI Components Applet Capabilities Example.
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.
CS377A: A Programming Approach to HCI Jan Borchers Spring Swing Refresher David Merrill 5/14/2002
Chapter 13. Applets and HTML HTML Applets Computer Programming with JAVA.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Introduction to Applets Course Lecture Slides 29 th July 2010.
Cs884(Prasad)java12AWT1 Abstract Windowing Toolkit Support for Graphical User Interface (Event-driven programming)
Applets Session 8. Java Simplified / Session 8 / 2 of 31 Review The Abstract Windowing Toolkit (AWT) is a set of classes that allow us to create a graphical.
Java Applets. 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 a browser.
Applets. What is an applet? Why create applets instead of applications? – Applets are Java programs that can be embedded in an HTML document – In contrast,
Applets. 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 a browser You.
CSC 205 – Java Programming II Applet. Types of Java Programs Applets Applications Console applications Graphics applications Applications are stand-alone.
CS100A, Fall Lecture, 4 Nov. 1 CS100A, Fall 1997 Lecture 4 November: OTHELLO Goals: Introduce you to assignment 8. Let you have fun with the game.
Swing Differences between Swing and AWT Naming Conventions All Swing components begin with a capital J -- JPanel, JButton, JScrollBar, JApplet, etc..
1 Lesson: Applets with User Input and Output with GUI ICS4M.
CS100A, Lecture 16, 27 October CS100A Lecture October 1998 Assignment 7: A Checker-playing program: learning about GUIs and working with a.
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.
Java Programming Applets. Topics Write an HTML document to host an applet Understand simple applets Use Labels with simple AWT applets Write a simple.
9.1 Java Packages A collection of classes Allows classes to be grouped arbitrarily Hierarchical structure independent of inheritance Classes can.
Java Applet Basics (2). The Body Mass Index Calculator.
Intro to Applets. Applet Applets run within the Web browser environment Applets bring dynamic interaction and live animation to an otherwise static HTML.
Csc Basic Graphical User Interface (GUI) Components.
Review_6 AWT, Swing, ActionListener, and Graphics.
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.
Java Swing One of the most important features of Java is its ability to draw graphics.
Introduction to Applets Chapter 21. Applets An applet is a Java application that is intended to be invoked and executed through a Web browser. Click Here.
Events (Chapter 11) Java Certification Study Group January 25, 1999 Mark Roth.
Rina System development with Java Instructors: Rina Zviel-Girshin Lecture 10.
Chapter 6: Events in Java 1.0 Model –Event class –selecting component to handle –handleEvent method –helper methods (action, keyUp, mouseUp, etc.) 1.1.
1 IM103 week 8 (C&K ch17, p412) Advanced graphic programming Learning objectives By the end of this chapter you should be able to:  create dialogue windows.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
JAVA, JAVA, JAVA Object-Oriented Problem Solving Ralph Morelli Trinity College Hartford, CT presentation slides for published by Prentice Hall Second Edition.
Chapter 11: Threaded Programs Situations where the program is following multiple execution paths (how to stop one?) Thread: a line of execution Thread.
1 Applets Programming. Introduction Java programs are divided into two main categories, applets and applications. An application is an ordinary Java program.
Java Programming (By Rama Bhadra Rao M) You can Trace me in Day 5
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
Lecture 09 Applets.
Abstract Window ToolKit (AWT)
AWT Components and Containers
UNIT-5.
APPLET PROGRAMMING.
Presentation transcript:

1 Java and AWT CPS 470 Spring 1998 Laura Campbell

2 Java 1.0 ADM group thinks they can do it using 1.0 instead of 1.1 Better chance of running under Netscape than 1.1 /usr/java/bin/javac /usr/java/bin/appletviewer

3 Setup for Java on SGIs Add to.personal file: if (`uname` == "IRIX") then set path=($path /usr/java/bin) endif A path to the correct javac (/opt/bin/javac) should already be set up on the Suns.

4 Java.awt-components MenuComponent –MenuBar –MenuItem Menu, CheckboxMenuItem Component –Button, Canvas, Checkbox, Choice, Label, List, Scrollbar –TextComponent TextArea, TextField –Container Panel, Window

5 References URLs on class web page(s) Java books on reserve in Engineering Library SunSoft Press Java Series Java API (James Gosling, et al)

6 Lab Assignment Files –MsuMap.java –MyCanvas.java –?.java (you’ll subclass Choice) Task –Keep the map display and the choice items synchronized How –Subclass Choice so you can override the event handling

7 // MsuMap.java import java.awt.*; import java.applet.*; import java.net.*; public class MsuMap extends Canvas { private Image im; private Image msumap; private Image selectedMsumap; public MsuMap(Image i1, Image i2) { msumap = i1; selectedMsumap = i2; im = msumap; } public void paint( Graphics g ) { g.drawImage(im,0,0,this); } public boolean handleEvent( Event event ) { Object target = event.target; int id = event.id; if ((target == this) && (id == Event.MOUSE_DOWN)) { if (im == msumap) { im = selectedMsumap; } else { im = msumap; } repaint(); return true; } return false; }

8 // MyCanvas.java (original) import java.applet.*; import java.awt.*; import java.net.*; public class MyCanvas extends Applet { java.awt.Component canvas; java.awt.Choice choiceBox; // Initialize this object. public void init() { super.init(); URL codebase = getCodeBase(); Image msumap = getImage(codebase, "msumap.gif"); Image selected = getImage(codebase, "selected.gif"); // Manual layout may be used for appletviewer // but should NOT be used for Netscape (it gets confused). // Set the layout to null to override it with manual commands. // // setLayout(null); // may uncomment this line for appletviewer // Set the background color to off-white. setBackground(new Color(0xfaf0e6)); resize(800, 500); add(canvas = new MsuMap(msumap,selected)); canvas.move(43, 20); canvas.resize(600, 500); canvas.show(); add(choiceBox = new java.awt.Choice()); choiceBox.addItem("Route"); choiceBox.addItem("Facility"); choiceBox.setFont(new Font("Dialog", 0, 12)); // may uncomment the next line if manual layout used for appletviewer // choiceBox.move(650, 49); choiceBox.show(); }

9 // MyCanvas.java (revised) import java.applet.*; import java.awt.*; import java.net.*; public class MyCanvas extends Applet { java.awt.Component canvas; RorF_Choice choiceBox; // Using our own subclassed Choice public void init() { super.init(); URL codebase = getCodeBase(); Image msumap = getImage(codebase, "msumap.gif"); Image selected = getImage(codebase, "selected.gif"); // Manual layout may be used for appletviewer // but should NOT be used for Netscape (it gets confused). // Set the layout to null to override it with manual commands. // // setLayout(null); // may uncomment this line for appletviewer // Set the background color to off-white. setBackground(new Color(0xfaf0e6)); resize(800, 500); add(canvas = new MsuMap(msumap,selected)); canvas.move(43, 20); canvas.resize(600, 500); canvas.show(); add(choiceBox = new RorF_Choice()); // Use our own // removed lines of code were placed in the RorF_Choice constructor // may uncomment the next line if manual layout used for appletviewer // choiceBox.move(650, 49); choiceBox.show(); }

10 // RorF_Choice.java (subclasses Choice) import java.applet.*; import java.awt.*; import java.net.*; public class RorF_Choice extends Choice { public RorF_Choice() { // call parent’s constructor first super(); // place the 3 lines of code from MyCanvas.java here // (use the implicit object “this” instead of “choiceBox”) } public boolean action( Event event, Object obj) { // cast the object argument to a String // print out the event and string now showing on menu System.out.println(“\nPut some message here.”); // return true if event handled successfully // return false if event should be passed to parent return super.action(event,obj); }