עקרנות תכנות מונחה עצמים

Slides:



Advertisements
Similar presentations
EXAMPLES (Arrays). Example Many engineering and scientific applications represent data as a 2-dimensional grid of values; say brightness of pixels in.
Advertisements

Graphic User Interfaces Layout Managers Event Handling.
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.
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.
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.
F27SB2 Software Development 2 Lecture 6: Java GUIs 5.
עקרונות תכנות מונחה עצמים תרגול 4 - GUI. Outline  Introduction to GUI  Swing  Basic components  Event handling.
Java Programming: Advanced Topics 1 Common Elements of Graphical User Interfaces Chapter 6.
1 Data Structures CSCI 132, Spring 2014 Lecture 4 Implementing Life.
עקרונות תכנות מונחה עצמים תרגול 6 - GUI. סיכום ביניים GUI:  Swing  Basic components  Event handling  Containers  Layouts.
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.
עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling.
SOLVING SUDOKU WITH MATLAB Raluca Marinescu, Andrea Garcia, Ivan Castro, Eduard Enoiu Mälardalen University, Västerås,
CS324e - Elements of Graphics and Visualization Java GUIs - Event Handling.
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.
Field Trip #23 Hangman By Keith Lynn. JApplet A JApplet is a top-level container An applet is a small Java program that is executed by another program.
עקרונות תכנות מונחה עצמים תרגול 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.
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.
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
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.
Practical Session 9 Computer Architecture and Assembly Language.
Introduction Many Java application use a graphical user interface or GUI (pronounced “gooey”). A GUI is a graphical window or windows that provide interaction.
EECS 110: Lec 12: Mutable Data
Chaotic Behavior - Cellular automata
Two-Dimensional Arrays
Topic Dimensional Arrays
CHAPTER 7 & 8 REVIEW QUESTIONS
Graphical User Interface (pronounced "gooey")
Rounding to Significant Figures
Illustrations of Simple Cellular Automata
Week 9 - Monday CS 121.
Ellen Walker Hiram College
Miscellaneous Topics #6: Polygons GUI Components and Event Handlers
Graphical User Interfaces -- Introduction
COS 260 DAY 13 Tony Gauvin.
עקרונות תכנות מונחה עצמים
עקרונות תכנות מונחה עצמים תרגול 7: אנימציה
Topic 26 Two Dimensional Arrays
Two-Dimensional Arrays
4.5 Applications of Pascal’s Triangle
Spatio-temporal information in society: cellular automata
Graphical User Interface
More 2 D Array.
2D Array and Matrix.
Two-Dimensional Arrays
Conway’s Game in matlab
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.
Continue with Life, Magic and Catch -up
Computer Architecture and Assembly Language
A Cellular Automata Approach to Population Modeling
CiS 260: App Dev I Chapter 6: GUI and OOD.
AP Java Learning Objectives
EECS 110: Lec 12: Mutable Data
עקרונות תכנות מונחה עצמים תרגול 7: אנימציה
Modeling Rainfall using a Cellular Automata
2D Array and Matrix Application: Game of Life
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 < 2 || 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