Hints for Assignment I

Similar documents
Assignment 2. Naming policy. Stack Trace. Actions Internationalization (I18N) Progress Icons Resize. getlastname() setmaxoflines(int i)

Containers and Components

Introduction to the JAVA UI classes Advanced HCI IAT351

CS 251 Intermediate Programming GUIs: Components and Layout

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN

CSSE 220 Day 19. Object-Oriented Design Files & Exceptions. Check out FilesAndExceptions from SVN

Layout. Dynamic layout, Swing and general layout strategies

Graphical User Interfaces in Java - SWING

Layout. Dynamic layout Layout design pattern Layout strategies

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

Layout. Dynamic layout Layout design pattern Layout strategies. 2.6 Layout 2

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

KF5008 Program Design & Development. Lecture 1 Usability GUI Design and Implementation

No SVN checkout today. Object-Oriented Design

The JFrame Class Frame Windows GRAPHICAL USER INTERFACES. Five steps to displaying a frame: 1) Construct an object of the JFrame class

CHAPTER 1: A GENERAL INTRODUCTION TO PROGRAMMING 1

CS11 Java. Fall Lecture 4

Laying Out Components. What is Widget Layout?

Welcome to CIS 068! 1. GUIs: JAVA Swing 2. (Streams and Files we ll not cover this in this semester, just a review) CIS 068

What is Widget Layout? Laying Out Components. Resizing a Window. Hierarchical Widget Layout. Interior Design for GUIs

Part I: Learn Common Graphics Components

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

CS11 Java. Fall Lecture 3

Programming Languages and Techniques (CIS120e)

Basicsof. JavaGUI and SWING

Graphical User Interfaces. Comp 152

To gain experience using GUI components and listeners.

News and info. Array. Feedback. Lab 4 is due this week. It should be easy to change the size of the game grid.

All the Swing components start with J. The hierarchy diagram is shown below. JComponent is the base class.

Midterm assessment - MAKEUP Fall 2010

Java Programming Lecture 6

CS Exam 1 Review Suggestions

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

Swing from A to Z Some Simple Components. Preface

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

Handling XML data with Java

RAIK 183H Examination 2 Solution. November 11, 2013

Control Flow: Overview CSE3461. An Example of Sequential Control. Control Flow: Revisited. Control Flow Paradigms: Reacting to the User

CSE 1325 Project Description

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008

Encapsulation. Administrative Stuff. September 12, Writing Classes. Quick review of last lecture. Classes. Classes and Objects

Object-Oriented Programming (OOP) Basics. CSCI 161 Introduction to Programming I

GUI Applications. Let s start with a simple Swing application in Java, and then we will look at the same application in Jython. See Listing 16-1.

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

This exam is closed textbook(s) and closed notes. Use of any electronic device (e.g., for computing and/or communicating) is NOT permitted.

Graphics programming. COM6516 Object Oriented Programming and Design Adam Funk (originally Kirill Bogdanov & Mark Stevenson)

MIT AITI Swing Event Model Lecture 17

Graphical User Interface (GUI)

Agenda. Container and Component

Resizing a Window. COSC 3461: Module 5B. What is Widget Layout? Size State Transitions. What is Widget Layout? Hierarchical Widget Layout.

Jonathan Aldrich Charlie Garrod

Dr. Hikmat A. M. AbdelJaber

SELF-STUDY. Glossary

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

CS 180 Final Exam Review 12/(11, 12)/08

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Component Based Software Engineering

CmSc 150 Fundamentals of Computing I. Lesson 28: Introduction to Classes and Objects in Java. 1. Classes and Objects

Graphical User Interface (GUI)

Object Oriented Design & Patterns. Part 1

Dot and Scope Resolution Operator

RAIK 183H Examination 2 Solution. November 10, 2014

AP CS Unit 11: Graphics and Events

MARKING KEY The University of British Columbia MARKING KEY Computer Science 260 Midterm #2 Examination 12:30 noon, Thursday, March 15, 2012

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

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

Programming graphics

How to be a Good Bean

SINGLE EVENT HANDLING

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

Java Interfaces Part 1 - Events Version 1.1

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: Graphical User Interfaces (GUI)

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

Java Review. Fundamentals of Computer Science

Part 3: Graphical User Interface (GUI) & Java Applets

Chapter 4 Defining Classes I

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

CS415 Human Computer Interaction

Final Exam CS 251, Intermediate Programming December 13, 2017

Chapter 4: Writing Classes

CS 1316 Exam 3 Fall 2009

Lecture 3: Java Graphics & Events

Java Object Oriented Design. CSC207 Fall 2014

ECE 122. Engineering Problem Solving with Java

Object-Oriented Programming: Revision. Revision / Graphics / Subversion. Ewan Klein. Inf1 :: 2008/09

We are on the GUI fast track path

Review sheet for Final Exam (List of objectives for this course)

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

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

Objects and Classes. Basic OO Principles. Classes in Java. Mark Allen Weiss Copyright 2000

Swing - JButton. Adding buttons to the main window

Packages: Putting Classes Together

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch

CS1004: Intro to CS in Java, Spring 2005

What is Widget Layout? COSC 3461 User Interfaces. Hierarchical Widget Layout. Resizing a Window. Module 5 Laying Out Components

YouTube Break.

State Application Using MVC

UI Software Organization

Transcription:

Hints for Assignment I Department of Information Technology Uppsala University

JDOM

JDOM JDOM is an open source library for Javaoptimized XML data manipulations JDOM was created to... Be straightforward for Java programmers Use the power of the Java language (method overloading, collections, reflection) Hide the complexities of XML wherever possible

Documents Documents are represented by org.jdom.document They may be constructed from scratch: Document doc = new Document(new Element("root")); Or built from a file, stream, systemid, URL: SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(url);

JDOM To create a simple document in JDOM: Document doc = new Document(); Element e = new Element("root"); e.settext("this is the root"); doc.addcontent(e);

Same thing (Power User) // Needs more documenting, though Document doc = new Document( new Element("root").setText( "This is the root") );

Output is very flexible Exporting to XML Document doc = new Document(...); XMLOutputter outp = new XMLOutputter(); // Raw output outp.output(doc, fileoutputstream); // Compressed output outp.settexttrim(true); outp.output(doc, socket.getoutputstream()); // Pretty output outp.setindent(" "); outp.setnewlines(true); outp.output(doc, System.out);

Element Class The XML tree consists of Elements // Get the root element Element root = doc.getrootelement(); // Get a list of all child elements List allchildren = root.getchildren(); // Get only elements with a given name List namedchildren = root.getchildren("name"); // Get the first element with a given name Element child = root.getchild("name"); NOTE! The List stuctures are java.util.list

The List is live! Active List List allchildren = root.getchildren(); //!!!! // Remove the fourth child allchildren.remove(3); // Remove children named "jack allchildren.removeall(root.getchildren("jack")); root.removechildren("jack"); // convenience // Add a new child allchildren.add(new Element("jane")); root.addcontent(new Element("jane")); // conv. allchildren.add(0, new Element("first"));

Element Content An Element may have text content <description> A cool demo </description> // The text is directly available // Returns "\n A cool demo\n" String desc = element.gettext(); // There's a convenient shortcut // Returns "A cool demo" String desc = element.gettexttrim();

Element Content Text content can be changed directly element.settext("a new description"); Special chars are interpreted correctly element.settext("<xml> content");

Unnecessary knowledge Orange (UK Telecom) used JDOM to support their B2B system "Orange API A "Where is my nearest" WAP service handles 1,000 requests per minute That's just 1 of 40 services built on XML All their XML processing uses JDOM JDOM supports an XML-RPC/SOAP framework now deployed globally Source: Jools Enticknap, Orange

XML

XML If you have problems with the XML part Read the suggested Links on the homepage

Assignment hints

Other things to consider Cohesion One class performs a set of closely related actions Decoupling classes should not depend on the structure of each other Communication through accessors and methods Flexibility awareness of the need for change in the solutions.

Collections TIJ/Eckel: chapter 11, Collections of Objects Read about containers, skip arrays List stores objects in sequence Important for the use of JDOM Set stores unique objects in a space Map manages key/value pairs

Abstraction Iterators you don t care about the storage structure Iterators are lightweight and do not consume a lot of resources Iterator it = collection.iterator(); while (it.hasnext()) { } Object o = it.next();

Swing Lightweight components Are not created by the operating system but by the jvm Reacts in the same way in different environments or operating systems Highly extendible Java library

Java Beans JavaBeans are reusable software components for Java that can be manipulated visually in a builder tool. The class must have a public default constructor. The class properties must be accessible using getters, setters, and other methods (so-called accessor methods and mutator methods), following a standard naming convention. The class should be serializable.

Access control! Public: can be accessed from anywhere. Private: can be accessed only from within the class in which the field or method is declared. Protected: can be accessed within the package, or from outside the package by a subclass of the class in which the members declared. Package: can be accessed within the package (it is the default)

ActionListener (AL) // This is not OOP class Foo implements ActionListener { Foo() { JButton b = new JButton(); b.addactionlistener(this); // ugly! } } public void actionperformed(actionevent e) { } // do the stuff

AL 2 // Sometimes ok, mostly not class Foo { class Bar implements ActionListener { public void actionperformed(actionevent e) { // doit } } } Foo() { JButton b = new JButton(); b.addactionlistener(new Bar()); }

AL 3 // Good! class Foo { } Foo() { JButton b = new JButton(); } b.addactionlistener(new ActionListener() { } }); public void actionperformed(actionevent e) { // doit

AL 2.1 class Foo { class Bar implements ActionListener { public void actionperformed(actionevent e) { // doit } } } Foo() { Bar bar = new Bar(); JButton b1 = new JButton(); JButton b2 = new JButton(); b1.addactionlistener(bar); // smart, shares action b2.addactionlistener(bar); }

AL 4 scope? class Foo { private int i; } Foo() { int k = 0; final m = 0; JButton b = new JButton(); b.addactionlistener(new ActionListener() { public void actionperformed(actionevent e) { // can see i and m, not k } }); }

INTERFACE

Thinking about the interface First attempt - keep it simple Get it working Think of alternative designs Different in principle, not detail What are the effects on the differences? What are the benefits of each alternative? What are the difficulties with each alternative?

LayoutManagers BorderLayout (!) BoxLayout CardLayout FlowLayout GridBagLayout (!) GridLayout (GroupLayout) SpringLayout Learn how to use them!

A simple interface structure Window Frame [Jframe] Panel Jpanel Layoutmanager Widgets Jbutton Jlabel Jslider Etc.

Versionings systems (CVS, SVN)

Subversion and CVS A system for versioning in software projects IDE supported One server per group Common file structure Password protected

DIARY

Project Diary Individual diaries Automatic time reporting Can be read by all in group Should be used daily Whenever you do something on the project Part of the examination Details will be sent via email

Group work Make sure that all group members have access to the SVN system Check that you can access the project diary Exchange email addresses (!) Make a plan for the work Remember that project groups can work on distance: SVN, MSN, Skype, Diary notes

START

Assignment 1 Create the application with a simple interface Make sure that it runs properly Document the code (!) Pack in a jar-file and send in

Problems Assignment, Java: Simon, (Lars) Diary: Mikael SVN: Simon Other problems: Lars Simon: room 1157 Mikael: room 1254 Lars: room 11257

Check your diary and get in contact via mail(hint: use Studentportalen) If you have problems finding your group members get in touch with us as soon as possible