עקרונות תכנות מונחה עצמים תרגול 6 - gui. outline game of life painting
TRANSCRIPT
![Page 1: עקרונות תכנות מונחה עצמים תרגול 6 - GUI. Outline Game of Life Painting](https://reader033.vdocuments.site/reader033/viewer/2022061612/5697bfab1a28abf838c9ac5c/html5/thumbnails/1.jpg)
עקרונות תכנות מונחה עצמים
GUI - 6תרגול
![Page 2: עקרונות תכנות מונחה עצמים תרגול 6 - GUI. Outline Game of Life Painting](https://reader033.vdocuments.site/reader033/viewer/2022061612/5697bfab1a28abf838c9ac5c/html5/thumbnails/2.jpg)
Outline
Game of Life
Painting
![Page 3: עקרונות תכנות מונחה עצמים תרגול 6 - GUI. Outline Game of Life Painting](https://reader033.vdocuments.site/reader033/viewer/2022061612/5697bfab1a28abf838c9ac5c/html5/thumbnails/3.jpg)
The paint method
Each graphical component has a paint method.
To perform a painting of a component we need to override its paint method.
public class MyPanel extends Jpanel {
…
public void paint(Graphics g){
super.paint(g);
…
}
}
![Page 4: עקרונות תכנות מונחה עצמים תרגול 6 - GUI. Outline Game of Life Painting](https://reader033.vdocuments.site/reader033/viewer/2022061612/5697bfab1a28abf838c9ac5c/html5/thumbnails/4.jpg)
The Graphics object
Graphics methods:
drawLine(int x1, int y1, int x2, int y2)
drawOval(int x, int y, int width, int height)
drawRect(int x, int y, int width, int height)
fillOval(int x, int y, int width, int height)
fillRect(int x, int y, int width, int height)
…
setColor(Color c)
![Page 5: עקרונות תכנות מונחה עצמים תרגול 6 - GUI. Outline Game of Life Painting](https://reader033.vdocuments.site/reader033/viewer/2022061612/5697bfab1a28abf838c9ac5c/html5/thumbnails/5.jpg)
Example
public class MyPanel extends Jpanel {
…
public void paint(Graphics g){
super.paint(g);
g.drawLine(0,0,200,200);
g.fillRect(10,20,50,50);
…
}
}
![Page 6: עקרונות תכנות מונחה עצמים תרגול 6 - GUI. Outline Game of Life Painting](https://reader033.vdocuments.site/reader033/viewer/2022061612/5697bfab1a28abf838c9ac5c/html5/thumbnails/6.jpg)
Invoking the paint method
The paint method is invoked automatically:
Once the component appears for the first time.
Each time the component is resized.
Each time the component moves.
Each time the component becomes visible
Invoking the method explicity is performed using the method repaint() of the component.
![Page 7: עקרונות תכנות מונחה עצמים תרגול 6 - GUI. Outline Game of Life Painting](https://reader033.vdocuments.site/reader033/viewer/2022061612/5697bfab1a28abf838c9ac5c/html5/thumbnails/7.jpg)
Example 1: Canvas
![Page 8: עקרונות תכנות מונחה עצמים תרגול 6 - GUI. Outline Game of Life Painting](https://reader033.vdocuments.site/reader033/viewer/2022061612/5697bfab1a28abf838c9ac5c/html5/thumbnails/8.jpg)
DrawingCanvas Class
![Page 9: עקרונות תכנות מונחה עצמים תרגול 6 - GUI. Outline Game of Life Painting](https://reader033.vdocuments.site/reader033/viewer/2022061612/5697bfab1a28abf838c9ac5c/html5/thumbnails/9.jpg)
Main method
![Page 10: עקרונות תכנות מונחה עצמים תרגול 6 - GUI. Outline Game of Life Painting](https://reader033.vdocuments.site/reader033/viewer/2022061612/5697bfab1a28abf838c9ac5c/html5/thumbnails/10.jpg)
The modified program
![Page 11: עקרונות תכנות מונחה עצמים תרגול 6 - GUI. Outline Game of Life Painting](https://reader033.vdocuments.site/reader033/viewer/2022061612/5697bfab1a28abf838c9ac5c/html5/thumbnails/11.jpg)
The modified program
![Page 12: עקרונות תכנות מונחה עצמים תרגול 6 - GUI. Outline Game of Life Painting](https://reader033.vdocuments.site/reader033/viewer/2022061612/5697bfab1a28abf838c9ac5c/html5/thumbnails/12.jpg)
Example 2: Graphicak Calculator
![Page 13: עקרונות תכנות מונחה עצמים תרגול 6 - GUI. Outline Game of Life Painting](https://reader033.vdocuments.site/reader033/viewer/2022061612/5697bfab1a28abf838c9ac5c/html5/thumbnails/13.jpg)
Polynom Class
![Page 14: עקרונות תכנות מונחה עצמים תרגול 6 - GUI. Outline Game of Life Painting](https://reader033.vdocuments.site/reader033/viewer/2022061612/5697bfab1a28abf838c9ac5c/html5/thumbnails/14.jpg)
Calculator Class
![Page 15: עקרונות תכנות מונחה עצמים תרגול 6 - GUI. Outline Game of Life Painting](https://reader033.vdocuments.site/reader033/viewer/2022061612/5697bfab1a28abf838c9ac5c/html5/thumbnails/15.jpg)
MainWin Class
![Page 16: עקרונות תכנות מונחה עצמים תרגול 6 - GUI. Outline Game of Life Painting](https://reader033.vdocuments.site/reader033/viewer/2022061612/5697bfab1a28abf838c9ac5c/html5/thumbnails/16.jpg)
MainWin Class