Array indexing. Before we use an array, we have to declare it. For example, int[] height=new int[11];

Size: px
Start display at page:

Download "Array indexing. Before we use an array, we have to declare it. For example, int[] height=new int[11];"

Transcription

1 Chapter 6 Arrays We want to organize objects or primitive data in a form that is easy to access and modify data. We will explore more about the ways to group and organize data in a later chapter, and even more in a later course. We now discuss a very simply way to put them together, an array of data. When writing a program to work with, e.g., a list of 100 piece of data, it is not practical to treat them as 100 isolated data. The array structure lets us declare them as a whole. 1

2 Array indexing An array is a list of values, each of which is stored at a specific, numbered position in the array. Those numbers corresponding to positions are referred to as index or subscript. In Java, they start at 0, thus, the data with index 5 is actually stored in the sixth position. To access a value in an array, we use the name of this array, together with its index. Thus, to get the value with index 5 in an array height, we use the expression of height[5]. Such an expression can be used whenever an integer can be used. Before we use an array, we have to declare it. For example, int[] height=new int[11]; declares an array, height, with 11 int type elements. 2

3 More examples Once the height array is declared, the following are all valid expressions: height[2]=72; height[count]=feet*12; average=(height[0]+height[1]+height[2])/3; System.out.println("The middle value is " +height[max/2]); pick=height[rand.nextint(11)]; When declaring an array, we don t need to give its size. However, once it is instantiated with the new, its size can t be changed. 3

4 A complete example The following code shows how to initialize an array, change one value, then print the whole array. public class BasicArray{ final static int LIMIT = 15; final static int MULTIPLE = 10; public static void main(string[] args){ int[] list = new int[limit]; //Initialize the array values for(int index = 0;index<LIMIT;index++) list[index] = index * MULTIPLE; list[5] = 999; // change one array value for (int index=0;index<limit;index++) System.out.print(list[index]+ " "); System.out.println (); 4

5 A couple of points 1. Technically, the bracket [] is an operator, and usually, has the highest precedence. 2. The index operator carries out automatic bound checking. Thus, if you try to print out height[23], an exception will be thrown back. 3. The size of any array is kept in a public variable, length, coming with the array. 4. Arrays can also be declared in an alternative way. For example, int height[]; Homework: Exercises 6.1, 6.2, 6.3 and

6 Another example The following code shows how to read in a list of numbers, then print them out in an reversed order. public class ReverseOrder{ public static void main (String[] args){ double[] numbers = new double[10]; System.out.println ("The size of the array: " + numbers.length); for (int index = 0; index < numbers.length; index++){ System.out.print("Enter number " + (index+1) + ": "); numbers[index] = Keyboard.readDouble(); System.out.println("The numbers in reverse order:"); for (int index=numbers.length-1;index>=0;index--) System.out.print(numbers[index] + " "); System.out.println(); 6

7 A couple of points 1. Arrays can be initialized. For example, int score=new int[4]; char lettergrades=new char[4]; score={87, 98, 78, 23; lettergrades={ A, B, C, F ; 2. Array can also be used as parameters. When an array is passed in, a copy of the reference to this array as an object is passed in. An array element can also be passed in. If the type of its element is a primitive type, a copy of its value is passed in. Homework: Exercises 6.5 and

8 Array of string objects Consider the following line String[] words=new String[25]; the variable words now becomes an array of references to String objects. The new operator instantiates this array and reserves space for them. An important point is that it does not create any String objects at this point. In the following example, an array of String objects are created, the associated string are created later, using string literals contained in the initializing list. 8

9 An example public class GradeRange{ public static void main (String[] args){ String[] grades = {"A", "A-", "B+", "B", "B-", "C+", "C", "C-", "D+", "D", "D-", "F"; int[] cutoff={95,90,87,83,80,77,73,70,67,63,60,0; for (int level = 0; level < cutoff.length; level++) System.out.println(grades[level]+"\t"+cutoff[level]); The problem with this sort of parallel array is that they may go out of sync. Thus, a better way is to construct one array of pairs, containing both the letter grade and the corresponding cutoff. Such a pair can be done as a class. Thus, we now will work with an array of objects, each of which consists of a pair. 9

10 Filling arrays of objects As we have said many times, it takes two separate steps to create an array and then fill it. public class Tunes{ public static void main (String[] args){ CDCollection music = new CDCollection (); music.addcd ("Storm Front", "Billy Joel", 14.95, 10); music.addcd ("Come On Over", "Shania Twain", 14.95, 16); music.addcd ("Soundtrack", "Les Miserables", 17.95, 33); music.addcd ("Graceland", "Paul Simon", 13.90, 11); System.out.println (music); music.addcd ("Double Live", "Garth Brooks", 19.99, 26); music.addcd ("Greatest Hits", "Jimmy Buffet", 15.95, 13); System.out.println (music); The CDCollection class is defined in the following slides. 10

11 The CDCollection class public class CDCollection{ private CD[] collection; private int count; private double totalcost; public CDCollection (){ collection = new CD[100]; count = 0; totalcost = 0.0; public void addcd (String title, String artist, double cost, int tracks){ if (count == collection.length) increasesize(); collection[count]=new CD(title,artist,cost,tracks); totalcost += cost; count++; 11

12 public String tostring(){ NumberFormat fmt = NumberFormat.getCurrencyInstance(); String report = "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n"; report += "My CD Collection\n\n"; report += "Number of CDs: " + count + "\n"; report += "Total cost: " + fmt.format(totalcost) + "\n"; report += "Average cost: " + fmt.format(totalcost/count); report += "\n\ncd List:\n\n"; for (int cd = 0; cd < count; cd++) report += collection[cd].tostring() + "\n"; return report; private void increasesize (){ CD[] temp = new CD[collection.length * 2]; for (int cd = 0; cd < collection.length; cd++) temp[cd] = collection[cd]; collection = temp; 12

13 Selection sort Sorting is the process of putting things in order. There are many ways to do sorting. We begin with a simple way, selection sort, which sorts things by successively selecting the smallest data, and putting it into its final place. public static void selectionsort (int[] numbers){ int min, temp; for (int index=0;index<numbers.length-1;index++){ min = index; for(int scan=index+1;scan<numbers.length;scan++) if(numbers[scan]<numbers[min]) min = scan; temp = numbers[min]; numbers[min] = numbers[index]; numbers[index] = temp; 13

14 How to run selection sort? Below shows how to pass in an array object to a method, particularly, how to sort a list of numbers. public class SortGrades{ public static void main (String[] args){ int[] grades={89,94,69,80,97,85,73,91,77,85,93; Sorts.selectionSort(grades); for (int index = 0; index < grades.length; index++) System.out.print (grades[index] + " "); 14

15 Insertion sort Insertion sort sorts things by inserting each and every element into the right place. In the following code, it starts with the left end and moves to the right. For every position, it goes backwards to insert the current data to its right place. public static void insertionsort (int[] numbers){ for (int index=1;index<numbers.length;index++){ int key = numbers[index]; int position = index; // shift larger values to the right while (position > 0 && numbers[position-1] > key){ numbers[position] = numbers[position-1]; position--; numbers[position] = key; 15

16 The general insertion sort The key difference between this more general insertion sort and the previous one is that now we apply it to a list of comparable objects, namely, the data within need not be int, as long as they are comparable. The class for that object has to implement the Comparable class, and more specifically, the compareto method definition will tell us the order between any two objects in that class. public static void insertionsort(comparable[] objects){ for (int index=1; index<objects.length; index++){ Comparable key = objects[index]; int position = index; while (position > 0 && objects[position-1].compareto(key)>0){ objects[position] = objects[position-1]; position--; objects[position] = key; Homework: Read the relevant part in pp. 346 and pp

17 Sort comparison There could be a few reasons to pick one sorting method over another one, such as its simplicity, the level of efficiency, the amount of space it needs, the amount of time it takes, etc.. Both insertion sort and selection sort basically take the same amount of space and time to run. More specifically, the time need for both is O(n 2 ), in the sense that both will take time proportional to n 2, where n is the size of the list. But, insertion sort is faster when the list is close to be sorted, while selection sort always take the same amount of work, no matter what. On the other hand, selection sort is easier to understand, and will often suffice in lots of cases. We will further study the difference between algorithms in a later course. 17

18 Two-dimensional arrays We have so far only looked at the one-dimensional arrays representing simple list of values. As a straightforward extension, the two-dimensional arrays represent a collection of values in two dimensions, or looked at from another angle, a list of pairs. 18

19 Declaration, etc. When declaring it, we now have to use two sets of brackets. For example, int [][] table; In accessing a value in such an array, we also have to give two indices to identify it, one for the row, and the other for the column. By the same token, we can declare multi-dimensional arrays, which can be used, e.g., to represent the number of students attending colleges across USA, we could use a 4D array. 19

20 An example The following piece of code declares and creates a 2D array, fills it with increasing integers, then prints them out. public class TwoDArray{ public static void main(string[] args){ int[][] table=new int[5][10]; for (int row=0; row<table.length; row++) for (int col=0; col<table[row].length; col++) table[row][col] = row * 10 + col; for (int row=0; row < table.length; row++){ for (int col=0; col < table[row].length; col++) System.out.print (table[row][col] + "\t"); System.out.println(); Question: What should the output look like? 20

21 Polygons and polylines Arrays are helpful when drawing complex shapes. A polygon is a multi-sided shape that is defined in Java using a series (list) of (x, y) points that indicate the vertices of the polygon. An array is certainly very appropriate to represent such a list of pairs. Technically, a polygon is drawn, filled or unfilled, using methods of the Graphics class, just like what we did with rectangles and ovals. Those specific methods are called drawpolygon and fillpolygon, respectively. Each of them takes three parameters, the list of x coordinates, that for the associated y, and the number of points, i.e., the size of those two lists. Finally, there is always a line drawn between the first and the last point. 21

22 A polyline is similar to the polygon as a series of segments represented with a series of points. But, the segment between the first and the last point is not automatically drawn. It is not closed, thus can t be filled. There is hence only one method, drawpolyline, which takes the same parameters as the drawpolygon does. The next slide shows an applet that draws a rocket, and its window. The first point in the array represents the tip of the rocket, the rest just goes clockwise from the tip. Both polygons are filled. 22

23 A rocket with a window import javax.swing.japplet; import java.awt.*; public class Rocket extends JApplet{ private final int APPLET_WIDTH = 200; private final int APPLET_HEIGHT = 200; private int[] xrocket={100,120,120,130,130,70,70,80,80; private int[] yrocket={15,40,115,125,150,150,125,115,40; private int[] xwindow={95,105,110,90; private int[] ywindow={45,45,70,70; private int[] xflame={70,70,75,80,90,100,110, 115,120,130,130; private int[] yflame={155,170,165,190,170,175, 160,185,160,175,155; public void init(){ setbackground (Color.black); setsize (APPLET_WIDTH, APPLET_HEIGHT); public void paint (Graphics page){ page.setcolor (Color.cyan); page.fillpolygon (xrocket, yrocket, xrocket.length); page.setcolor (Color.gray); page.fillpolygon (xwindow, ywindow, xwindow.length); page.setcolor (Color.red); page.drawpolyline (xflame, yflame, xflame.length); 23

24 More buttons We have so far discussed the push button component: once pushed, an action event is generated, which we can respond with a listener. Let s check out some other buttons. A check box is a button that can be toggled on or off using the mouse, indicating that a particular boolean condition is set or unset. For example, a check box labeled Collate can be used to indicate whether the output of a print job should be collated. If there are multiple check boxes created in your program, all of them are independent of each other. 24

25 Simple font changer The following piece changes the font of the text displayed in a text field. import javax.swing.*; public class StyleOptions{ public static void main (String[] args){ JFrame styleframe = new JFrame ("Style Options"); styleframe.setdefaultcloseoperation(jframe.exit_on_close); StyleGUI gui = new StyleGUI(); styleframe.getcontentpane().add(gui.getpanel()); styleframe.pack(); styleframe.show(); The StyleGUI class is given in the next slide. 25

26 import javax.swing.*; import java.awt.*; import java.awt.event.*; The StyleGUI class public class StyleGUI{ private final int WIDTH=300,HEIGHT=100,FONT_SIZE=36; private JLabel saying; private JCheckBox bold, italic; private JPanel primary; public StyleGUI(){ saying = new JLabel ("Say it with style!"); saying.setfont(new Font("Helvetica",Font.PLAIN,FONT_SIZE)); bold = new JCheckBox ("Bold"); bold.setbackground (Color.cyan); italic = new JCheckBox ("Italic"); italic.setbackground (Color.cyan); StyleListener listener = new StyleListener(); bold.additemlistener (listener); italic.additemlistener (listener); primary = new JPanel(); primary.add (saying); primary.add (bold); primary.add (italic); primary.setbackground(color.cyan); primary.setpreferredsize(new Dimension(WIDTH,HEIGHT)); 26

27 The StyleGUI class (Con d) public JPanel getpanel(){ return primary; private class StyleListener implements ItemListener{ public void itemstatechanged (ItemEvent event){ int style = Font.PLAIN; if (bold.isselected()) style = Font.BOLD; if (italic.isselected()) style += Font.ITALIC; saying.setfont(new Font("Helvetica",style,FONT_SIZE)); In this program, we also use the Font class, part of the Java standard library. A Font object is defined by the font name, the font style, and the font size. The name established the basic characteristic of the characters, such as Times, Helvetica, etc.. The style of a Java font can be plain, bold, italic, or bold and italic combined. The size simply decides how big the characters will look like. 27

28 Radio buttons A radio button is used with other radio buttons to provide a set of mutually exclusive options. Thus, unlike the check box, it is not meaningful by itself, and has to be used with other radio buttons. Only one option among that group is valid. In other words, at any time, exactly one radio button is on, and the rest is automatically toggle off. 28

29 Which quote do you like? The following piece of code displays a label and a set of associated radio buttons. The radio button decides which quote is to be displayed in the label. Question: What do we have to use radio button, but not a check box, in this case? Answer: Since we only want to put one quote up there. If we use check box, multiple quotes can be put there, just like multiple fonts can be added in the previous case. 29

30 Which quote do you like? The structure of the following is the same as that for the StyleOptions. import javax.swing.*; public class QuoteOptions{ public static void main (String[] args){ JFrame quoteframe = new JFrame ("Quote Options"); quoteframe.setdefaultcloseoperation (JFrame.EXIT_ON_CLOSE); QuoteGUI gui = new QuoteGUI(); quoteframe.getcontentpane().add (gui.getpanel()); quoteframe.pack(); quoteframe.show(); 30

31 The QuoteGUI class public class QuoteGUI{ private final int WIDTH = 300, HEIGHT = 100; private JPanel primary; private JLabel quote; private JRadioButton comedy,philosophy,carpentry; private String comedyquote="take my wife,please."; private String philosophyquote="i think,therefore I am."; private String carpentryquote="measure twice.cut once."; public QuoteGUI(){ quote = new JLabel (comedyquote); quote.setfont(new Font("Helvetica",Font.BOLD,24)); comedy = new JRadioButton ("Comedy", true); comedy.setbackground (Color.green); philosophy = new JRadioButton ("Philosophy"); philosophy.setbackground (Color.green); carpentry = new JRadioButton ("Carpentry"); carpentry.setbackground (Color.green); ButtonGroup group=new ButtonGroup(); group.add (comedy); group.add (philosophy); group.add (carpentry); QuoteListener listener = new QuoteListener(); comedy.addactionlistener (listener); philosophy.addactionlistener (listener); carpentry.addactionlistener (listener); primary = new JPanel(); primary.add (quote); primary.add (comedy); primary.add (philosophy); primary.add (carpentry); primary.setbackground (Color.green); primary.setpreferredsize(new Dimension(WIDTH,HEIGHT)); 31

32 The QuoteGUI class (Con d) public JPanel getpanel(){ return primary; private class QuoteListener implements ActionListener{ public void actionperformed (ActionEvent event){ Object source = event.getsource(); if (source == comedy) quote.settext (comedyquote); else if (source == philosophy) quote.settext (philosophyquote); else quote.settext (carpentryquote); 32

33 A couple of points 1. Check box and radio button, unlike push button, are toggle buttons, namely, either on or off. But, check boxes are independent of each other; while radio buttons work in a group, only one of them is on and the rest is off. 2. A button group is simply a way to define a group of buttons that will work together, thus, besides adding in, logically, into this group; all the buttons also have to be added physically into a panel to be displayed. 33

34 3. A radio button produces an action event when it is selected. The actionperformed method of the listener firstly determines the source of the event using the getsource method, and then compares it with the three radio button objects, before takes appropriate actions. Question: Why do we use == to compare source and the objects? Answer: The comparator == compares for references, thus truly identifies the source of the action. Homework: Exercise

7.3 Arrays of Strings (Objects) 7.3 Arrays of Strings (Objects) 7.3 Tunes.java. 7.3 Arrays of Objects 9/11/13. ! A UML diagram for the Tunes program

7.3 Arrays of Strings (Objects) 7.3 Arrays of Strings (Objects) 7.3 Tunes.java. 7.3 Arrays of Objects 9/11/13. ! A UML diagram for the Tunes program 7.3 Arrays of Strings (Objects)! The elements of an array can be object references! The following declara6on reserves space to store 5 references to String objects String[] words = new String[5];! Ini6ally

More information

Adding Buttons to StyleOptions.java

Adding Buttons to StyleOptions.java Adding Buttons to StyleOptions.java The files StyleOptions.java and StyleOptionsPanel.java are from Listings 5.14 and 5.15 of the text (with a couple of slight changes an instance variable fontsize is

More information

Chapter 7. Arrays are objects that help us organize large amounts of information

Chapter 7. Arrays are objects that help us organize large amounts of information Arrays 5 TH EDITION Chapter 7 Lewis & Loftus java Software Solutions Foundations of Program Design 2007 Pearson Addison-Wesley. All rights reserved Arrays Arrays are objects that help us organize large

More information

Arrays Chapter 7. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013

Arrays Chapter 7. Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 Arrays Chapter 7 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 2 Scope Arrays: Array declaration and use Bounds checking Arrays as objects Arrays of objects Command-line arguments Variable-length

More information

Chapter 6: Arrays. Presentation slides for. Java Software Solutions. for AP* Computer Science 3rd Edition

Chapter 6: Arrays. Presentation slides for. Java Software Solutions. for AP* Computer Science 3rd Edition Chapter 6: Arrays Presentation slides for Java Software Solutions for AP* Computer Science 3rd Edition by John Lewis, William Loftus, and Cara Cocking Java Software Solutions is published by Addison-Wesley

More information

b[0] = 1 b[1] = 2 b[2] = 3 b[3] = 4 b[4] = 5 c[0] = 2 c[1] = 3 c[2] = 4 c[3] = 5 c[4] = 6

b[0] = 1 b[1] = 2 b[2] = 3 b[3] = 4 b[4] = 5 c[0] = 2 c[1] = 3 c[2] = 4 c[3] = 5 c[4] = 6 APCS Arrays I. Array basics Java stores lists of values in arrays. An array is contiguous group of related memory locations. These locations are related by the fact that they all have the same name and

More information

11/19/2014. Arrays. Chapter 6: Arrays. Arrays. Arrays. Java Software Solutions for AP* Computer Science A 2nd Edition

11/19/2014. Arrays. Chapter 6: Arrays. Arrays. Arrays. Java Software Solutions for AP* Computer Science A 2nd Edition Chapter 6: Arrays Arrays An array is an ordered list of values Presentation slides for Java Software Solutions for AP* Computer Science A 2nd Edition by John Lewis, William Loftus, and Cara Cocking The

More information

H212 Introduction to Software Systems Honors

H212 Introduction to Software Systems Honors Introduction to Software Systems Honors Lecture #07: September 21, 2015 1/30 We explained last time that an array is an ordered list of values. Each value is stored at a specific, numbered position in

More information

import javax.swing.jframe; import javax.swing.joptionpane;

import javax.swing.jframe; import javax.swing.joptionpane; EvenOdd.java Printed: 11/8/17, 6:56:33 AM Page 1/1 PushCounter.java Printed: 11/8/17, 7:10:01 AM Page 1/1 //******************************************************************** // EvenOdd.java Java Foundations

More information

Graphics. Lecture 18 COP 3252 Summer June 6, 2017

Graphics. Lecture 18 COP 3252 Summer June 6, 2017 Graphics Lecture 18 COP 3252 Summer 2017 June 6, 2017 Graphics classes In the original version of Java, graphics components were in the AWT library (Abstract Windows Toolkit) Was okay for developing simple

More information

Chapter 12 Advanced GUIs and Graphics

Chapter 12 Advanced GUIs and Graphics Chapter 12 Advanced GUIs and Graphics Chapter Objectives Learn about applets Explore the class Graphics Learn about the classfont Explore the classcolor Java Programming: From Problem Analysis to Program

More information

Java - Applets. public class Buttons extends Applet implements ActionListener

Java - 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 information

Starting Out with Java: From Control Structures Through Objects Sixth Edition

Starting 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 information

Chapter 8 Arrays. Java Software Solutions. Foundations of Program Design Seventh Edition. John Lewis William Loftus

Chapter 8 Arrays. Java Software Solutions. Foundations of Program Design Seventh Edition. John Lewis William Loftus Chapter 8 Arrays Java Software Solutions Foundations of Program Design Seventh Edition John Lewis William Loftus Arrays Arrays are objects that help us organize large amounts of information Chapter 8 focuses

More information

Graphical Applications

Graphical Applications Graphical Applications The example programs we've explored thus far have been text-based They are called command-line applications, which interact with the user using simple text prompts Let's examine

More information

COMP 202. Programming With Arrays

COMP 202. Programming With Arrays COMP 202 Programming With Arrays CONTENTS: Arrays, 2D Arrays, Multidimensional Arrays The Array List Variable Length parameter lists The Foreach Statement Thinking Like A Programmer: Designing for arrays

More information

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,

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, 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 information

Java Bootcamp - Villanova University. CSC 2014 Java Bootcamp. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

Java Bootcamp - Villanova University. CSC 2014 Java Bootcamp. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Arrays CSC 2014 Java Bootcamp Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Some slides in this presentation are adapted from the slides accompanying Java Software Solutions

More information

Arrays. Outline 1/7/2011. Arrays. Arrays are objects that help us organize large amounts of information. Chapter 7 focuses on:

Arrays. Outline 1/7/2011. Arrays. Arrays are objects that help us organize large amounts of information. Chapter 7 focuses on: Arrays Arrays Arrays are objects that help us organize large amounts of information Chapter 7 focuses on: array declaration and use bounds checking and capacity arrays that store object references variable

More information

CompSci 125 Lecture 17. GUI: Graphics, Check Boxes, Radio Buttons

CompSci 125 Lecture 17. GUI: Graphics, Check Boxes, Radio Buttons CompSci 125 Lecture 17 GUI: Graphics, Check Boxes, Radio Buttons Announcements GUI Review Review: Inheritance Subclass is a Parent class Includes parent s features May Extend May Modify extends! Parent

More information

Java Programming Lecture 6

Java 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 information

CMPT 126: Lecture 6 Arrays

CMPT 126: Lecture 6 Arrays CMPT 126: Lecture 6 Arrays Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University September 25, 2007 1 Array Elements An array is a construct used to group and organize data.

More information

Programming graphics

Programming graphics Programming graphics Need a window javax.swing.jframe Several essential steps to use (necessary plumbing ): Set the size width and height in pixels Set a title (optional), and a close operation Make it

More information

Swing/GUI Cheat Sheet

Swing/GUI Cheat Sheet General reminders To display a Swing component, you must: Swing/GUI Cheat Sheet Construct and initialize the component. Example: button = new JButton ("ButtonLabel"); Add it to the content pane of the

More information

Class 16: The Swing Event Model

Class 16: The Swing Event Model Introduction to Computation and Problem Solving Class 16: The Swing Event Model Prof. Steven R. Lerman and Dr. V. Judson Harward 1 The Java Event Model Up until now, we have focused on GUI's to present

More information

Assignment #3 (Due 4/4/2017)

Assignment #3 (Due 4/4/2017) Assignment #3 (Due 4/4/2017) As a follow up to Assignment #2, modify the CheckingAccount class to add the following instance members: an array (self-expanding type) or ArrayList of Transaction objects

More information

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 7, Name:

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 7, Name: CSC 1051 Algorithms and Data Structures I Midterm Examination October 7, 2013 Name: Question Value Score 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 10 10 10 TOTAL 100 Please answer questions in the spaces

More information

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Last Class CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/ Some slides in this

More information

To gain experience using GUI components and listeners.

To 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 information

AP CS Unit 11: Graphics and Events

AP 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 information

Same idea, different implementation. Is it important?

Same idea, different implementation. Is it important? Analysis of algorithms Major field that provides tools for evaluating the efficiency of different solutions What is an efficient algorithm? Faster is better How do you measure time? Wall clock? Computer

More information

ECE 122. Engineering Problem Solving with Java

ECE 122. Engineering Problem Solving with Java ECE 122 Engineering Problem Solving with Java Lecture 13 Two Dimensional Arrays Outline Problem: How do store and manipulate data in tabular format Two-dimensional arrays easy access with 2 indices This

More information

ECE 122. Engineering Problem Solving with Java

ECE 122. Engineering Problem Solving with Java ECE 122 Engineering Problem Solving with Java Lecture 13 Two Dimensional Arrays Outline Problem: How do store and manipulate data in tabular format Two-dimensional arrays easy access with 2 indices This

More information

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Arrays, Part 2 CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/ Some slides in

More information

Arrays - Review. Two-Dimensional Arrays. Arrays, Part 2. Dr. Papalaskari 1. CSC 1051 Data Structures and Algorithms I

Arrays - Review. Two-Dimensional Arrays. Arrays, Part 2. Dr. Papalaskari 1. CSC 1051 Data Structures and Algorithms I Arrays, Part 2 CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/ Some slides in

More information

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Arrays, Part 2 CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/ Some slides in

More information

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Module 5 The Applet Class, Swings. OOC 4 th Sem, B Div Prof. Mouna M. Naravani Module 5 The Applet Class, Swings OOC 4 th Sem, B Div 2016-17 Prof. Mouna M. Naravani The layout manager helps lay out the components held by this container. When you set a layout to null, you tell the

More information

Graphical User Interface (GUI)

Graphical 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 information

Graphics Applets. By Mr. Dave Clausen

Graphics Applets. By Mr. Dave Clausen Graphics Applets By Mr. Dave Clausen Applets A Java application is a stand-alone program with a main method (like the ones we've seen so far) A Java applet is a program that is intended to transported

More information

What Is an Event? Some event handler. ActionEvent. actionperformed(actionevent e) { }

What Is an Event? Some event handler. ActionEvent. actionperformed(actionevent e) { } CBOP3203 What Is an Event? Events Objects that describe what happened Event Sources The generator of an event Event Handlers A method that receives an event object, deciphers it, and processes the user

More information

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Graphics & Applets CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/ Back to Chapter

More information

&KDSWHU$UUD\VDQG9HFWRUV

&KDSWHU$UUD\VDQG9HFWRUV &KDSWHU$UUD\VDQG9HFWRUV Presentation slides for Java Software Solutions Foundations of Program Design Second Edition by John Lewis and William Loftus Java Software Solutions is published by Addison-Wesley

More information

Graphics and Painting

Graphics and Painting Graphics and Painting Lecture 17 CGS 3416 Fall 2015 November 30, 2015 paint() methods Lightweight Swing components that extend class JComponent have a method called paintcomponent, with this prototype:

More information

Contents Chapter 1 Introduction to Programming and the Java Language

Contents Chapter 1 Introduction to Programming and the Java Language Chapter 1 Introduction to Programming and the Java Language 1.1 Basic Computer Concepts 5 1.1.1 Hardware 5 1.1.2 Operating Systems 8 1.1.3 Application Software 9 1.1.4 Computer Networks and the Internet

More information

CS1004: Intro to CS in Java, Spring 2005

CS1004: Intro to CS in Java, Spring 2005 CS4: Intro to CS in Java, Spring 25 Lecture #8: GUIs, logic design Janak J Parekh janak@cs.columbia.edu Administrivia HW#2 out New TAs, changed office hours How to create an Applet Your class must extend

More information

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

PROGRAMMING 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 information

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

CSC 1051 Data Structures and Algorithms I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Arrays, Part 2 CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/ Some slides in

More information

Arrays - Review. Initializer Lists. The for-each Loop. Arrays, Part 2. Dr. Papalaskari 1. CSC 1051 Data Structures and Algorithms I

Arrays - Review. Initializer Lists. The for-each Loop. Arrays, Part 2. Dr. Papalaskari 1. CSC 1051 Data Structures and Algorithms I Arrays, Part 2 Arrays - Review Declaration: double[] scores element type Instantiation: = new double[10]; CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences

More information

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

Topic 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 information

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!

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 = 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 information

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

Outline. 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 information

ANSWER KEY Exam 2 Computer Programming 230 Dr. St. John Lehman College City University of New York Thursday, 5 November 2009

ANSWER KEY Exam 2 Computer Programming 230 Dr. St. John Lehman College City University of New York Thursday, 5 November 2009 ANSWER KEY Exam 2 Computer Programming 230 Dr. St. John Lehman College City University of New York Thursday, 5 November 2009 1. True or False: (a) T In Alice, there is an event that is processed as long

More information

Name: Checked: Learn about listeners, events, and simple animation for interactive graphical user interfaces.

Name: 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 information

Part I: Learn Common Graphics Components

Part I: Learn Common Graphics Components OOP GUI Components and Event Handling Page 1 Objectives 1. Practice creating and using graphical components. 2. Practice adding Event Listeners to handle the events and do something. 3. Learn how to connect

More information

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling Handout 12 CS603 Object-Oriented Programming Fall 15 Page 1 of 12 Handout 14 Graphical User Interface (GUI) with Swing, Event Handling The Swing library (javax.swing.*) Contains classes that implement

More information

COMP 202. Programming With Arrays

COMP 202. Programming With Arrays COMP 202 Programming With Arrays CONTENTS: Arrays, 2D Arrays, Multidimensional Arrays The Array List Variable Length parameter lists The For-each Statement Thinking Like A Programmer: Designing for arrays

More information

Chapter 7: A First Look at GUI Applications

Chapter 7: A First Look at GUI Applications Chapter 7: A First Look at GUI Applications Starting Out with Java: From Control Structures through Objects Fourth Edition by Tony Gaddis Addison Wesley is an imprint of 2010 Pearson Addison-Wesley. All

More information

AP CS Unit 12: Drawing and Mouse Events

AP 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 information

Unit 7: Event driven programming

Unit 7: Event driven programming Faculty of Computer Science Programming Language 2 Object oriented design using JAVA Dr. Ayman Ezzat Email: ayman@fcih.net Web: www.fcih.net/ayman Unit 7: Event driven programming 1 1. Introduction 2.

More information

Java - Applications. The following code sets up an application with a drop down menu, as yet the menu does not do anything.

Java - Applications. The following code sets up an application with a drop down menu, as yet the menu does not do anything. Java - Applications C&G Criteria: 5.3.2, 5.5.2, 5.5.3 Java applets require a web browser to run independently of the Java IDE. The Dos based console applications will run outside the IDE but have no access

More information

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

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written. SOLUTION HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC212, FALL TERM, 2006 FINAL EXAMINATION 7pm to 10pm, 19 DECEMBER 2006, Jeffrey Hall 1 st Floor Instructor:

More information

Frames, 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 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 information

CSC Algorithms and Data Structures I. Midterm Examination February 25, Name:

CSC Algorithms and Data Structures I. Midterm Examination February 25, Name: CSC 1051-001 Algorithms and Data Structures I Midterm Examination February 25, 2016 Name: Question Value Score 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 10 10 10 TOTAL 100 Please answer questions in the

More information

Last Class. While loops Infinite loops Loop counters Iterations

Last Class. While loops Infinite loops Loop counters Iterations Last Class While loops Infinite loops Loop counters Iterations public class January31{ public static void main(string[] args) { while (true) { forloops(); if (checkclassunderstands() ) { break; } teacharrays();

More information

Command-Line Applications. GUI Libraries GUI-related classes are defined primarily in the java.awt and the javax.swing packages.

Command-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 information

Arrays Chapter 6 Chapter 6 1

Arrays Chapter 6 Chapter 6 1 Arrays 1 Reminders Project 4 released: due Oct 6 @ 10:30 pm Project 1 regrades due by midnight tonight Project 2 grades posted on WebCT regrade requests due by Friday Oct 7 midnight (send to rnehme@cs.purdue.edu)

More information

Graphical User Interface (GUI)

Graphical 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 information

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 25, Name: KEY A

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 25, Name: KEY A CSC 1051 Algorithms and Data Structures I Midterm Examination February 25, 2016 Name: KEY A Question Value Score 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 10 10 10 TOTAL 100 Please answer questions in

More information

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail. OOP in Java 1 Outline 1. Getting started, primitive data types and control structures 2. Classes and objects 3. Extending classes 4. Using some standard packages 5. OOP revisited Parts 1 to 3 introduce

More information

Method OverLoading printf method Arrays Declaring and Using Arrays Arrays of Objects Array as Parameters

Method OverLoading printf method Arrays Declaring and Using Arrays Arrays of Objects Array as Parameters Outline Method OverLoading printf method Arrays Declaring and Using Arrays Arrays of Objects Array as Parameters Variable Length Parameter Lists split() Method from String Class Integer & Double Wrapper

More information

Sorting and Searching

Sorting and Searching CHAPTER 13 Sorting and Searching The exercises in this chapter are a framework for comparing algorithms empirically. This approach provides students with a means for understanding the finer details of

More information

Introduction. Introduction

Introduction. 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 information

Arrays, Part 3: Multidimensional arrays

Arrays, Part 3: Multidimensional arrays Arrays, Part 3: Multidimensional arrays CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: www.csc.villanova.edu/~map/1051/

More information

Data Representation and Applets

Data Representation and Applets Data Representation and Applets CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Overview Binary representation Data types revisited

More information

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

Part 3: Graphical User Interface (GUI) & Java Applets 1,QWURGXFWLRQWR-DYD3URJUDPPLQJ (( Part 3: Graphical User Interface (GUI) & Java Applets EE905-GUI 7RSLFV Creating a Window Panels Event Handling Swing GUI Components ƒ Layout Management ƒ Text Field ƒ

More information

CSC 2014 Java Bootcamp. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

CSC 2014 Java Bootcamp. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Arrays of objects CSC 2014 Java Bootcamp Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Some slides in this presentation are adapted from the slides accompanying Java

More information

Graphics Applets. By Mr. Dave Clausen

Graphics Applets. By Mr. Dave Clausen Graphics Applets By Mr. Dave Clausen Applets A Java application is a stand-alone program with a main method (like the ones we've seen so far) A Java applet is a program that is intended to transported

More information

Graphical User Interfaces. Comp 152

Graphical User Interfaces. Comp 152 Graphical User Interfaces Comp 152 Procedural programming Execute line of code at a time Allowing for selection and repetition Call one function and then another. Can trace program execution on paper from

More information

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 9, Name: KEY

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 9, Name: KEY CSC 1051 Algorithms and Data Structures I Midterm Examination October 9, 2014 Name: KEY Question Value Score 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 10 10 10 TOTAL 100 Please answer questions in the

More information

First Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 7 October 2010

First Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 7 October 2010 First Exam Computer Programming 326 Dr. St. John Lehman College City University of New York Thursday, 7 October 2010 NAME (Printed) NAME (Signed) E-mail Exam Rules Show all your work. Your grade will be

More information

Goals. Lecture 7 More GUI programming. The application. The application D&D 12. CompSci 230: Semester JFrame subclass: ListOWords

Goals. Lecture 7 More GUI programming. The application. The application D&D 12. CompSci 230: Semester JFrame subclass: ListOWords Goals By the end of this lesson, you should: Lecture 7 More GUI programming 1. Be able to write Java s with JTextField, JList, JCheckBox and JRadioButton components 2. Be able to implement a ButtonGroup

More information

Applets and the Graphics class

Applets and the Graphics class Applets and the Graphics class CSC 2014 Java Bootcamp Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Some slides in this presentation are adapted from the slides accompanying

More information

CSC 1051 Algorithms and Data Structures I. Final Examination May 2, Name:

CSC 1051 Algorithms and Data Structures I. Final Examination May 2, Name: CSC 1051 Algorithms and Data Structures I Final Examination May 2, 2016 Name: Question Value Score 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 10 10 10 TOTAL 100 Please answer questions in the spaces provided.

More information

Java Help Files. by Peter Lavin. May 22, 2004

Java Help Files. by Peter Lavin. May 22, 2004 Java Help Files by Peter Lavin May 22, 2004 Overview Help screens are a necessity for making any application user-friendly. This article will show how the JEditorPane and JFrame classes, along with HTML

More information

Appendix F: Java Graphics

Appendix F: Java Graphics Appendix F: Java Graphics CS 121 Department of Computer Science College of Engineering Boise State University August 21, 2017 Appendix F: Java Graphics CS 121 1 / 15 Topics Graphics and Images Coordinate

More information

CSC 1051 Algorithms and Data Structures I. Final Examination May 2, Name: Question Value Score

CSC 1051 Algorithms and Data Structures I. Final Examination May 2, Name: Question Value Score CSC 1051 Algorithms and Data Structures I Final Examination May 2, 2016 Name: Question Value Score 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 10 10 10 TOTAL 100 Please answer questions in the spaces provided.

More information

Method OverLoading printf method Arrays Declaring and Using Arrays Arrays of Objects Array as Parameters

Method OverLoading printf method Arrays Declaring and Using Arrays Arrays of Objects Array as Parameters Outline Method OverLoading printf method Arrays Declaring and Using Arrays Arrays of Objects Array as Parameters Variable Length Parameter Lists split() Method from String Class Integer & Double Wrapper

More information

CSC 1051 Algorithms and Data Structures I. Final Examination May 12, Name

CSC 1051 Algorithms and Data Structures I. Final Examination May 12, Name CSC 1051 Algorithms and Data Structures I Final Examination May 12, 2017 Name Question Value Score 1 10 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 10 10 10 TOTAL 100 Please answer questions in the spaces provided.

More information

CS111: PROGRAMMING LANGUAGE II

CS111: PROGRAMMING LANGUAGE II CS111: PROGRAMMING LANGUAGE II Computer Science Department Lecture 10(b): Working with Controls Agenda 2 Case study: TextFields and Labels Combo Boxes buttons List manipulation Radio buttons and checkboxes

More information

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

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written. HAND IN Answers Are Recorded on Question Paper QUEEN'S UNIVERSITY SCHOOL OF COMPUTING CISC212, FALL TERM, 2006 FINAL EXAMINATION 7pm to 10pm, 19 DECEMBER 2006, Jeffrey Hall 1 st Floor Instructor: Alan

More information

Appendix F: Java Graphics

Appendix F: Java Graphics Appendix F: Java Graphics CS 121 Department of Computer Science College of Engineering Boise State University August 21, 2017 Appendix F: Java Graphics CS 121 1 / 1 Topics Graphics and Images Coordinate

More information

CSC 1051 Algorithms and Data Structures I. Final Examination December 17, Name:

CSC 1051 Algorithms and Data Structures I. Final Examination December 17, Name: CSC 1051 Algorithms and Data Structures I Final Examination December 17, 2013 Name: Question Value 1 10 Score 2 10 3 10 4 10 5 10 6 10 7 10 8 10 9 20 TOTAL 100 Please answer questions in the spaces provided.

More information

Give one example where you might wish to use a three dimensional array

Give one example where you might wish to use a three dimensional array CS 110: INTRODUCTION TO COMPUTER SCIENCE SAMPLE TEST 3 TIME ALLOWED: 60 MINUTES Student s Name: MAXIMUM MARK 100 NOTE: Unless otherwise stated, the questions are with reference to the Java Programming

More information

Chapter. We've been using predefined classes. Now we will learn to write our own classes to define objects

Chapter. We've been using predefined classes. Now we will learn to write our own classes to define objects Writing Classes 4 Chapter 5 TH EDITION Lewis & Loftus java Software Solutions Foundations of Program Design 2007 Pearson Addison-Wesley. All rights reserved Writing Classes We've been using predefined

More information

8. Polymorphism and Inheritance

8. Polymorphism and Inheritance 8. Polymorphism and Inheritance Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich http://seal.ifi.uzh.ch/info1 Objectives Describe polymorphism and inheritance in general Define interfaces

More information

MIT AITI Swing Event Model Lecture 17

MIT 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 information

Layouts and Components Exam

Layouts and Components Exam Layouts and Components Exam Name Period A. Vocabulary: Answer each question specifically, based on what was taught in class. Term Question Answer JScrollBar(a, b, c, d, e) Describe c. ChangeEvent What

More information

Practice Midterm 1 Answer Key

Practice Midterm 1 Answer Key CS 120 Software Design I Fall 2018 Practice Midterm 1 Answer Key University of Wisconsin - La Crosse Due Date: October 5 NAME: Do not turn the page until instructed to do so. This booklet contains 10 pages

More information

JRadioButton account_type_radio_button2 = new JRadioButton("Current"); ButtonGroup account_type_button_group = new ButtonGroup();

JRadioButton account_type_radio_button2 = new JRadioButton(Current); ButtonGroup account_type_button_group = new ButtonGroup(); Q)Write a program to design an interface containing fields User ID, Password and Account type, and buttons login, cancel, edit by mixing border layout and flow layout. Add events handling to the button

More information

Data Representation and Applets

Data Representation and Applets Data Representation and Applets CSC 1051 Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website: http://www.csc.villanova.edu/~map/1051/

More information