CS 170 Java Programming 1. Week 9: Learning about Loops
|
|
- Scott Austin
- 6 years ago
- Views:
Transcription
1 CS 170 Java Programming 1 Week 9: Learning about Loops
2 What s the Plan? Topic 1: A Little Review ACM GUI Apps, Buttons, Text and Events Topic 2: Learning about Loops Different kinds of loops Using loops to modify Picture objects Writing loop functions that work with String objects Topic 3: Introducing Animation Using loops to animate your GUI objects
3 Your "IC" or "Lab" Document Use Word or OpenOffice to create a new document Save the file as IC09.doc (Office compatible) Place on your network U: drive or on a thumb drive Put your name and today's date at the top of the sheet Title it "CS 170 Lab Exercises Week 9" Start DrJava and we'll start with a little GUI review Open TurtleWorld.java in your week09 folder
4 Topic 1 (Review) ACM GUI Apps, Widgets and Events
5 ACM GraphicsProgram Review Notice how ACM GUI apps are different Three different import statements Inheritance: extends GraphicsProgram Two different methods you will override The acm.graphics package contains graphical shapes Exercise 9.1 create a GTurtle variable Create the variable outside of your methods Put the word private in front of it This is called an instance variable
6 Creating Graphical Objects Exercise 9.2 create a GTurtle object Put inside init() method (means initialization) Initialize GTurtle instance variable (NOT NEW VAR) Look up GTurtle docs on class Web site Add it to the center of your program's canvas Find out the width and height of canvas Use width / 2 half the width of the turtle Run and shoot a picture
7 Using Interactors (aka Widgets) The javax.swing package contains interactors JButton: push buttons JLabel: labels JTextField: text input areas Exercise 9.3 create three JButton objects Create them inside the init() method "Turn Left", "Turn Right", "Move" Add them to the SOUTH panel of your program Run and snap a screen-shot
8 Hooking Up Events Buttons don't do anything without an event handler Event handling is in the java.awt.event package For ACM GUI apps, "activate" all buttons in program addactionlisteners(); // bottom of init() Respond to Action events with this method public void actionperformed(actionevent e) { // Your code goes here }
9 Responding to Events First, you need to know which button was clicked ActionEvent variable has two methods e.getactioncommand(): String on button e.getsource(): reference to button Exercise 9.4 Activate your turtle Get the text on the button Use sequential if statements to decide what to do Call the methods in your GTurtle variable Run, move your turtle around and snap a picture
10 Other Event Listeners We can listen for mouse events as well In ACM programs, just add this to your init() method addmouselisteners(); // bottom of init() Respond to different mouse events with these handlers: mouseclicked(), mousemoved(), etc. All are void methods that take a MouseEvent parameter Exercise 9.5 hook up mouse events for your program When clicked, use setlocation() to move the turtle
11 Topic 2 Introducing Counted Loops
12 Iteration and Loops A CS term that means repeating a set of actions Also called repetition or looping Statements used in iteration are called loops Loops are flow-of-control statements similar to if Like the if statement, a loop evaluates a condition If the condition is true, a group of actions are performed If the condition is false, the actions are skipped
13 Iteration and Selection Iteration is not the same as selection, though A loop returns to its test after performing its actions If the test is still true, then the actions are performed again A selection statement only performs its actions once You cannot replace a loop with a selection statement
14 Java and Iteration Java has three loops: while, do-while, and for Each is designed to work best in a specific situation One difference is where the test is made Test at the bottom { } // // Loop Body Loop Test Test at the top Loop Test { } // // Loop Body
15 Loop Classification Not the most useful method of classification Doesn't give you any empirical guidance for designing Better: ask how each loop is controlled Two basic methods of loop control Simplest method relies on a counter Called counting or counted loops "Repeat these actions 10 times" More complex loops test the occurrence of a particular event, or combination of events. These are called indefinite or indeterminate loops
16 For Loops A counted loop is simplest kind of loop The loop is controlled by a or counter variable Also known as the loop index Use it to for "perform this action 10 times" Java's for loop specializes in this for (int idx = 0; idx < 10; idx++) { System.out.println("idx = " + idx); }
17 The for Loop Syntax The for loop has both a header and body (like if) Header has 3 expressions: initialize, test, and update
18 Your Turn Exercise 9.6 Try these in the Interactions pane Write a loop that prints 40 asterisks to the screen Write a method that prints n asterisks to the screen Call your method with 5 and 10 Write a loop that adds 5 numbers input by the user
19 Modifying Pictures Let's use some loops to modify some Picture objects Open your own (640 x 480) picture in the Interactions Pane String fname = FileChooser.pickAFile(); Picture p = new Picture(fname); p.explore(); Now, find out how large the Picture is and save the info int width = p.getwidth(); int height = p.getheight();
20 The Pixel class The Pixel class models individual pixels in your picture Each object of the Pixel class has An (x, y) position in a picture (x = horizontal, y = vertical) A red, green, and blue value (between 0 and 255) We can get a pixel at a specific location in a picture by using the getpixel() method of the Picture class Pixel pix1 = p.getpixel(0,0);
21 Pixel Methods Pixels "know" how to do certain things You can ask a Pixel for its color values, or change them int red = pix.getred(); pix.setred(red / 2); // half as much You can also ask a Pixel for the entire Color Color pc = pix.getcolor(); pix.setcolor(pc.darker()); You can ask a Pixel to tell you where it is located int x = pix.getx();
22 Your Turn Exercise 9.7 Let's continue modifying our Picture Start by drawing a green line vertically down the center import java.awt.* so we can use Color Write a loop that starts at 0 and goes until height Inside, grab a Pixel from your Picture, using width/2for x and the loop index for y Set the PixelColor to green Show the picture again When it works, draw a horizontal red line and snap a pic
23 Nested Loops Nested loops let us process all of the pixels in a picture Write one loop that processes all rows Inside that loop, write another loop that visits the columns for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { Pixel pix = p.getpixel(x, y); Color col = pix.getcolor(); col = col.darker().darker(); pix.setcolor(col); } }
24 Your Turn Exercise 9.8 Let's use some nested loops Process the upper-left quadrant: make all pixels darker Process the lower-right quadrant: make all pixels brighter Process the upper-right quadrant: add vertical stripes Only process every other x position in your loop Process the lower-left quadrant: add a checkerboard If the row is even, process the odd pixels If the row is odd, process the even pixels Save as a new file name and paste into your IC doc
25 Just An Example
26 For Loop Functions
27 Step 1: The Skeleton Same steps for all function problems 1. Write the header 2. Create a result variable 3. Return the result 4. Run your tests
28 Step 2: Loop Through Strings Normally String problems require you to visit every character (or set of characters) in the String You can write a "skeleton" for this part too int len = str.length() for (int i = 0; i < len; i++) { // do your processing here }
29 Step 3: Processing Inside the loop, process characters or substrings Use the charat() or substring() method to extract int len = str.length(); for (int i = 0; i < len; i++) { // Use only one of these below char ch = str.charat(i); String sch = str.substring(i, i+1); }
30 Introducing the while Loop Counted loops with for are easy All of the pieces are in one place The initializer for your counter The test expression The update expression The simpler, general-purpose while loop can also be used to create counted loops It's just not quite as convenient as for
31 Counted while Loops To use the while statement to build a counted loop, you must do three things: 1. Create a counter variable, and initialize it before the loop is encountered. 2. Test the counter variable inside the while loop's boolean condition expression 3. Update your counter at the end of the loop body. This takes the place of the for loop's update expression.
32 A Counted while Skeleton Here is a skeleton for building counted while loops: int counter = 0; while (counter < 10) { // Loop body statements counter++; } Use this basic structure for many of exercises this week
33 While Loop Functions Exercise 9.10 mixstring in WhileLoopProblems Always start with the basic function skeleton Notice that these problems require a while loop Add basic while loop pattern (skeleton) to code Use shorter string for length of variable Add character from a to result, then from b After loop, see if index is < length Add remaining characters to end Shoot a screenshot of tests passing
34 Topic 3 Loops and Animation
35 Animation Appearance of motion by changing the shape or position of objects as a fixed, but rapid rate Provides the illusion of motion, similar to movies Similar (but different) techniques for applets and ACM Four steps: 1. Create objects to be animated as instance vars 2. Paint object at current location, shape, color 3. Call mutator methods to update state of object 4. Advance to next frame of animation
36 Frame-Rate and Skeleton Normally want to redisplay from frames per sec Create constant in terms of milliseconds inside run() final int FRAME_RATE = 1000 / 30; ACM animation: endless loop inside run() method public void run() { advanceoneframe(); // update objects pause(frame_rate); // wait for next }
37 Your Turn Let's animate our GTurtle so that it moves automatically It's up to you to keep it "on the table"; if it crawls off, it dies Add the advanceoneframe() method Inside, move your turtle forward 5 spaces Start by adding the skeleton animation loop to run() Add the constant FRAME_RATE Add a loop that continues while the turtle is visible Have to approximate using getx() and gety() When the loop ends, display a message box
38 Finishing Up To complete your IC "lab" document: Complete Exercise 9.11 in the For Loop lesson, Exercise 9.12 in the While Loop lesson, and Exercises 9.13 in the Loop Functions lesson, and Exercises in the Introducing Animation Lesson. Submit to Blackboard when done Reading for next week: Mediacomp: read Chapter 4 for modifying Pictures Gaddis: finish Chapter 3, start Chapter 5
39 Homework and Quiz Homework, Quiz and Assignments Deadline is Monday at noon 11 homework problems 5 for loop functions (similar to exam) 5 while loop functions (similar to exam) 1 animation, GUI program Upload to Assignment Dropbox, press Submit Proficiency Quiz 6: Simple for and while loop functions Practice on assignments You will have ½ hour, assigned seating
40 Additional Credits Some material adapted from instructor materials created by B. Ericson to accompany Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, released under a Creative Commons 3.0 Attribution License.
CS 170 Java Programming 1. Week 10: Loops and Arrays
CS 170 Java Programming 1 Week 10: Loops and Arrays What s the Plan? Topic 1: A Little Review Use a counted loop to create graphical objects Write programs that use events and animation Topic 2: Advanced
More informationCS 170 Java Programming 1. Week 5: Procedures and Functions
CS 170 Java Programming 1 Week 5: Procedures and Functions What s the Plan? Topic 1: More on graphical objects Creating your own custom Turtle types Introducing media, pictures and sounds Topic 2: Decomposition:
More informationCS 170 Java Programming 1. Week 12: Creating Your Own Types
CS 170 Java Programming 1 Week 12: Creating Your Own Types What s the Plan? Topic 1: A Little Review Work with loops to process arrays Write functions to process 2D Arrays in various ways Topic 2: Creating
More informationWeek 2: Data and Output
CS 170 Java Programming 1 Week 2: Data and Output Learning to speak Java Types, Values and Variables Output Objects and Methods What s the Plan? Topic I: A little review IPO, hardware, software and Java
More informationWeek 3: Objects, Input and Processing
CS 170 Java Programming 1 Week 3: Objects, Input and Processing Learning to Create Objects Learning to Accept Input Learning to Process Data What s the Plan? Topic I: Working with Java Objects Learning
More informationCS 170 Java Programming 1. Week 15: Interfaces and Exceptions
CS 170 Java Programming 1 Week 15: Interfaces and Exceptions Your "IC" or "Lab" Document Use Word or OpenOffice to create a new document Save the file as IC15.doc (Office 97-2003 compatible) Place on your
More informationCS 170 Java Programming 1. Week 13: Classes, Testing, Debugging
CS 170 Java Programming 1 Week 13: Classes, Testing, Debugging What s the Plan? Short lecture for makeup exams Topic 1: A Little Review How to create your own user-defined classes Defining instance variables,
More informationCS 170 Java Programming 1. Week 7: More on Logic
CS 170 Java Programming 1 Week 7: More on Logic What s the Plan? Topic 1: A Little Review Use relational operators to compare values Write functions using if and else to make decisions Topic 2: New Logical
More informationExpress Yourself. What is Eclipse?
CS 170 Java Programming 1 Eclipse and the for Loop A Professional Integrated Development Environment Introducing Iteration Express Yourself Use OpenOffice or Word to create a new document Save the file
More informationExpress Yourself. Writing Your Own Classes
Java Programming 1 Lecture 5 Defining Classes Creating your Own Classes Express Yourself Use OpenOffice Writer to create a new document Save the file as LastFirst_ic05 Replace LastFirst with your actual
More informationCS 106A, Lecture 23 Interactors and GCanvas
CS 106A, Lecture 23 Interactors and GCanvas suggested reading: Java Ch. 10.5-10.6 This document is copyright (C) Stanford Computer Science and Marty Stepp, licensed under Creative Commons Attribution 2.5
More informationTo gain experience using GUI components and listeners.
Lab 5 Handout 7 CSCI 134: Fall, 2017 TextPlay Objective To gain experience using GUI components and listeners. Note 1: You may work with a partner on this lab. If you do, turn in only one lab with both
More informationJava Programming Lecture 6
Java Programming Lecture 6 Alice E. Fischer Feb 15, 2013 Java Programming - L6... 1/32 Dialog Boxes Class Derivation The First Swing Programs: Snow and Moving The Second Swing Program: Smile Swing Components
More informationOutline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics
Topic 9: Swing Outline Swing = Java's GUI library Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 7: Expand moving shapes from Assignment 4 into game. "Programming
More informationLecture 15. For-Loops
Lecture 15 For-Loops Announcements for This Lecture Today s Material Section 2.3.8 (first use of loops in the text) All of Chapter 7 Two topics covered today Elementary graphics For-loops Both used on
More informationCS 106A, Lecture 24 Interactors and NameSurfer
CS 106A, Lecture 24 Interactors and NameSurfer suggested reading: Java Ch. 10.5-10.6 This document is copyright (C) Stanford Computer Science and Marty Stepp, licensed under Creative Commons Attribution
More informationIntroduction. Introduction
Introduction Many Java application use a graphical user interface or GUI (pronounced gooey ). A GUI is a graphical window or windows that provide interaction with the user. GUI s accept input from: the
More informationFirst Name: AITI 2004: Exam 2 July 19, 2004
First Name: AITI 2004: Exam 2 July 19, 2004 Last Name: JSP Track Read Instructions Carefully! This is a 3 hour closed book exam. No calculators are allowed. Please write clearly if we cannot understand
More informationTOPIC 8 MORE ON WHILE LOOPS
1 TOPIC 8 MORE ON WHILE LOOPS Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared by B. Ericson.
More informationChanging a picture. Modifying Pictures. Looping (iteration) Changing all the pixels in a picture TOPIC 6 MODIFYING PICTURES USING LOOPS
1 Outline TOPIC 6 MODIFYING PICTURES USING LOOPS 2 2 How to manipulate digital images by changing pixels What is a loop in Java while loop for loop Notes adapted from Introduction to Computing and Programming
More informationStructured Programming
CS 170 Java Programming 1 Objects and Variables A Little More History, Variables and Assignment, Objects, Classes, and Methods Structured Programming Ideas about how programs should be organized Functionally
More informationTOPIC 6 MODIFYING PICTURES USING LOOPS
1 TOPIC 6 MODIFYING PICTURES USING LOOPS Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared by
More informationCS 134 Programming Exercise 7:
CS 134 Programming Exercise 7: Scribbler Objective: To gain more experience using recursion and recursive data structures. This week, you will be implementing a program we call Scribbler. You have seen
More informationGraphical User Interface (GUI)
Graphical User Interface (GUI) An example of Inheritance and Sub-Typing 1 Java GUI Portability Problem Java loves the idea that your code produces the same results on any machine The underlying hardware
More informationCoSc Lab # 5 (The Controller)
CoSc 10403 Lab # 5 (The Controller) Due Date: Part I, Experiment classtime, Thursday, Oct 25 th, 2018. Part II, Program - by midnight, Thursday, Oct 25 th, 2018. Part I MUST be typed and submitted to your
More informationAP CS Unit 11: Graphics and Events
AP CS Unit 11: Graphics and Events This packet shows how to create programs with a graphical interface in a way that is consistent with the approach used in the Elevens program. Copy the following two
More informationJava - Applets. public class Buttons extends Applet implements ActionListener
Java - Applets Java code here will not use swing but will support the 1.1 event model. Legacy code from the 1.0 event model will not be used. This code sets up a button to be pushed: import java.applet.*;
More informationCS Exam 1 Review Suggestions
CS 235 - Fall 2015 - Exam 1 Review Suggestions p. 1 last modified: 2015-09-30 CS 235 - Exam 1 Review Suggestions You are responsible for material covered in class sessions, lab exercises, and homeworks;
More informationCommand-Line Applications. GUI Libraries GUI-related classes are defined primarily in the java.awt and the javax.swing packages.
1 CS257 Computer Science I Kevin Sahr, PhD Lecture 14: Graphical User Interfaces Command-Line Applications 2 The programs we've explored thus far have been text-based applications A Java application is
More informationSlide 1 CS 170 Java Programming 1
CS 170 Java Programming 1 Objects and Methods Performing Actions and Using Object Methods Slide 1 CS 170 Java Programming 1 Objects and Methods Duration: 00:01:14 Hi Folks. This is the CS 170, Java Programming
More informationDEMYSTIFYING PROGRAMMING: CHAPTER SIX METHODS (TOC DETAILED) CHAPTER SIX: METHODS 1
DEMYSTIFYING PROGRAMMING: CHAPTER SIX METHODS (TOC DETAILED) CHAPTER SIX: METHODS 1 Objectives 1 6.1 Methods 1 void or return 1 Parameters 1 Invocation 1 Pass by value 1 6.2 GUI 2 JButton 2 6.3 Patterns
More informationMIT AITI Swing Event Model Lecture 17
MIT AITI 2004 Swing Event Model Lecture 17 The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the user. But how do GUIs interact with users? How do applications
More informationSlide 1 CS 170 Java Programming 1 Object-Oriented Graphics Duration: 00:00:18 Advance mode: Auto
CS 170 Java Programming 1 Object-Oriented Graphics The Object-Oriented ACM Graphics Classes Slide 1 CS 170 Java Programming 1 Object-Oriented Graphics Duration: 00:00:18 Hello, Welcome to the CS 170, Java
More informationFirst Name: AITI 2004: Exam 2 July 19, 2004
First Name: AITI 2004: Exam 2 July 19, 2004 Last Name: Standard Track Read Instructions Carefully! This is a 3 hour closed book exam. No calculators are allowed. Please write clearly if we cannot understand
More informationPROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7
PROGRAMMING DESIGN USING JAVA (ITT 303) Graphical User Interface Unit 7 Learning Objectives At the end of this unit students should be able to: Build graphical user interfaces Create and manipulate buttons,
More informationCS 106A, Lecture 14 Events and Instance Variables
CS 106A, Lecture 14 Events and Instance Variables Reading: Art & Science of Java, Ch. 10.1-10.4 This document is copyright (C) Stanford Computer Science and Marty Stepp, licensed under Creative Commons
More informationSlide 1 CS 170 Java Programming 1 The while Loop Duration: 00:00:60 Advance mode: Auto
CS 170 Java Programming 1 The while Loop Writing Counted Loops and Loops that Check a Condition Slide 1 CS 170 Java Programming 1 The while Loop Duration: 00:00:60 Hi Folks. Welcome to the CS 170, Java
More informationCISC 1600, Lab 3.1: Processing
CISC 1600, Lab 3.1: Processing Prof Michael Mandel 1 Getting set up For this lab, we will be using OpenProcessing, a site for building processing sketches online using processing.js. 1.1. Go to https://www.openprocessing.org/class/57767/
More information+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created.
+ Inheritance + Inheritance Classes that we design in Java can be used to model some concept in our program. For example: Pokemon a = new Pokemon(); Pokemon b = new Pokemon() Sometimes we need to create
More informationAssignment 6 YEAH Hours. Ben Barnett and Avery Wang
Assignment 6 YEAH Hours Ben Barnett and Avery Wang 2 Overview 1. Review relevant material. 2. Discuss each milestone. 3. Q&A Classes Define your very own variable type! 4 What custom variables have you
More informationCS 3331 Advanced Object-Oriented Programming. Final Exam
1 Fall 2006 (Thursday, December 7) Name: CS 3331 Advanced Object-Oriented Programming Final Exam This test has 6 questions and pages numbered 1 through 12. Reminders This test is open book. You may also
More informationCSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT
CSE 143 Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia http://www.cs.washington.edu/331/
More informationProgramming Languages and Techniques (CIS120)
Programming Languages and Techniques (CIS120) Lecture 32 April 9, 2018 Swing I: Drawing and Event Handling Chapter 29 HW8: Spellchecker Available on the web site Due: Tuesday! Announcements Parsing, working
More informationTopic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more
Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 5: Will be an open-ended Swing project. "Programming Contest"
More informationTopic 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 = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Why are we studying Swing? 1. Useful & fun! 2. Good application of OOP techniques
More informationStarting Out with Java: From Control Structures Through Objects Sixth Edition
Starting Out with Java: From Control Structures Through Objects Sixth Edition Chapter 12 A First Look at GUI Applications Chapter Topics 12.1 Introduction 12.2 Creating Windows 12.3 Equipping GUI Classes
More informationCSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing
CSEN401 Computer Programming Lab Topics: Graphical User Interface Window Interfaces using Swing Prof. Dr. Slim Abdennadher 22.3.2015 c S. Abdennadher 1 Swing c S. Abdennadher 2 AWT versus Swing Two basic
More informationAdvanced Java Unit 6: Review of Graphics and Events
Advanced Java Unit 6: Review of Graphics and Events This is a review of the basics of writing a java program that has a graphical interface. To keep things simple, all of the graphics programs will follow
More informationGraphical User Interface (GUI)
Graphical User Interface (GUI) An example of Inheritance and Sub-Typing 1 Java GUI Portability Problem Java loves the idea that your code produces the same results on any machine The underlying hardware
More informationGraphics User Defined Forms, Part I
Graphics User Defined Forms, Part I Quick Start Compile step once always mkdir labs javac PropertyTax5.java cd labs mkdir 5 Execute step cd 5 java PropertyTax5 cp /samples/csc/156/labs/5/*. cp PropertyTax1.java
More informationObjectives. OO Exceptions (ch( ch.. 10) and a little Applets thrown in. Applets. Understand Applet model Understand Exceptions
Objectives OO Exceptions (ch( ch.. 10) and a little Applets thrown in CS201 Spring 2005 Week 7 Understand Applet model Understand Exceptions throw-catch block rethrowing Development Methods 2 Applets import
More informationSlide 1 CS 170 Java Programming 1 Multidimensional Arrays Duration: 00:00:39 Advance mode: Auto
CS 170 Java Programming 1 Working with Rows and Columns Slide 1 CS 170 Java Programming 1 Duration: 00:00:39 Create a multidimensional array with multiple brackets int[ ] d1 = new int[5]; int[ ][ ] d2;
More informationGUI DYNAMICS Lecture July 26 CS2110 Summer 2011
GUI DYNAMICS Lecture July 26 CS2110 Summer 2011 GUI Statics and GUI Dynamics 2 Statics: what s drawn on the screen Components buttons, labels, lists, sliders, menus,... Containers: components that contain
More informationLecture 3: Java Graphics & Events
Lecture 3: Java Graphics & Events CS 62 Fall 2017 Kim Bruce & Alexandra Papoutsaki Text Input Scanner class Constructor: myscanner = new Scanner(System.in); can use file instead of System.in new Scanner(new
More informationSINGLE EVENT HANDLING
SINGLE EVENT HANDLING Event handling is the process of responding to asynchronous events as they occur during the program run. An event is an action that occurs externally to your program and to which
More informationProgramming Assignment 4 ( 100 Points )
Programming Assignment 4 ( 100 Points ) Due: 11:59pm Thursday, October 26 START EARLY!! In PA4 you will continue exploring the graphical user interface (GUI) and object oriented programming. You will be
More informationAP CS Unit 12: Drawing and Mouse Events
AP CS Unit 12: Drawing and Mouse Events A JPanel object can be used as a container for other objects. It can also be used as an object that we can draw on. The first example demonstrates how to do that.
More informationJava Swing. Recitation 11/(20,21)/2008. CS 180 Department of Computer Science, Purdue University
Java Swing Recitation 11/(20,21)/2008 CS 180 Department of Computer Science, Purdue University Announcements Project 8 is out Milestone due on Dec 3rd, 10:00 pm Final due on Dec 10th, 10:00 pm No classes,
More informationEXCEPTIONS & GUI. Errors are signals that things are beyond help. Review Session for. -Ankur Agarwal
Review Session for EXCEPTIONS & GUI -Ankur Agarwal An Exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions. Errors are signals
More informationCS 134 Programming Exercise 9:
CS 134 Programming Exercise 9: Nibbles Objective: To gain experience working with 2 dimensional arrays. The Problem Nibbles is a snake. Nibbles moves around a field, looking for food. Unfortunately, Nibbles
More informationThroughout the exam, write concisely and underline key words or phrases. Have fun! Exam 2. Week 7 (Winter 2013). Dr. Yoder. Sec 031.
SE1021 Exam 2 Name: You may have an 8.5x11 note sheet for this exam. No calculators or other study aids on this exam. Write your initials at the tops of the following pages and read through the exam before
More informationReview sheet for Final Exam (List of objectives for this course)
Review sheet for Final Exam (List of objectives for this course) Please be sure to see other review sheets for this semester Please be sure to review tests from this semester Week 1 Introduction Chapter
More informationCS Homework 11 p. 1. CS Homework 11
CS 111 - Homework 11 p. 1 Deadline 11:59 pm on Monday, May 2, 2016 How to submit Each time you would like to submit your work: CS 111 - Homework 11 If your files are not already on nrs-labs, be sure to
More informationBuilding a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver
Building a GUI in Java with Swing CITS1001 extension notes Rachel Cardell-Oliver Lecture Outline 1. Swing components 2. Building a GUI 3. Animating the GUI 2 Swing A collection of classes of GUI components
More informationBCIS 3630 Dr. GUYNES SPRING 2018 TUESDAY SECTION [JAN version] GRADER COURSE WEBSITE
COURSE WEBSITE http://www.steveguynes.com/bcis3630/bcis3630/default.html Instructor: Dr. Guynes Office: BLB 312H Phone: (940) 565-3110 Office Hours: By Email Email: steve.guynes@unt.edu TEXTBOOK: Starting
More informationCMSC 150 Lab 8, Part II: Little PhotoShop of Horrors, Part Deux 10 Nov 2015
CMSC 150 Lab 8, Part II: Little PhotoShop of Horrors, Part Deux 10 Nov 2015 By now you should have completed the Open/Save/Quit portion of the menu options. Today we are going to finish implementing the
More informationG51PRG: Introduction to Programming Second semester Applets and graphics
G51PRG: Introduction to Programming Second semester Applets and graphics Natasha Alechina School of Computer Science & IT nza@cs.nott.ac.uk Previous two lectures AWT and Swing Creating components and putting
More informationCSE 331 Software Design and Implementation. Lecture 19 GUI Events
CSE 331 Software Design and Implementation Lecture 19 GUI Events Leah Perlmutter / Summer 2018 Announcements Announcements Quiz 7 due Thursday 8/9 Homework 8 due Thursday 8/9 HW8 has a regression testing
More information2IS45 Programming
Course Website Assignment Goals 2IS45 Programming http://www.win.tue.nl/~wsinswan/programmeren_2is45/ Rectangles Learn to use existing Abstract Data Types based on their contract (class Rectangle in Rectangle.
More information+! Today. Lecture 3: ArrayList & Standard Java Graphics 1/26/14! n Reading. n Objectives. n Reminders. n Standard Java Graphics (on course webpage)
+! Lecture 3: ArrayList & Standard Java Graphics +! Today n Reading n Standard Java Graphics (on course webpage) n Objectives n Review for this week s lab and homework assignment n Miscellanea (Random,
More informationDEMYSTIFYING PROGRAMMING: CHAPTER FOUR
DEMYSTIFYING PROGRAMMING: CHAPTER FOUR Chapter Four: ACTION EVENT MODEL 1 Objectives 1 4.1 Additional GUI components 1 JLabel 1 JTextField 1 4.2 Inductive Pause 1 4.4 Events and Interaction 3 Establish
More informationImplementing Graphical User Interfaces
Chapter 6 Implementing Graphical User Interfaces 6.1 Introduction To see aggregation and inheritance in action, we implement a graphical user interface (GUI for short). This chapter is not about GUIs,
More informationFrames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling
Frames, GUI and events Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling Introduction to Swing The Java AWT (Abstract Window Toolkit)
More informationTOPIC 5 INTRODUCTION TO PICTURES
1 TOPIC 5 INTRODUCTION TO PICTURES Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B. Ericson, and instructor materials prepared by B. Ericson.
More informationCSSE 490 Model-Based Software Engineering
CSSE 490 Model-Based Software Engineering Project Milestone 1 This first Milestone develops the first iteration of the system, FacePamphlet, that we want to develop. Ultimately we will use this as the
More informationAn 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
CBOP3203 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 page. When you use a Java technology-enabled
More informationCS180 Recitation. More about Objects and Methods
CS180 Recitation More about Objects and Methods Announcements Project3 issues Output did not match sample output. Make sure your code compiles. Otherwise it cannot be graded. Pay close attention to file
More informationIntroduction to the JAVA UI classes Advanced HCI IAT351
Introduction to the JAVA UI classes Advanced HCI IAT351 Week 3 Lecture 1 17.09.2012 Lyn Bartram lyn@sfu.ca About JFC and Swing JFC Java TM Foundation Classes Encompass a group of features for constructing
More informationCS 251 Intermediate Programming GUIs: Event Listeners
CS 251 Intermediate Programming GUIs: Event Listeners Brooke Chenoweth University of New Mexico Fall 2017 What is an Event Listener? A small class that implements a particular listener interface. Listener
More informationUI Software Organization
UI Software Organization The user interface From previous class: Generally want to think of the UI as only one component of the system Deals with the user Separate from the functional core (AKA, the app
More informationGraphic User Interfaces. - GUI concepts - Swing - AWT
Graphic User Interfaces - GUI concepts - Swing - AWT 1 What is GUI Graphic User Interfaces are used in programs to communicate more efficiently with computer users MacOS MS Windows X Windows etc 2 Considerations
More informationWindow Interfaces Using Swing Objects
Chapter 12 Window Interfaces Using Swing Objects Event-Driven Programming and GUIs Swing Basics and a Simple Demo Program Layout Managers Buttons and Action Listeners Container Classes Text I/O for GUIs
More informationCSC 160 LAB 8-1 DIGITAL PICTURE FRAME. 1. Introduction
CSC 160 LAB 8-1 DIGITAL PICTURE FRAME PROFESSOR GODFREY MUGANDA DEPARTMENT OF COMPUTER SCIENCE 1. Introduction Download and unzip the images folder from the course website. The folder contains 28 images
More informationJava - 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,
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, 5.3.2. Java is not confined to a DOS environment. It can run with buttons and boxes in a Windows
More informationJava Applets / Flash
Java Applets / Flash Java Applet vs. Flash political problems with Microsoft highly portable more difficult development not a problem less so excellent visual development tool Applet / Flash good for:
More informationAssoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.
Assoc. Prof. Dr. Marenglen Biba Before writing a program to solve a problem, have a thorough understanding of the problem and a carefully planned approach to solving it. Understand the types of building
More informationCS 106A Midterm Review. Rishi Bedi, adapted from slides by Kate Rydberg and Nick Troccoli Summer 2017
+ CS 106A Midterm Review Rishi Bedi, adapted from slides by Kate Rydberg and Nick Troccoli Summer 2017 Details n Only the textbook is allowed n n n The Art and Science of Java Karel Course Reader You will
More informationSolution to Section #7
Chris Piech Section #7 CS 106A Feburary 28, 2018 Solution to Section #7 Portions of this handout by Eric Roberts and Nick Troccoli 1. Word Cloud /** * File: WordCloud.java * -------------------- * This
More informationJAVA NOTES GRAPHICAL USER INTERFACES
1 JAVA NOTES GRAPHICAL USER INTERFACES Terry Marris 24 June 2001 5 TEXT AREAS 5.1 LEARNING OUTCOMES By the end of this lesson the student should be able to understand how to get multi-line input from the
More informationCISC 1600 Lecture 2.2 Interactivity&animation in Processing
CISC 1600 Lecture 2.2 Interactivity&animation in Processing Topics: Interactivity: keyboard and mouse variables Interactivity: keyboard and mouse listeners Animation: vector graphics Animation: bitmap
More informationUser interfaces and Swing
User interfaces and Swing Overview, applets, drawing, action listening, layout managers. APIs: java.awt.*, javax.swing.*, classes names start with a J. Java Lectures 1 2 Applets public class Simple extends
More informationLecture 5: Java Graphics
Lecture 5: Java Graphics CS 62 Spring 2019 William Devanny & Alexandra Papoutsaki 1 New Unit Overview Graphical User Interfaces (GUI) Components, e.g., JButton, JTextField, JSlider, JChooser, Containers,
More informationProgrammierpraktikum
Programmierpraktikum Claudius Gros, SS2012 Institut für theoretische Physik Goethe-University Frankfurt a.m. 1 of 18 17/01/13 11:46 Java Applets 2 of 18 17/01/13 11:46 Java applets embedding Java applications
More information1. Traffic Control CIT/CSE 230 PROGRAMMING PROJECT 4
CIT/CSE 230 PROGRAMMING PROJECT 4 1. Traffic Control In this exercise you will develop a traffic light application. The application draws three lights red (top), yellow (middle), and green (bottom) that
More informationCISC 1600 Lecture 3.1 Introduction to Processing
CISC 1600 Lecture 3.1 Introduction to Processing Topics: Example sketches Drawing functions in Processing Colors in Processing General Processing syntax Processing is for sketching Designed to allow artists
More informationYEAH session #6. 6 March 2014, 5:30p-6:30p Miles Seiver
YEAH session #6 6 March 2014, 5:30p-6:30p Miles Seiver Review session schedule Topic Date Time Location assignment 6 today! now! here! assignment 7 Sun 16 Mar 7p - 8p Hewlett 200 Interactors JSlider slide
More informationName: Checked: Learn about listeners, events, and simple animation for interactive graphical user interfaces.
Lab 15 Name: Checked: Objectives: Learn about listeners, events, and simple animation for interactive graphical user interfaces. Files: http://www.csc.villanova.edu/~map/1051/chap04/smilingface.java http://www.csc.villanova.edu/~map/1051/chap04/smilingfacepanel.java
More informationCSE 331. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT
CSE 331 Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia http://www.cs.washington.edu/331/
More informationGraphical User Interfaces 2
Graphical User Interfaces 2 CSCI 136: Fundamentals CSCI 136: Fundamentals of Computer of Science Computer II Science Keith II Vertanen Keith Vertanen Copyright 2011 Extending JFrame Dialog boxes Overview
More informationCISC 1600 Lecture 2.2 Interactivity&animation in Processing
CISC 1600 Lecture 2.2 Interactivity&animation in Processing Topics: Interactivity: keyboard and mouse variables Interactivity: keyboard and mouse listeners Animation: vector graphics Animation: bitmap
More information