Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


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

1 עקרונות תכנות מונחה עצמים תרגול 5 - GUI

2 בשיעור הקודם :  Introduction to GUI  Swing  Basic components  Event handling

3 Outline  Containers  Layouts  Advanced examples

4 Top-Level Containers  Swing uses tree top-level contauners:

5 Top-Level Containers

6 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);

7 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); …

8 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);

9 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);

10 General-Purpose Containers Toolbar  Lays out buttons conveniently

11 Layouts

12 Simple Layouts

13 Example 1 PIZZA PANEL

14 Example 1: Pizza panel

15 The Pizza Class

16 Recalculating

17 Making Spinners

18 Making Checkboxes

19 Making the Frame

20 Toppings Panel

21 Cost Panels

22 Wrapping Up the Frame

23 Advanced Layouts Spring Layout  Allows specifying distances between pairs of components (“springs”)

24 Spring Layout

25 Advanced Layouts GridBag Layout  Like grid, but inner components can span over several cells and respond differently to re-sizing.

26 GridBag Constraints

27 Desigging GridBag Layouts

28

29 Example 2 Personal Details Panel

30

31 Reminder: Gridbag Constaints

32 Personal Details Panel

33 Personal Details Panel Constructor

34 Prototype Constraints

35 Name and Surname

36 Gender Panel

37 Age Spinner

38 Address

39 Comments Panel

40 Putting in all together

41 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


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

Similar presentations


Ads by Google