Download presentation
Presentation is loading. Please wait.
1
עקרונות תכנות מונחה עצמים
תרגול GUI
2
Outline Game of Life Painting
3
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); }
4
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)
5
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); }
6
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.
7
Example 1: Canvas
8
DrawingCanvas Class
9
Main method
10
The modified program
11
The modified program
12
Example 2: Graphicak Calculator
13
Polynom Class
14
Calculator Class
15
MainWin Class
16
MainWin Class
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.