Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 280 Data Structures Professor John Peterson. Quiz 4 Recap Consider the following array: {2, 6, 7, 3, 4, 1, 5, 9}. Draw this in tree form and then show.

Similar presentations


Presentation on theme: "CS 280 Data Structures Professor John Peterson. Quiz 4 Recap Consider the following array: {2, 6, 7, 3, 4, 1, 5, 9}. Draw this in tree form and then show."— Presentation transcript:

1 CS 280 Data Structures Professor John Peterson

2 Quiz 4 Recap Consider the following array: {2, 6, 7, 3, 4, 1, 5, 9}. Draw this in tree form and then show the array after each exchange in stage 1 of heapsort. For stage 2, show the array NOT in tree form but as an array at the end of each iteration of the loop after the swap and the call to heapify Suppose we sort an array of 1,000,000 items. What is the maximum number of calls to heapify generated by heapify(0, s, 1000000)? You can use round numbers – off by 1 is good enough.

3 New Timetable Projects due Monday Homework due Friday

4 This Week We have a big “todo” this week – understanding how to create animations in Java. Note – we’re not using the ACM library! No homework this week so you can concentrate on coding. I will go through the theory here and then let you work on the project in Netbeans.

5 How to do Animation Need a JFrame at the top level (this is something you can select in NetBeans when you create a file) The JFrame has two views: code and design. You can switch between these. Code shows the actual code with protected areas, design shows what happens when the code runs.

6 How to do Animation Top level variables have to go in the JFrame There’s a special place for initialization if you want to do something at startup You need to set up a timer to wake the program up to display the next frame of animation The timer calls a “step()” method to change the animation state

7 How to do Animation Objects which change during the animation need a custom paint method. You need to subclass the Java objects to add this You need to use custom creation code in Netbeans to make this work Objects like buttons can talk to the program through events Drag and drop to create objects

8 How to do Animation Widgets to know: JPanel: a place to draw pictures JButton: a push button that sends “ActionPerformed” when you push it JLabel: a place to put text Graphics: this is a class used to draw pictures – it’s part of the repaint process

9 How to do Animation Drawing: Use setColor to choose a paint color Use fillRectangle to create rectangles (that’s all we need in this class) (0,0) is at the top left, coordinates are in pixels Labels: setText is needed to change the text Set the font at design time

10 Your Program import all sorts of library stuff Main class (extends JFrame) Program level vars, including timer Classes to add graphics to GUI objects Constructor Place initializers here (timer too) Step() method to change animation Event handlers and helpers

11 Into the Wiki Start your Netbeans now Todays stuff doesn’t need the previous project. http://wiki.western.edu/mcis/index.php /CIS280/f07/project5http://wiki.western.edu/mcis/index.php /CIS280/f07/project5


Download ppt "CS 280 Data Structures Professor John Peterson. Quiz 4 Recap Consider the following array: {2, 6, 7, 3, 4, 1, 5, 9}. Draw this in tree form and then show."

Similar presentations


Ads by Google