עקרונות תכנות מונחה עצמים תרגול 6 - GUI. סיכום ביניים GUI:  Swing  Basic components  Event handling  Containers  Layouts.

Slides:



Advertisements
Similar presentations
COSC2007 Data Structures II
Advertisements

EXAMPLES (Arrays). Example Many engineering and scientific applications represent data as a 2-dimensional grid of values; say brightness of pixels in.
Mouse Listeners We continue our examination of GUIs by looking at how to interact with the mouse –Just as Java creates Events when the user interacts with.
Graphic User Interfaces Layout Managers Event Handling.
Deitel Ch 11-part 1 Java GUIs 1 Java GUIs (Deitel, Chap 14-part1) Focus: Attaching GUI components + event handling  input dialog => only one value for.
Game of Life Rules and Games Linh Tran ECE 573. What is Life? Life is just one example of a cellular automaton, which is any system in which rules are.
1 The Game of Life Supplement 2. 2 Background The Game of Life was devised by the British mathematician John Horton Conway in More sophisticated.
Week 9: Methods 1.  We have written lots of code so far  It has all been inside of the main() method  What about a big program?  The main() method.
Java Swing Toolkit Graphics The key to effectively using graphics in Java is understanding: –the basic components of the graphics library –the patterns.
Lecture 15 Graphical User Interfaces (GUI’s). Objectives Provide a general set of concepts for GUI’s Layout manager GUI components GUI Design Guidelines.
© Marty Hall, Larry Brown Web core programming 1 Advanced Swing Custom Data Models and Cell Renderers.
CS305j Introduction to Computing Two Dimensional Arrays 1 Topic 22 Two Dimensional Arrays "Computer Science is a science of abstraction -creating the right.
1 Object Oriented Design & Patterns Part 1. 2 Design Patterns Derived from architectural patterns: –rules for design of buildings –describe common problems,
Click here to start round 2! You Should Know Access FunctionsSay.
Variations of Conway’s Game of Life Eswar Kondapavuluri.
Introduction Computational Challenges Serial Solutions Distributed Memory Solution Shared Memory Solution Parallel Analysis Conclusion Introduction: 
ARRAYS EXAMPLE: THE GAME OF LIFE CITS Scope of this lecture The Game of Life Implementation Performance Issues References:
Week 4-5 Java Programming. Loops What is a loop? Loop is code that repeats itself a certain number of times There are two types of loops: For loop Used.
ACM/JETT Workshop - August 4-5, ExceptionHandling and User Interfaces (Event Delegation, Inner classes) using Swing.
F27SB2 Software Development 2 Lecture 6: Java GUIs 5.
עקרונות תכנות מונחה עצמים תרגול 4 - GUI. Outline  Introduction to GUI  Swing  Basic components  Event handling.
CELLULAR AUTOMATA RULES GENERATOR FOR MICROBIAL COMMUNITIES CALIFORNIA STATE UNIVERSITY, SAN BERNARDINO SCHOOL OF COMPUTER SCIENCE & ENGINEERING By Melissa.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
The Game of Life A simulation of "life". From simple rules, complex behavior arises Rules –A cell that is alive and has fewer than two live neighbors dies.
Topic 26 Two Dimensional Arrays "Computer Science is a science of abstraction -creating the right model for a problem and devising the appropriate mechanizable.
Parallel Programming 0024 Spring Semester 2010 May 6, 2010.
1 Data Structures CSCI 132, Spring 2014 Lecture 4 Implementing Life.
Programming Principles Chapter 1. Objectives Discuss the program design process. Introduce the Game of Life. Discuss object oriented design. – Information.
Review Recursion Call Stack. Two-dimensional Arrays Visualized as a grid int[][] grays = {{0, 20, 40}, {60, 80, 100}, {120, 140, 160}, {180, 200, 220}};
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
1 Outline 1 Introduction 2 Overview of Swing Components 3 JLabel 4 Event Handling 5 TextFields 6 How Event Handling Works 7 JButton 8 JCheckBox and JRadioButton.
Graphic User Interface. Graphic User Interface (GUI) Most of us interact with computers using GUIs. GUIs are visual representations of the actions you.
Homework 9 Due ( M & T sections ) ( W & Th sections ) at midnight Sun., 11/3 Mon., 11/4 Problems
עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling.
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
The Abstract Window Toolkit (AWT) supports Graphical User Interface (GUI) programming. AWT features include: a rich set of user interface components; a.
A Variation on Conway’s Game of Life Winston Lee EPS 109.
Clicker questions 11/14/13 CSE 1102 Fall A. Composite B. Holder C. Proxy D. Factory E. Impossible to tell from diagram In this example, we want.
Graphics in Java Dr. Andrew Wallace PhD BEng(hons) EurIng
CS1010E Programming Methodology Tutorial 9 Pointers in Arrays & Structures C14,A15,D11,C08,C11,A02.
עקרונות תכנות מונחה עצמים תרגול 6 - GUI. Outline  Game of Life  Painting.
Review_6 AWT, Swing, ActionListener, and Graphics.
עקרונות תכנות מונחה עצמים תרגול 8: MVC. Outline  MVC  Using the default models  Example- File Browser.
Ajmer Singh PGT(IP) JAVA IDE Programming - I. Ajmer Singh PGT(IP) GUI (Graphical User Interface) It is an interface that uses a graphic entities along.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Advanced Swing Custom Data Models and Cell Renderers.
A cannon game ?. Simple version angle from command line, one shot only Coordinate system is “upside-down”: Use dy(int) method to transform y coordinate:
Week 9 - Monday.  What did we talk about last time?  Method practice  Lab 8.
עקרונות תכנות מונחה עצמים תרגול 7: אנימציה. בשבוע שעבר  paint  Graphics  repaint.
1 Layout Managers Layout managers –Provided for arranging GUI components –Provide basic layout capabilities –Processes layout details –Programmer can concentrate.
Week 9 - Wednesday.  What did we talk about last time?  2D arrays  Queen attacking pawn example  Started Game of Life.
Mouse Events GUI. Types of Events  Below, are some of the many kinds of events, swing components generate. Act causing EventListener Type User clicks.
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
1 Working with Controls at Run Time. 2 Objectives You will be able to Add controls to a Windows form at run time. Modify controls at run time.
Introduction to GUI in 1 Graphical User Interface 3 Nouf Almunyif.
Java Threads 1 1 Threading and Concurrent Programming in Java Threads and Swing D.W. Denbo.
GUIs & Event-Driven Programming Chapter 11 Review.
Practical Session 9 Computer Architecture and Assembly Language.
עקרונות תכנות מונחה עצמים תרגול 7: כתיבה לקבצים
Graphical User Interface (pronounced "gooey")
עקרנות תכנות מונחה עצמים
עקרונות תכנות מונחה עצמים
עקרונות תכנות מונחה עצמים תרגול 7: אנימציה
More 2 D Array.
Computer Architecture and Assembly Language
Task 2 Implementation help
int DP_ABString(int count) { int fa[1000], fb[1000]; if(count > 1000) return -1; memset(fa, 0, sizeof(fa)); memset(fb, 0, sizeof(fb)); for(int i.
Computer Architecture and Assembly Language
עקרונות תכנות מונחה עצמים תרגול 7: אנימציה
TA: Nouf Al-Harbi NoufNaief.net :::
Presentation transcript:

עקרונות תכנות מונחה עצמים תרגול 6 - GUI

סיכום ביניים GUI:  Swing  Basic components  Event handling  Containers  Layouts

Outline  Game of Life  Painting

Case Study Game of Life

Conway’s Game of Life

Basic Rules  Each cell in the grid is either live or dead  The user determines the initial positions of all live cells.  The game proceeds in rounds. In each round some new organisms born, and others die, according to predefined evolution rules.

Neighbors  The neighbors of a cell are the cells that surround it.

Neighbors  The neighbors of a cell are the cells that surround it.

Evolution Rules  Any live cell with fewer than two live neighbors dies, as if caused by under-population.  Any live cell with two or three live neighbors lives on to the next generation.  Any live cell with more than three live neighbors dies as if by overcrowding.  Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction

Program clasess  Game – Main class that creates the graphical user interface.  Board – A class that represents the game board. Holds an array of integers and an array of buttons  ButtonPressed – An ActionListener for setting the initial position MODEL VIEW

Game Class

Board Class

public void next ( ) { int [ ] [ ] lastState = new int [ N +2] [ N +2] ; for(int i = 1 ; i <= N ; i++){ // copy current state to new array. for ( int j =1 ; j <= N ; j++){ lastState [i][j] = array [i-1][j-1]; } } // top and buttom row (i = 0,N+1), left and right culomn(j= 0,N+1) initiate to 0 for ( int i = 0 ; i < N ; i++){ // update current state. for(int j < 1; j <= N ; j++ ){ int count = 0; count = countNeighbors(lastState,i+1,j+1); if(count 3 ){ //check for under-population or overcrowding killCell(i,j); } if(count == 3) { // check for reproduction reviveCell(i,j); } private int countNeighbors(int[][] lastState,int x, int y){ int count = lastState[x-1][y-1] + lastState[x-1][y]+lastState[x-1][y+1] // all 3 neighbors left to current cell + lastState[x][y-1] + lastState[x][y+1] // the cell above current and the cell below + lastState[x+1][y-1] + lastState[x+1][y]+lastState[x+1][y+1] ; // all 3 neighbors left to current cell return count; } private void killCell( int i, int j ){ array [i][j] = 0; buttons [i][j].setIcon( null ); } private void reviveCell( int i, int j ){ array [i][j] = 1; buttons [i][j].setIcon( new ImageIcon( “button.gif” )); } }//end of Board class

ButtonPressed Class