JApplet. toy example extends. class Point { // public int x; public int y; } p Point 5.2. Point. Point p; p = new Point(); instance,

Similar documents
Introduction. Introduction

Inheritance (cont.) Inheritance. Hierarchy of Classes. Inheritance (cont.)

Day before tests of Java Final test. IDM institution of Bandarawela. Project for department of education

MIT AITI Swing Event Model Lecture 17

GUI 4.1 GUI GUI MouseTest.java import javax.swing.*; import java.awt.*; import java.awt.event.*; /* 1 */

ASSIGNMENT NO 14. Objectives: To learn and demonstrated use of applet and swing components

Swing - JTextField. Adding a text field to the main window (with tooltips and all)

/* Write a Program implementing GUI based Calculator using Swing */

JAVA Swings Sample Codes CODE NO: EduLanka Sample Java Codes - ONLINE JAVA

What Is an Event? Some event handler. ActionEvent. actionperformed(actionevent e) { }

Java - Applets. public class Buttons extends Applet implements ActionListener

CS 251 Intermediate Programming GUIs: Components and Layout

Graphics User Defined Forms, Part I

Question 1. Show the steps that are involved in sorting the string SORTME using the quicksort algorithm given below.

SINGLE EVENT HANDLING

Name Section. CS 21a Introduction to Computing I 1 st Semester Final Exam

Java Programming Lecture 6

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing

CHAPTER 2. Java Overview

JRadioButton account_type_radio_button2 = new JRadioButton("Current"); ButtonGroup account_type_button_group = new ButtonGroup();

TTTK Program Design and Problem Solving Tutorial 3 (GUI & Event Handlings)

Window Interfaces Using Swing Objects

An array is a type of variable that is able to hold more than one piece of information under a single variable name.

Midterm Test II Object Oriented Programming in Java Computer Science, University of Windsor Fall 2014 Time 2 hours. Answer all questions

Example 3-1. Password Validation

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,

Dr. Hikmat A. M. AbdelJaber

Example: Building a Java GUI

Example: Building a Java GUI

Java. GUI building with the AWT

Lecture 5: Java Graphics

H212 Introduction to Software Systems Honors

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

Java Intro 3. Java Intro 3. Class Libraries and the Java API. Outline

Command-Line Applications. GUI Libraries GUI-related classes are defined primarily in the java.awt and the javax.swing packages.

Chapter #1. Program to demonstrate applet life cycle

Introduction to Graphical Interface Programming in Java. Introduction to AWT and Swing

Chapter 1 GUI Applications

UTM CSC207: Midterm Examination October 28, 2011

CMP 326 Midterm Fall 2015

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

The first version of the bank will look like this:

GUI Forms and Events, Part II

GUI and its COmponent Textfield, Button & Label. By Iqtidar Ali

Packages: Putting Classes Together

AP CS Unit 11: Graphics and Events

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in

Window Interfaces Using Swing Objects

1 GUI GUI GUI GUI GUI. GUI(Graphical User Interface) JDK java.awt. ? Component

Swing - JLabel. Adding a text (and HTML) labels to a GUI

DEMYSTIFYING PROGRAMMING: CHAPTER FOUR

Graphical User Interface (GUI) components in Java Applets. With Abstract Window Toolkit (AWT) we can build an applet that has the basic GUI

Lecture Static Methods and Variables. Static Methods

JFrame & JLabel. By Iqtidar Ali

Extra Credit Lab. Your job is to catch any syntax errors a user might make. Two examples follow. In the panel on the left the user has used

CSC 1214: Object-Oriented Programming

Interfaces & Polymorphism part 2: Collections, Comparators, and More fun with Java graphics

AP CS Unit 12: Drawing and Mouse Events

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling

Swing from A to Z Some Simple Components. Preface

RAIK 183H Examination 2 Solution. November 11, 2013

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

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

Swing Programming Example Number 2

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread

Graphical Interfaces

University of Cape Town Department of Computer Science. Computer Science CSC117F Solutions

University of Cape Town ~ Department of Computer Science. Computer Science 1016S / 1011H ~ November Exam

Building Java Programs Bonus Slides

CSE 331. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

1.00/1.001 Introduction to Computers and Engineering Problem Solving Fall (total 7 pages)

navlakhi.com / navlakhi.education / navlakhi.mobi / navlakhi.org 1

THE UNIVERSITY OF AUCKLAND

CS 134 Programming Exercise 7:

Gracefulness of TP-Tree with Five Levels Obtained by Java Programming

Course Status Networking GUI Wrap-up. CS Java. Introduction to Java. Andy Mroczkowski

17 GUI API: Container 18 Hello world with a GUI 19 GUI API: JLabel 20 GUI API: Container: add() 21 Hello world with a GUI 22 GUI API: JFrame: setdefau

JAVA NOTES GRAPHICAL USER INTERFACES

Give one example where you might wish to use a three dimensional array

Graphical User Interfaces (GUIs)

Java Swing. Recitation 11/(20,21)/2008. CS 180 Department of Computer Science, Purdue University

Java Swing. based on slides by: Walter Milner. Java Swing Walter Milner 2005: Slide 1

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

Lecture 3: Java Graphics & Events

DEMYSTIFYING PROGRAMMING: CHAPTER SIX METHODS (TOC DETAILED) CHAPTER SIX: METHODS 1

Java Programming Language Mr.Rungrote Phonkam

Multiple Choice Questions: Identify the choice that best completes the statement or answers the question. (15 marks)

protected void printserial() { System.out.println("> NO." + this.serialno); this.serialno++; }

CONTENTS. Chapter 1 Getting Started with Java SE 6 1. Chapter 2 Exploring Variables, Data Types, Operators and Arrays 13

Java Applet Basics. Life cycle of an applet:

Graphic User Interfaces. - GUI concepts - Swing - AWT

State Application Using MVC

Chapter 12 Advanced GUIs and Graphics

RAIK 183H Examination 2 Solution. November 10, 2014

Programming Language Concepts: Lecture 8

CORBA Java. Java. Java. . Java CORBA. Java CORBA (RMI) CORBA ORB. . CORBA. CORBA Java

User interfaces and Swing

Queens College, CUNY Department of Computer Science. CS 212 Object-Oriented Programming in Java Practice Exam 2. CS 212 Exam 2 Study Guide

Final Examination Semester 2 / Year 2011

Transcription:

35 5 JApplet toy example 5.1 2 extends class Point { // public int x; public int y; Point x y, 5.2 Point int Java p Point Point p; p = new Point(); Point instance, p Point int 2

36 5 Point p = new Point(); p.x = 1; p.y = 2; System.out.println("(" + p.x + ", " + p.y + ")");. 5.3 C, class Point { // ( public int x; public int y; // public void move(int dx, int dy) { x += dx; y += dy; public void print() { System.out.print("(" + x + ", " + y + ")"); // public Point(int x0, int y0) { x = x0; y = y0; move print x, y. Point int 2 Point p = new Point(1, 2); x 1 y 2 PointTest Point main

5.4. 37 public class PointTest { public static void main(string args[]) { Point p = new Point(10, 20); p.move(1, -1); p.print(); System.out.println("<br>"); static main static C C++ PointTest.java Point public public Point PointTest Point public javac PointTest.java java PointTest 5.4 Point ColorPoint Point Point Point ColorPoint ColorPoint Point extends class ColorPoint extends Point { public String color; public ColorPoint(int x, int y, String c) { super(x, y); /* 1 */ color = c; public void print() { System.out.print("<font color= "+color+ >"); // System.out.print("(" + x + ", " + y + ")"); // super.print(); System.out.print("</font>"); // ColorPoint color print() Applet super(x, y) /* 1 */ Point super

38 5 print() HTML HTML ColorPoint print() 2 /* 2 */ Point print() super.print(); Point x y move /* 2 */ public static void main(string args[]) { ColorPoint cp = new ColorPoint(10, 20, "green"); cp.move(1, -1); cp.print(); System.out.println("<br>"); (11, 19) 5.5 color "red", "green" 2 setcolor getcolor ColorPoint "black", "red", "green", "yellow","blue", "magenta", "cyan", "white" color int 1 class ColorPoint extends Point { public String[] cs = {"black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", ""; public int color; // 0-1- 2-3- 4-5- 6-7- public void print() { System.out.print("<font color= "+getcolor()+" >"); // System.out.print("(" + x + ", " + y + ")"); super.print();// System.out.print("</font>"); public void setcolor(string c) { int i; for (i=0;!cs[i].equals(""); i++) { if (c.equals(cs[i])) { color = i; return; // public ColorPoint(int x, int y, String c) { super(x, y); setcolor(c); public String getcolor() { return cs[color]; // // 1 color int

5.5. 39 setcolor getcolor color 0 7 p.color = 100; public ColorPoint color private int color; // color cs p.color = 100; public 2 private, public, protected public ColorPoint color "black", "red" 5.5.1 ColorPoint color "black", "red" 5.5.2 DeepPoint Point int depth print depth 5 DeepPoint (((((11, 19))))) 5 1. DeepPoint 2. depth 1 10 setdepth getdepth 5.5.3 SecretPoint Point 2 int a, b print a x+b y = 1 (1, 2) (?,?) SecretPoint 2 protected

40 5 5.6 public static void main(string args[]) { Point p = new Point(1, 2); ColorPoint cp = new ColorPoint(3, 4, "green"); DeepPoint dp = new DeepPoint(5, 6, 5); Point, ColorPoint, DeepPoint 3 Point 3 Point[] pts = new Point[3]; pts[0] = p; pts[1] = cp; pts[2] = dp; ColorPoint DeepPoint Point, widening move int i; for (i=0; i<3; i++) { pts[i].move(10, 10); move print for (i=0; i<3; i++) { pts[i].print(); System.out.println("<br>"); print ColorPoint, DeepPoint? Java print (11, 12) (13, 14) (((((15, 16)))))

5.6. 41 C++ Java Point, ColorPoint, DeepPoint Point* pts[3]; Point* p = new Point(1, 2); ColorPoint* cp = new ColorPoint(3, 4, "green"); DeepPoint* dp = new DeepPoint(5, 6, 5); pts[0] = p; pts[1] = cp; pts[2] = dp; for (i=0; i<3; i++) { pts[i]->print(); cout << "<br>y=n"; Point print (11, 12) (13, 14) (15, 16) C++ Java print pts[i] p, cp, dp Java C++ virtual class Point { // : C++ public: int x, y; void move(int dx, int dy); virtual void print(void); ; C++ static void moveinsquare(point p) { p.move(1, 0); p.print(); System.out.print(" "); p.move(0, 1); p.print(); System.out.print(" "); p.move(-1, 0); p.print(); System.out.print(" "); p.move(0, -1); p.print(); System.out.println("<br>"); moveinsquare ColorPoint DeepPoint print 3

42 5 3 Poly 4 Morph 1 (GUI) Java / Button, Label, TextField, TextArea GUI Component java.awt.component Component setvisible, setenabled, setlocation 5.6.1 HideShow.java import javax.swing.*; import java.awt.*; import java.awt.event.*; public class HideShow extends JApplet implements ActionListener { JTextField input; JLabel l1; JButton b1, b2; public void init() { l1 = new JLabel("label"); input= new JTextField("text", 5); b1 = new JButton("Hide"); b1.addactionlistener(this); b2 = new JButton("Show"); b2.addactionlistener(this); getcontentpane().setlayout(new FlowLayout()); getcontentpane().add(l1); getcontentpane().add(input); getcontentpane().add(b1); getcontentpane().add(b2); public void actionperformed(actionevent e) { if (e.getsource()==b1) { l1.setvisible(false); input.setvisible(false); b1.setvisible(false); else if (e.getsource()==b2) { l1.setvisible(true); input.setvisible(true); b1.setvisible(true); repaint(); 3 4 =

5.6. 43 Hide setvisible Component Component add = setvisible,,,