16
תתתתתתת תתתתת תתתתת תתתתת תתתתת6 - GUI

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

Embed Size (px)

Citation preview

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

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

GUI - 6תרגול

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

Outline

Game of Life

Painting

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

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

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

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

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

Example 1: Canvas

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

DrawingCanvas Class

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

Main method

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

The modified program

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

The modified program

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

Example 2: Graphicak Calculator

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

Polynom Class

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

Calculator Class

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

MainWin Class

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

MainWin Class