CS288 Lab Exercise 3.

Slides:



Advertisements
Similar presentations
Animation Mrs. C. Furman. Animation  We can animate our crab by switching the image between two pictures.  crab.png and crab2.png.
Advertisements

Faculty of Sciences and Social Sciences HOPE Structured Problem Solving Object Oriented Concepts 2 Stewart Blakeway FML 213
© The McGraw-Hill Companies, 2006 Chapter 18 Advanced graphics programming.
CS115 HOW TO INSTALL THE JAVA DEVELOPMENT KIT (JDK)
Object-Oriented Software Engineering PersonGui (Mark 2) Case Study.
CS288 Lab Exercise 1. UniS Open PersonGui Files Go to Course web site for PersonGui source files
Reference Manager Making your life easier! Updated September 2007.
CS 1110 Final Exam: Review Session 2 Part 1 : Inheriting classes 1. Inheritance Facts 2. Constructors in Subclasses BREAK : 10 sec. Part 2 : Working with.
A Prezi presentation is like creating a mind map. It is created on a blank canvas and you decide where the information goes on this canvas.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
Creating Integrated Web-based Projects using Microsoft Word.
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.
Putting Applets into Web Pages.  Two things are involved in the process of putting applets onto web pages ◦ The.class files of the applet ◦ The html.
Updating the Laboratory Website. Useful Info Address: Everything is saved in the desktop.
0 eCPIC User Training: Resource Library These training materials are owned by the Federal Government. They can be used or modified only by FESCOM member.
Creating and running a Java program. Eclipse Interactive Development Environment (IDE)  Eclipse is an Interactive Development Environment (IDE) for Java.
EIE375 BlueJ: Getting Started Dr Lawrence Cheung.
OOP in Java : © W. Milner 2005 : Slide 1 Java and OOP Part 2 – Classes and objects.
Topic 1 Object Oriented Programming. 1-2 Objectives To review the concepts and terminology of object-oriented programming To discuss some features of.
Lecture 15.1 Static Methods and Variables Static Methods In Java it is possible to declare methods and variables to belong to a class rather than.
CIS Intro to JAVA Lecture Notes Set July-05 GUI Programming – Home and reload buttons for the webbrowser, Applets.
IT108 Objects and Classes Part I George Mason University Revised 4/3/2012.
CSI 3125, Preliminaries, page 1 Compiling the Program.
1 Class 1 Lecture Topic Concepts, Definitions and Examples.
Lecture 8: Advanced OOP Part 2. Overview Review of Subtypes Interfaces Packages Sorting.
Topic 8Classes, Objects and Methods 1 Topic 8 l Class and Method Definitions l Information Hiding and Encapsulation l Objects and Reference Classes, Objects,
Variables and Strings. Variables  When we are writing programs, we will frequently have to remember a value for later use  We will want to give this.
CS116 COMPILER ERRORS George Koutsogiannakis 1. How to work with compiler Errors The Compiler provide error messages to help you debug your code. The.
Written by: Dr. JJ Shepherd
1 Project 2: Using Variables and Expressions. 222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What.
Singleton Pattern. Problem Want to ensure a single instance of a class, shared by all uses throughout a program Context Need to address initialization.
1 Project 7: Looping. Project 7 For this project you will produce two Java programs. The requirements for each program will be described separately on.
1 SIC / CoC / Georgia Tech MAGIC Lab Rossignac Processing  Install Processing  Learn how to edit, run, save, export,
Beginning JavaScript 4 th Edition. Chapter 1 Introduction to JavaScript and the Web.
5.1 Basics of defining and using classes A review of class and object definitions A class is a template or blueprint for an object A class defines.
Content Programming Overview The JVM A brief look at Structure – Class – Method – Statement Magic incantations – main() – output Coding a Dog Programming.
Section 10.1 Define scripting
The eclipse IDE IDE = “Integrated Development Environment”
The need for Programming Languages
Unit 9.1 Learning Objectives Data Access in Code
Phil Tayco Slide version 1.0 Created Sep 10, 2017
More Sophisticated Behavior
Content Programming Overview The JVM A brief look at Structure
3 Introduction to Classes and Objects.
Intro to Dreamweaver Web Design Section 8-1
Eclipse Navigation & Usage.
ADE EDIS READ & Optimizer TRAINING Colorado Department of Education
Retrieving information from forms
European Computer Driving Licence
PC02 Term 1 Project Basic Messenger. PC02 Term 1 Project Basic Messenger.
CS2102: Lecture on Abstract Classes and Inheritance
Some Tips for Using Eclipse
Java Programming Language
Object-Oriented Software Engineering
Overview of Memory Layout in C++
CS288 Lab Exercise 1.
Interfaces.
Introduction to Computing Using Java
Java Tutorial – Application Building
Programming games Classes and objects (used for Jigsaw, Bouncing stuff, other projects) Homework: Complete cannonball. Video or Audio. Your own project.
Do … Loop Until (condition is true)
CS115 HOW TO INSTALL THE JAVA DEVELOPMENT KIT (JDK)
Tonga Institute of Higher Education
CS288 Lab Exercise 2.
Constructors, GUI’s(Using Swing) and ActionListner
Java Tutorial – Application Building
Java Programming with BlueJ Objectives
Running a Java Program using Blue Jay.
References Revisted (Ch 5)
CMPE212 – Reminders Assignment 2 due next Friday.
Presentation transcript:

CS288 Lab Exercise 3

Open PersonGui Files Go to Course web site for PersonGui source files http://www.computing.surrey.ac.uk/courses/cs288/Examples/PersonGui Make copies of these files in you home folder and then open them in some editor (e.g. Emacs): PersonGui.java PersonMaker.java Person.java images.zip (unzip this file in the same directory as you have put the java files) Download a copy of these slides so that you can read them directly, and not simply view them in Internet Explorer. This is handy as you can then copy and paste code examples directly from these slides.

Overview At the moment with the PersonGui we can define age, height, first name and last name. In this lab you will add a new attribute, eye colour together with all the supporting code to add a new entry to the pop-up menu. That means there will be a new menu item on the pop-up menu to choose the eye colour of a person.

Overview So that when you choose to finally create a new person in a JFrame, this will appear with an extra attribute for eye colour:

1: PersonMaker.java Open PersonMaker.java in Emacs. Define a new instance field: private String eye_colour = ""; in the same place as you find these declarations: private String first_name = ""; private String last_name = ""; Next define methods: setEyeColour and getEyeColour in just the same way as you defined setLastName and getLastName

1: PersonMaker.java Next change the String Make_Person method, so that it includes information about the eye colour of the person. Do this in exactly the same way that the method includes the age and height of a person. Check that this code compiles correctly: javac PersonMaker.java

2: Person.java Next, open the Person.java file in Emacs. Change the constructor so that it has an extra parameter for the eye colour: public Person(String first_text, String last_text, String age_text, String height_text, String eye_colour_text, boolean bool_cat ) Next declare a new JLabel label_eye_colour with all the other JLabel declarations: To do this you will have to search through the file for the keyword JLabel until you find the line where all the other labels such as label_height are declared.

2: Person.java Next find the lines of code: label_height = new JLabel(height_text); set_fonts(label_height); Do the same thing for the eye_colour_text string and the label_eye_colour JLabel. I.e. create a new JLabel, using the eye_colour_text string, assign it to label_eye_colour, and then set the fonts for this new JLabel. Next add these lines: c.gridx = 4; c.gridy = 0; add(label_eye_colour, c); immediately after these lines: c.gridx = 3; add(label_height, c);

2: Person.java Next change this line: c.gridwidth = 4; to Now go back to the file PersonMaker.java. Change the creation of Person newContentPane to take account of the fact we have added an extra parameter to the Person constructor method for eye colour. Check that this code compiles correctly: javac Person.java javac PersonMaker.java (Remember that some times it is necessary to remove all .class files to make the compiler properly recompile your source files)

3: PersonGui.java Open PersonGui.java in Emacs Find the line static final private String POPUP_2 = "Surname of Person"; Add a new line immediately after this: static final private String POPUP_2_1 = "Eye Colour of Person"; Next find the text: menuItem = new JMenuItem(POPUP_2); menuItem.addActionListener(this); popup.add(menuItem); After this add three appropriate lines so that we have the same pattern of code here for POPUP_2_1, (so that exactly the same is done for POPUP_2_1 as is done for POPUP_2, and POPUP_1 for that matter).

3: PersonGui.java Now for the harder part. Find the part of the code: } else if(POPUP_2.equals(cmd)) { String text = textField.getText(); textField.setText(""); dude.setLastName(text); description = "The Persons Last Name is: " + " \"" + dude.getLastName() + "\"\n"; } You now have to insert code of this same pattern for POPUP_2_1. The difference is that you will not use setLastName and getLastName since you want to define the eye colour of someone. Check in PersonMaker.java to see what methods you defined for setting and getting the eye colour and use those methods for POPUP_2_1. In the new code you will want the description variable to say something about eye colour rather than the last name.

4: Finally Compile and run the code. Check that you get a new entry in the JFrame that shows all the attributes, and that the text frame in the original JFrame shows the eye colour. Next go back to PersonMaker.java and change the constructor so that it include a default value for eye colour as well as all the other attributes.