© copyright Janson Industries 2014

Slides:



Advertisements
Similar presentations
Java GUI building with the AWT. AWT (Abstract Window Toolkit) Present in all Java implementations Described in (almost) every Java textbook Adequate for.
Advertisements

Java Graphical User Interface (GUI) using Visual Editor in eclipse CSI 1390 – Java Programming Instructor: Saeid Nourian University.
KompoZer. This is what KompoZer will look like with a blank document open. As you can see, there are a lot of icons for beginning users. But don't be.
Using Eclipse. Getting Started There are three ways to create a Java project: 1:Select File > New > Project, 2 Select the arrow of the button in the upper.
Event Driven Programming and GUIs Part 3 CS221 – 4/15/09.
1 Mobile Computing Mobile First (formerly Worklight) Copyright 2015 by Janson Industries.
1 Frameworks. 2 Framework Set of cooperating classes/interfaces –Structure essential mechanisms of a problem domain –Programmer can extend framework classes,
Chapter 6 Graphical User Interface (GUI) and Object-Oriented Design (OOD)
Java Integrated Development Environments: ECLIPSE Part1 Installation.
2. Introduction to the Visual Studio.NET IDE 2. Introduction to the Visual Studio.NET IDE Ch2 – Deitel’s Book.
OOP Languages: Java vs C++
Java: Chapter 1 Computer Systems Computer Programming II Aug
1 Intro to Programming & Algorithm Design Overview Copyright 2014 by Janson Industries Assg1Assg1 Assg2Assg2.
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
20-753: Fundamentals of Web Programming Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 16: Java Applets & AWT Fundamentals of Web Programming.
Writing Classes (Chapter 4)
1 v1.6 08/02/2006 Overview of Eclipse Lectures 1.Overview 2.Installing and Running 3.Building and Running Java Classes 4.Refactoring 5.Debugging 6.Testing.
Chapter 1a© copyright Janson Industries RAD ▮ Explain Eclipse, RAD, and their relationship ▮ Basic RAD concepts ▮ How to install RAD ▮ How to import.
Java: Chapter 1 Computer Systems Computer Programming II.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
Intro to GUIs (Graphical User Interfaces) Section 2.5Intro. to GUIs: a GUI Greeter Section 3.7Graphical/Internet Java: Einstein's Equation.
Learn about the types of Graphics that are available Develop a basic Graphics applet Develop a basic Graphics application Review the Java API and use.
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Lesson 27: Introduction to the Java GUI. // helloworldbutton.java import java.awt.*; import javax.swing.*; class HelloButton{ public static void main.
Applets and Frames CS 21a: Introduction to Computing I First Semester,
11 Web Services. 22 Objectives You will be able to Say what a web service is. Write and deploy a simple web service. Test a simple web service. Write.
Chapter 1© copyright Janson Industries Java ▮ Java programming concepts ▮ Downloading the JDK ▮ Java coding and executing example This presentation.
Tutorial 111 The Visual Studio.NET Environment The major differences between Visual Basic 6.0 and Visual Basic.NET are the latter’s support for true object-oriented.
Chapter 13. Applets and HTML HTML Applets Computer Programming with JAVA.
Copyright © Curt Hill Turtles The beginning of media computation.
Copyright © Curt Hill First Window Builder Program Easy GUIs in Eclipse.
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
HTML Concepts and Techniques Fifth Edition Chapter 6 Using Frames in a Web Site.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
9/2/ CS171 -Math & Computer Science Department at Emory University.
Graphics and Event-Driven Programming in Java John C. Ramirez Department of Computer Science University of Pittsburgh.
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.
Concurrent Programming and Threads Threads Blocking a User Interface.
Java Applets: GUI Components, Events, Etc. Ralph Westfall June, 2010.
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.
1 CSE1340 Class 4. 2 Objectives Write a simple computer program in Java Use Swing components to build the GUI Use proper naming conventions for classes.
1 CSC/ECE 517 Fall 2010 Lec. 3 Overview of Eclipse Lectures Lecture 2 “Lecture 0” Lecture 3 1.Overview 2.Installing and Running 3.Building and Running.
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming – Home and reload buttons for the webbrowser, Applets.
Chapter 2© copyright Janson Industries Java ▮ Java/PC programming environment ▮ Java syntax rules ▮ Java documentation ▮ Java/RAD coding example.
1 GUI programming Graphical user interface-based programming Chapter G1 (pages )
Class Builder Tutorial Presented By- Amit Singh & Sylendra Prasad.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Week101 APCS-AB: Java Miscellaneous Topics: Snippets we missed in Chapters 1-6 of book November 11, 2005.
Chapter 5 Introduction To Form Builder. Lesson A Objectives  Display Forms Builder forms in a Web browser  Use a data block form to view, insert, update,
Creating a Java Application and Applet
Chapter 4© copyright Janson Industries More GUI ▮ Events, Actions, and Listeners ▮ The Visual Editor ▮ More GUI component properties Non-graded assg.
Chapter 12© copyright Janson Industries Java Server Faces ▮ Explain the JSF framework ▮ SDO (service data objects) ▮ Facelets ▮ Pagecode classes.
Microsoft Office 2013 Try It! Chapter 4 Storing Data in Access.
Graphical User Interface (GUI) Two-Dimensional Graphical Shapes.
M1G Introduction to Programming 2 2. Creating Classes: Game and Player.
Chapter 10 - Writing Graphical User Interfaces1 Chapter 10 Writing Graphical User Interfaces.
Lesson 28: More on the GUI button, frame and actions.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
XP New Perspectives on Macromedia Dreamweaver MX 2004 Tutorial 5 1 Adding Shared Site Elements.
5-1 GUIs and Events Rick Mercer. 5-2 Event-Driven Programming with Graphical user Interfaces  Most applications have graphical user interfaces to respond.
Chapter 1a© copyright Janson Industries RAD ▮ Explain Eclipse, RAD, and their relationship ▮ Basic RAD concepts ▮ How to install RAD ▮ How to import.
Module Road Map Refactoring Why Refactoring? Examples
Lecture 27 Creating Custom GUIs
Ellen Walker Hiram College
Overview of Eclipse Lectures
UNIT-5.
Constructors, GUI’s(Using Swing) and ActionListner
The beginning of media computation Followed by a demo
Presentation transcript:

© copyright Janson Industries 2014 GUI Java Explain difference between: Applications/Applets/Servlets AWT/Swing/SWT Inheritance Basic AWT visual components UML (Unified Modeling Language) Non-graded assg part 1 part2 Chapter 3 © copyright Janson Industries 2014

Apps/Applets/Servlets Apps are stored & executed on the client PC Applets are “called” by a web page. The applet’s Java code Stored on the server Downloaded to the client PC Run by the client browser Servlets are stored and run on the server Servlets generate HTML that is sent to the client’s browser Chapter 3 © copyright Janson Industries 2014

Apps/Applets/Servlets Stored on client Run on client Stored on server Run on server Apps X Applets Servlets Chapter 3 © copyright Janson Industries 2014

Apps/Applets/Servlets Stored on Run on Apps client Applets server Servlets Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Client Apps Client based apps Adv: Fast: execute on client, no communication lag No catastrophic failure Client based apps DisAdv: Must install app on each client computer Multiple copies of app: Take up more space Updating app more difficult/time consuming Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Server Apps Server based apps Adv: Accessible from any computer with a browser One copy of app Takes up little space Updates to app are fast Server based apps DisAdv: Catastrophic failure – server goes out, no processing can occur Communication time lag – especially with applets Must download entire application before executing Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Java GUI Components Many sets of GUI components: AWT (Advanced Windowing Toolkit) Swing SWT (Simple Widget Toolkit) AWT implements each H/W platform’s version of the GUI components Swing is consistent across all H/W (but takes longer to “paint” the GUI) Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 GUI Java As much as possible, SWT implements each H/W’s platforms version of the GUI components Provides the added Swing components and functions Works differently than AWT and Swing Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 GUI Java AWT and Swing have similar sets of GUI components stored in packages (that are part of the JDK): Frame - JFrame Button - JButton TextField - JTextField Label - JLabel To use the GUI components, must “import” the AWT or Swing classes into your class Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 GUI Java FRAME JFRAME Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Using GUI Components AWT GUI classes in java.awt package You can use them by fully specifying their location java.awt.Label empName = new java.awt.Label(); Or, use the import statement to identify the java.awt package import tells complier to look in that location for any non-fully specified classes Sorta like the path and classpath but for the compiler not JVM or Windows Chapter 3 © copyright Janson Industries 2014

This make GUIEx a subclass of Frame GUI Components Using import allows easier access to the GUI components because you don’t have to fully specify the location of the GUI component // GUIEx.java import java.awt.*; public class GUIEx extends Frame { : : : We define this class as a Frame with the extends “clause” in the class header This make GUIEx a subclass of Frame Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Subclass/Superclass Subclasses inherit all methods and variables of the superclass (also called Specialization) You can create superclasses to hold common information and functions For instance: A Person superclass with name, address, and phone number variables Subclasses Employee, Customer, and Supplier would all get these variables Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Subclass/Superclass Person String name, addr, phnum; Employee extends Person String EmpNum; name = "Joe"; addr="1 1st St"; phnum="111-1111"; Customer extends Person String CustNum; name = "Mary"; addr="2 2nd St"; phnum="222-2222"; Supplier extends Person String SuppNum; name = "Pat"; addr="3 3rd St"; phnum="333-3333"; Subclasses inherit all methods and variables of the superclass (aka Specialization) Chapter 3 © copyright Janson Industries 2014

Create a new class (Cust2) – File, New, Class Click Browse... Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Start typing “Frame”, select Frame, (and make sure its from the java.awt package), click OK then Finish Chapter 3 © copyright Janson Industries 2014

RAD creates a bare minimum class Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Labels Display constant text on a frame Must define a label object and, optionally, set it’s text property Label custNameLabel = new Label(“Joe Customer"); Chapter 3 © copyright Janson Industries 2014

Click light bulb icon to get possible solutions But you get an error Click light bulb icon to get possible solutions Chapter 3 © copyright Janson Industries 2014

RAD will list solutions with most likely at top Click a solution to show the solution code Double click solution to insert code Chapter 3 © copyright Janson Industries 2014

What happens if you click the Run button and why? Chapter 3 © copyright Janson Industries 2014

When running, RAD first suggests saving changes It’s usually a good idea: click OK Chapter 3 © copyright Janson Industries 2014

Gotcha: if you click the Run button, RAD will run Cust1 (the last application that was run) Chapter 3 © copyright Janson Industries 2014

Can display the Run drop down menu Notice Cust1 is the first listed Run Configuration This means it is the default application to be run Can click Run Configurations... Chapter 3 © copyright Janson Industries 2014

What’s going to happen and why? Specify Cust2 Click Run What’s going to happen and why? Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Oops, forgot to create a main method that instantiates (creates) a Cust2 object Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Getting Cust2 to work Since Cust2 will be instantiated you need A constructor for the class (i.e. must have method called Cust2) In addition, to get the frame and labels to work you must set their properties: Define sizes for the frame and labels Position the labels on the frame Make the frame visible Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Frames In the constructor, specify: this.setSize(600, 400); this.setLayout(null); (this refers to “this object”, i.e. the Cust2 frame) Layout null tells the system not to use the predefined BorderLayout You will position the components individually Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Labels In constructor, set label size & location: labelVariableName.setSize(length, height) labelVariableName.setLocation(from left, from top) Numbers are in pixels Example (after the label object is created and after this.setLayout(null);) add: custNameLabel.setSize(100,10); custNameLabel.setLocation(155,135); Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Labels In the constructor, after the label properties are set, add the label to the frame object (referred to as this) this.add(custNameLabel); At the end of the constructor, make the frame visible this.setVisible(true); Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 main method In the main method, must create a Cust2 object We will assign it to a variable called custTest Cust2 custTest = new Cust2(); (Actually, don't need to create variable and assign object because we will not reference the Cust2 object) Time to run! Chapter 3 © copyright Janson Industries 2014

Display Run menu – notice Cust2 is default launch Click Cust2 to run Chapter 3 © copyright Janson Industries 2014

Results in Cust2 object being created (instantiated) Chapter 3 © copyright Janson Industries 2014

Steps to Create and Display a Working Frame 1. Create a class as a subclass of Frame 2. Set the following Frame properties: Layout to null Size Location (optional) Visible to true 3. To view the frame, create an instance of the Frame subclass Chapter 3 © copyright Janson Industries 2014

How to Create a Working Label 1. Import the Label class 2. Create a Label object 3. Set the following label properties: Size Location Text (optional) 4. Add the label to the frame Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Cust2 (or any Frame subclass) does not inherit a close function from Frame To close the frame, click the Terminate button in the Console pane tool bar Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Non Graded Assg – Part 1 Create Cust2 so it displays the same info as Customer but in a frame with 3 labels import java.awt.Frame; import java.awt.Label; public class Cust2 extends Frame { Label custNameLabel = new Label("Joe Customer"); Label custAddressLabel = new Label("123 Main St."); Label custCSZLabel = new Label("Jax, FL 32246"); public Cust2(){ this.setSize(600, 400); this.setLayout(null); custNameLabel.setSize(100,10); custNameLabel.setLocation(155,135); this.add(custNameLabel); custAddressLabel.setSize(100,10); custAddressLabel.setLocation(155,155); this.add(custAddressLabel); custCSZLabel.setSize(100,10); custCSZLabel.setLocation(155,175); this.add(custCSZLabel); this.setVisible(true); } public static void main(String[] args){ Cust2 custTest = new Cust2(); Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Instead of displaying static info, we can pass the frame info to display Like Cust1 did Chapter 2 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Passing Info Need to change the frame's constructor to: Accept info Set the label value to the passed info Chapter 3 © copyright Janson Industries 2014

Passing Info Constructor must accept info Constructor must set label value Info must be passed Chapter 3 © copyright Janson Industries 2014

Passing Info If 2 pieces of info need to be passed, public Cust3(String name, String address){… Problem: if 7 pieces of info need to be passed, How easy is it to remember what’s the order? When is phone # passed: First? Second? Sixth? Solution: object properties Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Properties Already worked with properties Label text and location, Frame size and layout In a class, each property is: Defined as a private class variable Has a getter method that returns the property value Has a setter method (usually with validation functions) that sets the value of the property Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Properties Usually you will create an object Then manipulate the object properties We created a label, then set its size, location, text For instance: We’ll redefine the Customer class to have properties that hold the following info: Contact Person, Customer Name, Phone Number, Ship to Address Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Creating Properties Define private variables for each property Chapter 3 © copyright Janson Industries 2014

Let RAD create the getters and setters Click Source then Generate Getters and Setters... Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Properties Select getters and setters or click Select All Can specify Where methods should be in the class How they are grouped Click OK button Generates 14 methods Chapter 3 © copyright Janson Industries 2014

Can't fit all getters/setters in work area Can see them all in the outline Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Using Properties Just as you set Frame and Label object properties, a Customer object’s properties can now be set Then pass the Customer variable (assigned to the Customer object) instead of individual variables/values We will modify the customer application so that a Customer variable is passed to a Customer Frame Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Using Properties A new class CustApp will be used to "kick off the application" This means CustApp will: Create a Customer object and assign it to a Customer variable Set the Customer object's properties Create a Customer Frame object and pass it the Customer variable (instead of individual variables/values) Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 New Customer Example 1 CustApp creates a Customer object, assigns to variable c, sets object’s properties Customer Object 3 CustFrame retrieves & displays Customer object properties 2 CustApp creates a CustFrame object, assigns to variable cf, and sends Customer variable c CustFrame Object CustApp Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 New Customer Example Customer Object 1 3 Data Data 2 CustApp creates a CustFrame object, assigns to variable cf, and sends Customer variable c CustFrame Object CustApp Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Using Properties Create a new Frame subclass CustFrame CustFrame constructor accepts a variable of type Customer and assigns it to a variable named cust CustFrame has four labels custName shipToLbl1 shipToLbl2 contactInfo CustFrame retrieves info from the Customer object and puts the info into the labels Chapter 3 © copyright Janson Industries 2014

Select project (JavaCourse) then File, New, Class Specify name of Class and superclass Chapter 3 © copyright Janson Industries 2014

Cust Frame Need to define a constructor to accept a Customer variable Initial code import java.awt.Frame; public class CustFrame extends Frame { } Need to define a constructor to accept a Customer variable Chapter 3 © copyright Janson Industries 2014

Programming Technique We will code portions of the class, then test each portion as it is created Incremental coding makes finding errors easier If a new method is added and RAD shows an error, it has something to do with the new code If all the methods coded at once results in 42 errors, harder to determine what the errors are Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Cust Frame import java.awt.Frame; public class CustFrame extends Frame { public CustFrame(Customer cust) { } Even though CustApp passes a variable called c, CustFrame stores it in a variable named cust Don’t forget, for frame to work need to: Size the frame : this.setSize(300, 282); Set layout to null: this.setLayout(null); Set visible: this.setVisible(true); Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Cust Frame Labels Import the Label class: import java.awt.Label; Create 4 label objects and assign to variables Size and position the labels Label custNameLbl = new Label(); Label shipToLbl1 = new Label(); Label shipToLbl2 = new Label(); Label contactInfo = new Label(); custNameLbl.setBounds(62, 65, 176, 23); shipToLbl1.setBounds(62, 120, 176, 23); shipToLbl2.setBounds(62, 175, 176, 23); contactInfo.setBounds(62, 230, 176, 23); Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Cust Frame Labels Set some test text Add the labels to the frame Test it : what do we need? custNameLbl.setText("test text"); shipToLbl1.setText("test text"); shipToLbl2.setText("test text"); contactInfo.setText("test text"); this.add(custNameLbl); this.add(shipToLbl1); this.add(shipToLbl2); this.add(contactInfo); Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 CustFrame Labels Code a main method in CustFrame to create a CustFrame object (to test so far) public static void main(String[] args) { Customer c = new Customer(); CustFrame cf = new CustFrame(c); } In class assg: Try it! Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Cust Frame Labels Need code to retrieve data from Customer object and put into labels Use Customer object getter to retrieve a property value Could do like this String tempName = cust.getCustName(); custNameLbl.setText(tempName); String tempStreet = cust.getShipToStreet(); shipToLbl1.setText(tempStreet); Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Cust Frame Labels More efficient to do like this Two less statements no temp variables These labels are easy: one getter retrieves one label’s text Need to use concatenation for other label’s text I.e. multiple getter return values go into these labels custNameLbl.setText(cust.getCustName()); shipToLbl1.setText(cust.getShipToStreet()); Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Concatenation Combines 2 strings into one String a = new String(“Sam”); String b = new String(“I am”); a + b would be equal to “SamI am” Use concatenation (+) to combine multiple property values into one label shipToLbl2.setText(cust.getShipToCity() + ", " + cust.getShipToState() + " " + cust.getShipToZip()); contactInfo.setText(cust.getContactPerson() + " Ph: " + cust.getContactPhone()); Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Customer So we’ve: Added properties to Customer Created CustFrame to display the properties Need to create a CustApp that Creates a Customer object, a Customer variable named c, and assigns the object to c Sets values for the Customer properties Creates a CustFrame object and passes the Customer variable c, creates a CustFrame variable named cf, assigns the CustFrame object to cf Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 CustApp Create a class called CustApp In CustApp Create a main method In main, write code to: Create a Customer object, assign to variable c Use setters to assign the following values in the Customer object associated with variable c: Kindness Foods, 1 Milkof St., Human, ME 03234 Joe Samaritan, 555-3333 Create a CustFrame object and pass c, assign the CustFrame object to a variable named cf Chapter 3 © copyright Janson Industries 2014

Have RAD generate the main method Chapter 3 © copyright Janson Industries 2014

Non-graded assg: Finish creating the Customer Application public class CustApp { public static void main(String[] args) { Customer c = new Customer(); c.setContactPerson("Joe Samaritan"); c.setContactPhone("555-3333"); c.setCustName("Kindness Foods"); c.setShipToStreet("1 Milkof St."); c.setShipToCity("Human"); c.setShipToState("ME"); c.setShipToZip("03234"); CustFrame cf = new CustFrame(c); } When run should look like import java.awt.Frame; import java.awt.Label; public class CustFrame extends Frame { Label custNameLbl = new Label(); Label shipToLbl1 = new Label(); Label shipToLbl2 = new Label(); Label contactInfo = new Label(); public CustFrame(Customer cust) { this.setSize(300, 282); this.setLayout(null); this.setVisible(true); custNameLbl.setBounds(62, 65, 176, 23); shipToLbl1.setBounds(62, 120, 176, 23); shipToLbl2.setBounds(62, 175, 176, 23); contactInfo.setBounds(62, 230, 176, 23); custNameLbl.setText(cust.getCustName()); shipToLbl1.setText(cust.getShipToStreet()); shipToLbl2.setText(cust.getShipToCity() + ", " + cust.getShipToState() + " " + cust.getShipToZip()); contactInfo.setText(cust.getContactPerson() + " Ph: " + cust.getContactPhone()); this.add(custNameLbl); this.add(shipToLbl1); this.add(shipToLbl2); this.add(contactInfo); } public static void main(String[] args) { Customer c = new Customer(); CustFrame cf = new CustFrame(c); Non-graded assg: Finish creating the Customer Application Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Non-graded Assg Export as one jar file Cust2.java Customer.java CustFrame.java CustApp.java Email the jar file as an email attachment to wsjavaws@yahoo.com Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 UML Unified Modeling Language Diagrams to show class methods and variables and interclass relationships: Composition Specialization Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Class Diagram Example For each class a box is created The box consists of three areas: Identification (name) Attributes (variables) Operations (methods) Attributes and Operations are further identified as public or private (+,-) Customer - name:String - address:String + setName:void + setAddress:void Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Class Diagram Example Attribute entries also specify the attribute’s type (the type is preceded by a colon & follows the attribute name) Customer -name:String -address:String +setName:void +setAddress:void Operation entries also specify a return value (the return value is preceded by a colon & follows the operation name) Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Class Diagram Example Attribute entries can also specify an initial value: Attribute:Type=initial_value name:String=“Joe Programmer” Operation entries can also specify the expected parameter(s) type(s): Operation(parm_list):returned_value getCustomerPO(int):String Chapter 3 © copyright Janson Industries 2014

UML Relationship Diagrams Can show specialization Object Component Button Container TextComponent Window Panel TextField Chapter 3 Frame © copyright Janson Industries 2014 Applet

RAD can generate for you Right click a java file (CustApp) Scroll to bottom and choose: Visualize Add to New Diagram File Class Diagram Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Click Finish Chapter 3 © copyright Janson Industries 2014

Initially shows class diagram for that class As you add, will show composition relationship Right click Customer and CustFrame Choose Visualize Add to current diagram Chapter 3 © copyright Janson Industries 2014

Can't fit diagram in window In outline view, click Overview button to display “the big picture” Can drag boxes, close Palette, & resize window to fit Chapter 3 © copyright Janson Industries 2014

Initially only shows composition (use relationship) Chapter 3 © copyright Janson Industries 2014

Need to simplify diagram Select all three boxes (Ctrl+click) Right click one box and choose: Filters Show/Hide Compartment Name Compartment only Chapter 3 © copyright Janson Industries 2014

Want to see superclasses, must add to diagram Expand JRE System Library, vm.jar, java.lang Chapter 3 © copyright Janson Industries 2014

Select Object.class and String.class Right click either class and select Visualize then Add to Current Diagram Chapter 3 © copyright Janson Industries 2014

Close up vm.jar and expand rt.jar and java.awt Chapter 3 © copyright Janson Industries 2014

Scroll down and select Frame.class and Label.class Right click either class and select Visualize then Add to Current Diagram Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Right click anywhere on diagram background and choose Select then All Shapes Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Right click Frame box and select Filters, Show/Hide Compartment, Name Compartment Only Chapter 3 © copyright Janson Industries 2014

Right click background and choose Arrange All Chapter 3 © copyright Janson Industries 2014

Still need to drag boxes into better arrangement and resize the boxes Chapter 3 © copyright Janson Industries 2014

You can modify which relationships are shown Chapter 3 © copyright Janson Industries 2014

You can modify which relationships are shown Chapter 3 © copyright Janson Industries 2014

New diagram file in the project Chapter 3 © copyright Janson Industries 2014

© copyright Janson Industries 2014 Other Resources JavaRanch: http://www.javaranch.com/ Forums, faqs, tutorials http://www.javaranch.com/campfire has stories/tutorials concerning various java topics Here is a link to some online java videos: http://www.youtube.com/user/webhasher/videos? sort=da&view=u I looked at several of them and they seemed pretty good Chapter 3 © copyright Janson Industries 2014