Essential Series. Springer-Verlag London Ltd.

Similar documents
Essential Series. Springer-Verlag London Ltd.

John Cowell. Essential Java Fast. How to write object oriented software for the Internet. with 64 figures. Jp Springer

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

Table of Contents. Chapter 1 Getting Started with Java SE 7 1. Chapter 2 Exploring Class Members in Java 15. iii. Introduction of Java SE 7...

Introduction... xv SECTION 1: DEVELOPING DESKTOP APPLICATIONS USING JAVA Chapter 1: Getting Started with Java... 1

Graphics Programming in c++

Supporting Materials

ощ 'ршорвшэш! цвн-эориэу ощ 'sajbpossv # PIPG DUJ 'ssjmoossv ^ PIPG pipa w н OX ЛЮН VAV

Contents. iii Copyright 1998 Sun Microsystems, Inc. All Rights Reserved. Enterprise Services August 1998, Revision B

Murach s Beginning Java with Eclipse

Java Application Development

JAVA. A. Zakiuddin Ahmed. M.Sc.,M.Phil M.S.(Edn), PGDCSM, Professor in Computer Science, P. Rizwan Ahmed. MCA., M.Sc.,M.A., M.Phil.

VALLIAMMAI ENGINEERING COLLEGE

Govt. of Karnataka, Department of Technical Education Diploma in Information Science & Engineering. Fifth Semester

Object Oriented Programming with Java. Unit-1

Sri Vidya College of Engineering & Technology

Mobile MOUSe JAVA2 FOR PROGRAMMERS ONLINE COURSE OUTLINE

The AWT Package, An Overview

SymbolicC++: An Introduction to Computer Algebra using Object-Oriented Programming

Practitioner Series. Springer London Berlin Heidelberg New York Hong Kong Milan Paris Santa Clara Singapore Tokyo

Web Development with Java

Foundations of 3D Graphics Programming

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours

Syllabus & Curriculum for Certificate Course in Java. CALL: , for Queries

Stereo Scene Flow for 3D Motion Analysis

SELF-STUDY. Glossary

Frameworks. CS151 Chris Pollett Oct. 26, 2005.

(listener)... MouseListener, ActionLister. (adapter)... MouseAdapter, ActionAdapter. java.awt AWT Abstract Window Toolkit GUI

Contents Chapter 1 Introduction to Programming and the Java Language

GUI Program Organization. Sequential vs. Event-driven Programming. Sequential Programming. Outline

Contents Introduction 1

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

Software Development & Education Center. Java Platform, Standard Edition 7 (JSE 7)

SD Module-1 Advanced JAVA

1 OBJECT-ORIENTED PROGRAMMING 1

Example Programs. COSC 3461 User Interfaces. GUI Program Organization. Outline. DemoHelloWorld.java DemoHelloWorld2.java DemoSwing.

SD Module-1 Advanced JAVA. Assignment No. 4

Production Methods: Behind the Scenes of Virtual Inhabited 3D Worlds

G51PRG: Introduction to Programming Second semester Applets and graphics

Inside Relational Databases with Examples in Access

DHANALAKSHMI SRINIVASAN COLLEGE OF ENGINEERING AND TECHNOLOGY ACADEMIC YEAR (ODD SEM)

15CS45 : OBJECT ORIENTED CONCEPTS

SRM ARTS AND SCIENCE COLLEGE SRM NAGAR, KATTANKULATHUR

This page intentionally left blank

CSC207H: Software Design Lecture 11

MACMILAN MASTER SBUEI

Object-Oriented Programming and Java

SCHEME OF COURSE WORK

Java Fundamentals p. 1 The Origins of Java p. 2 How Java Relates to C and C++ p. 3 How Java Relates to C# p. 4 Java's Contribution to the Internet p.

E Oracle 10g Java Bootcamp I v1

Programming graphics

Virtualians.ning.pk. 2 - Java program code is compiled into form called 1. Machine code 2. native Code 3. Byte Code (From Lectuer # 2) 4.

"Charting the Course... Java Programming Language. Course Summary

Introduction to Programming Using Java (98-388)

Concurrent, Real-Time and Distributed Programming in Java

B2.52-R3: INTRODUCTION TO OBJECT ORIENTATED PROGRAMMING THROUGH JAVA

Application Development in JAVA. Data Types, Variable, Comments & Operators. Part I: Core Java (J2SE) Getting Started

CS8392 OBJECT ORIENTED PROGRAMMING

CS/B.TECH/CSE(OLD)/SEM-6/CS-605/2012 OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

MyProgram m i ng Lab. get with the programming. Through the power of practice and immediate personalized

Core Java Syllabus. Pre-requisite / Target Audience: C language skills (Good to Have)

C ONTENTS PART I FUNDAMENTALS OF PROGRAMMING 1. and Java 3. Chapter 1 Introduction to Computers, Programs,

Unit - I INTRODUCTION TO OOP AND JAVA FUNDAMENTALS

PESIT Bangalore South Campus

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

Packages: Putting Classes Together

Oracle 10g: Java Programming

Interfacing with C++

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

Java Programming Lecture 6

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

COWLEY COLLEGE & Area Vocational Technical School

HTML p. 1 Introduction to HTML p. 1 Getting Started p. 1 The Structure of an HTML Page p. 1 HTML Basics p. 3 The Weather Forecast Page p.

Java Programming. Price $ (inc GST)

Java Foundations John Lewis Peter DePasquale Joe Chase Third Edition

Big Java Late Objects

Enterprise Networks and Telephony

The init() Method. Browser Calling Applet Methods

John Hunt and Alex McManus. Key Java. Advanced Tips and Techniques

Come & Join Us at VUSTUDENTS.net

Introduction to Java Programming

Core JAVA Training Syllabus FEE: RS. 8000/-

Java & Graphical User Interface II. Wang Yang wyang AT njnet.edu.cn

Casting -Allows a narrowing assignment by asking the Java compiler to "trust us"

Introduction to Java Programming

Punjab Technical University Bachelor in Mobile Computing & Internet Batch 2014 onwards. Semester Fourth

Java 1.8 Programming

CS 3331 Advanced Object-Oriented Programming Final Exam

Fundamentals of the Java Programming Language

Merge Sort Quicksort 9 Abstract Windowing Toolkit & Swing Abstract Windowing Toolkit (AWT) vs. Swing AWT GUI Components Layout Managers Swing GUI

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

The Internet of Things

5. In JAVA, is exception handling implicit or explicit or both. Explain with the help of example java programs. [16]

Overloading Example. Overloading. When to Overload. Overloading Example (cont'd) (class Point continued.)

Introduction to the JAVA UI classes Advanced HCI IAT351

Objective Questions. BCA Part III Paper XIX (Java Programming) page 1 of 5

Object-Oriented Programming and Data Structures

CHAPTER 2. Java Overview

David Parsons. Foundational Java. Key Elements and Practical Programming

Core Java. Basics of Java. String Handling. OOPS Concepts. Exception Handling

Transcription:

Essential Series Springer-Verlag London Ltd.

Also in this series: Essential Visual Basic 4.0 fast 3-540-19998-5 Essential Delphi 2.0 fast 3-540-76026-1 Essential Java fast 3-540-76052-0 Essential Visual Basic 5.0 fast 3-540-76148-9 Duncan Reed and Peter Thomas Essential HTML fast 3-540-76199-3 Essential Delphi 3 fast 3-540-76150-0 John Hunt Essential JavaBeans fast 1-85233-032-5 John Vince Essential Virtual Reality fast 1-85233-012-0 Essential Visual J++ 6.0 fast 1-85233-013-9

Essential Java 2 fast How to develop applications and applets with Java 2, Springer

, BSc(Hons), MPhil, PhD Department of Computer and Information Sciences, De Montfort University Kents Hill Campus, Hammerwood Gate, Kents Hill Milton Keynes, MK7 6HP, UK ISBN 978-1-85233-071-2 British Library Cataloguing in Publication Data Cowell, John, 1957- Essential Java 2 fast: how to develop applications and applets with Java 2. - (Essential series) 1.J ava (Computer program language) I.Title 005.2'76'2 ISBN 978-1-85233-071-2 Library of Congress Cataloging-in-Publication Data Cowell, John, 1957- Essential Java 2 fast: how to develop applications and applets with Java 2/. p. cm. ISBN 978-1-85233-071-2 DOI 10.1007/978-1-4471-0573-2 1. Title. QA76.73.J38C694 1999 005.2'762--dc21 ISBN 978-1-4471-0573-2 (ebook) 99-25430 CIP Apart from any fair dealing for the purposes of research or private study, or criticism or review, as permitted under the Copyright, Designs and Patents Act 1988, this publication may on1y be reproduced, stored or transmitted, in any form or by any means, with the prior permission in writing of the publishers, or in the case of reprographic reproduction in accordance with the terms oflicences issued by the Copyright Licensing Agency. Enquiries concerning reproduction outside those terms should be sent to the publishers. Springer-V erlag London 1999 Originally published by Springer-Verlag London Berlin Heidelberg in 1999 Microsoft, MS, Visual Basic, Windows, Windows 95 and Windows 98 are trademarks of Microsoft Corporation Ltd. Java and Hot Java are trademarks of Sun Microsystems Corporation Ltd. Pentium is a trademark of Intel Corporation Ud. The use of registered names, trademarks etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant laws and regulations and therefore free for general use. The publisher makes no representation, express or implied, with regard to the accuracy of the information contained in this book and cannot accept any legal responsibility or liability for any errors or omissions that may be made. Typesetting: Camera-ready by author 34/3830-5432 Printed on acid-free paper SPIN 10786551

1 WHY JAVA 2 IS SPECIAL... 1 Introduction......... 1 Is this book for you?... 2 What you need to run Java 2... 2 How to use this book... 3 An object-oriented approach... 4 Conventions... 4 2 AN OBJECT-ORIENTED APPLICATION... 6 Introduction... 6 A first application... 7 What can go wrong?... 8 How does the application work?... 8 Classes and objects... 9 The main method... 10 What's new... 11 Running the application... 12 Using classes and objects... 12 Naming conventions... 12 3 THE JAVA LANGUAGE..................... 14 Introduction... 14 Applications and applets... 14 Comments... 14 Terminating Java statements... 15 Data types... 15 The integer data types... 15 The floating point data types... 16 The boolean data type...,... 16 The char data type...... 16 The String data type... 17 Names in Java... 17 Declaring data... 17 Arithmetic in Java... 18 Mixing data types... 18 Casting... 19 v

vi Assignment operators... 20 Using strings in Java... 21 Operator precedence... 22 Displaying information on your screen... 22 4 BRANCHING AND LOOPING... 24 Introduction... 24 The If... else statement... 24 Logical operators... 26 The switch statement... 27 Block statements... 29 Looping... 29 The for loop... 29 The while loop... 31 The do... while loop... 31 The break statement... 32 Arrays... 33 5 CREATING AND USING CLASSES AND OBJECTS... 35 Introduction... '"... 35 The Account class... 35 The displaydetails method... 36 The incredit method... '"... 37 The credit and debit methods... 3 7 The main method... 37 Using constructors... 40 Encapsulating data... 41 Calling methods... 44 Command line arguments for applications....45 6 USIN'G.APPLETS... 47 Introduction... '"... 47 Writing applets... 47 The APPLET tag... 48 Key methods of the Applet class... 50 The init method... 50 The start method... 50 The stop method... 50 The destroy method... 51 The paint method... 51 Command line arguments for applets... 51

vii 7 THE GRAPHICS, COLOR AND FONT CLASSES... 54 Introduction... 54 The co-ordinate frame... 54 Importing classes... 55 The Graphics class... 56 Drawing lines... 56 Drawing rectangles... 57 Drawing circles and ovals... 59 Drawing arcs... 60 Drawing polygons... 61 The Color class... 63 Creating colours... 64 Displaying text and changing fonts... 65 Displaying images... 67 8 INHERITANCE AND POLYMORPHISM... 70 Introduction... 70 A hierarchy of computer components... 70 Defining the Memory subclass... 73 Polymorphism... 74 The MBoard class... 75 Extending a subclass... 76 Class and instance variables... 78 Static methods... 80 Overloading methods... 81 Access control... 82 Interfaces... 84 9 MOUSE AND KEYBOARD EVENTS... 85 Introduction... 85 The MouseEvent class... 85 The MouseListener interface... 87 Which button was pressed?... 90 The MouseAdapter class... 92 The MouseMotionListener interface... 94 The KeyEvent class... 96 The KeyAdapter class... 97 The KeyListener interface... 100 10 THE AWT COMPONENTS... 102 Introduction... 102 Event-driven programming... 102

viii The A WT classes... 102 The Button class... 103 Handling events... 104 The Label class... '"... 106 The Scrollbar class... 107 Handling Scrollbar events... 108 The Checkbox class... 111 The List class... 114 Multiple selection in List objects... 116 The TextComponent class... 118 The TextArea class... 119 Using the TextListener interface... 123 The TextField class... 124 The Canvas class... 12 6 11 THE LAYOUT MANAGERS... 128 Introduction... 128 The FlowLayout class... 128 The BorderLayout class... 130 The CardLayout class... 132 The GridLayout class... 135 The GridBagLayout class... 136 12 WINDOWS, DIALOGS AND MENUS........................ 140 Introduction... 140 The Container class... 140 The Frame class... 141 Creating an application which uses a frame... 141 The WindowListener interface... 144 Creating an applet which uses a frame... 145 The MenuBar class... 1 47 The Dialog class... 1 50 The FileDialog class... 153 The Panel class... 15 9 13 THE SWING COMPONENTS... 162 Introduction... 162 Differences between Swing and A WT components... 162 The Swing components... 163 The Swing container classes... 163 The AbstractButton class... 164 The Swing and A WT buttons... 164 Changing the look and feel... 167

ix The JButton class..................... 171 The IToggleButton, JRadioButton and JCheclcBox classes... 173 Displaying text... 178 The llabel class... 178 The ITextField class... 182 The ITextArea class... 183 The llist class...,... 184 The JColorChooser class... 188 The JFileChooser class... 193 14 JAVA EXCEPTIONS... 198 Introduction........................... 198 The Exception class... 198 The try and catch clauses... ", 198 Throwing an exception... 201 Creating new exceptions... 202 Throwing without catching... 202 15 WRITING THREADED APPLICATIONS 203 Introduction... 203 Pre-emptive scheduling..,... 203 The Runnable interface... 205 The Thread class... 207 Synchronizing threads... 208 The Thread class... 210 Creating animation... 211 The bouncing ball applet... 214 16 FILES AND STREAMS... 218 Introduction... 218 The File class... 218 The InputStream and OutputStream classes... 221 The DatalnputStream and DataOutputStream classes... 224 Using the DataOutputStream class... 225 Using the DatalnputStream class... 229 Reading text flies... 232 Reading from the keyboard... 233 Converting strings to other data types... 234 IN"DEX................................ 236