Presentation is loading. Please wait.

Presentation is loading. Please wait.

עקרונות תכנות מונחה עצמים תרגול 6 - GUI. Outline  Game of Life  Painting.

Similar presentations


Presentation on theme: "עקרונות תכנות מונחה עצמים תרגול 6 - GUI. Outline  Game of Life  Painting."— Presentation transcript:

1 עקרונות תכנות מונחה עצמים תרגול 6 - 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

12 Example 2: Graphicak Calculator

13 Polynom Class

14 Calculator Class

15 MainWin Class

16


Download ppt "עקרונות תכנות מונחה עצמים תרגול 6 - GUI. Outline  Game of Life  Painting."

Similar presentations


Ads by Google