41
תתתתתתת תתתתת תתתתת תתתתת תתתתת5 - GUI

עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם : Introduction to GUI Swing Basic components Event handling

Embed Size (px)

Citation preview

Page 1: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

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

GUI - 5תרגול

Page 2: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

בשיעור הקודם:

Introduction to GUI

Swing

Basic components

Event handling

Page 3: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Outline

Containers

Layouts

Advanced examples

Page 4: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Top-Level Containers

Swing uses tree top-level contauners:

Page 5: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Top-Level Containers

Page 6: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

General-Purpose Containers

JPanel

Contains other components (JButton,JLabel,…)

Can be contained by Top-Level Containers

We can set its own features such as Background Color, Layout, size,etc...

JPanel buttonPanel = new JPanel( new FlowLayout());

buttonPanel.setBackground(Color.magenta);

buttonPanel.add(convertButton);

buttonPanel.add(resetButton);

buttonPanel.add(changeButton);

getContentPane().add(buttonPanel);

Page 7: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

General-Purpose Containers

Scroll Pane

Takes another component(the ViewportView)

and displays it with scrollers (if necessary)

textArea = new JTextArea(10,30);

JScrollPane sp = new JScrollPane(textArea);

Page 8: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

General-Purpose Containers

Split Pane

Takes two component and displays them

with a moveable splitter in the middle

splitPane = new JSplitPane(Jsplitpane.HORIZONTAL_SPLIT,

listScrollPane, pictureScrollPane);

splitPane.setDividerLocation(150);

Page 9: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

General-Purpose Containers

Tabbed Pane

Can be given any number of components

as tabs by using addTab

JTabbedPane tp = new JTabbedPane();

Tp.addTab(“Tab 1”, icon, panel1);

Page 10: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

General-Purpose Containers

Toolbar

Lays out buttons conveniently

Page 11: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Layouts

Page 12: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Simple Layouts

Page 13: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Example 1

PIZZA PANEL

Page 14: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Example 1: Pizza panel

Page 15: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

The Pizza Class

Page 16: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Recalculating

Page 17: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Making Spinners

Page 18: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Making Checkboxes

Page 19: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Making the Frame

Page 20: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Toppings Panel

Page 21: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Cost Panels

Page 22: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Wrapping Up the Frame

Page 23: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Advanced Layouts

Spring Layout

Allows specifying distances between pairs of components (“springs”)

Page 24: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Spring Layout

Page 25: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Advanced Layouts

GridBag Layout

Like grid, but inner components can span over several cells and respond differently to re-sizing.

Page 26: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

GridBag Constraints

Page 27: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Desigging GridBag Layouts

Page 28: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Desigging GridBag Layouts

Page 29: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Example 2

Personal Details Panel

Page 30: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Personal Details Panel

Page 31: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Reminder: Gridbag Constaints

Page 32: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Personal Details Panel

Page 33: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Personal Details Panel Constructor

Page 34: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Prototype Constraints

Page 35: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Name and Surname

Page 36: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Gender Panel

Page 37: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Age Spinner

Page 38: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Address

Page 39: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Comments Panel

Page 40: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Putting in all together

Page 41: עקרונות תכנות מונחה עצמים תרגול 5 - GUI. בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

Layout Considerations

What to consider when planning a layout?

Not distorted by resize

Aligned, visually attractive

Put important data in the center, auxiliaries on the sides

Flexible, user-controlled

Usable