Presentation is loading. Please wait.

Presentation is loading. Please wait.

COS 260 DAY 23 Tony Gauvin.

Similar presentations


Presentation on theme: "COS 260 DAY 23 Tony Gauvin."— Presentation transcript:

1 COS 260 DAY 23 Tony Gauvin

2 Agenda Mini Quiz 10 Assignment 7 Due Assignment 8 Posted
Questions? Assignment 7 Due Assignment 8 Posted Dee Dec 12 Mini Quiz 10 Chapter 12 Password ElmerFudd Capstone progress report 3 Due Building Graphical User Interfaces Con’t

3 Capstone Project Capstone Project Description Fall 2017.pdf
October Proposal Due ed to Tony in Blackboard October 27 Progress Report ed to Tony in Blackboard November 17 Progress Report ed to Tony in Blackboard November Progress Report ed to Tony in Blackboard December All Deliverables & Presentation Due Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

4 Final CountDown Dec 1 Dec 5 Dec 8 Dec 12 @ 8 AM Gui’s Continued
Assignment 7 Due Miniquiz 10 Course evaluations Dec 5 Handling errors Dec 8 Min quiz 11 Dec 8 AM Assignment 8 due Capstone Projects and presentation Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

5 Building Graphical User Interfaces
Objects First with Java Building Graphical User Interfaces Replace this with your course title and your name/contact details. 6.0 © David J. Barnes and Michael Kölling

6 Overview Constructing GUIs Interface components GUI layout
Event handling © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

7 Dialogs Modal dialogs block all other interaction.
Forces a response from the user. Non-modal dialogs allow other interaction. This is sometimes desirable. May be difficult to avoid inconsistencies. © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

8 JOptionPane standard dialogs
Message dialog Message text plus an OK button. Confirm dialog Yes, No, Cancel options. Input dialog Message text and an input field. Variations are possible. © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

9 A message dialog private void showAbout() {
JOptionPane.showMessageDialog(frame, "ImageViewer\n" + VERSION, "About ImageViewer", JOptionPane.INFORMATION_MESSAGE); } © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

10 Image filters Functions applied to the whole image.
int height = getHeight(); int width = getWidth(); for(int y = 0; y < height; y++) { for(int x = 0; x < width; x++) { Color pixel = getPixel(x, y); alter the pixel's color value; setPixel(x, y, pixel); } © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

11 Adding further filters
private void makeLighter() { if(currentImage != null) { currentImage.lighter(); frame.repaint(); showStatus("Applied: lighter"); } else { showStatus("No image loaded."); Code duplication? Refactor! private void threshold() { if(currentImage != null) { currentImage.threshold(); frame.repaint(); showStatus("Applied: threshold"); } else { showStatus("No image loaded."); © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

12 Adding further filters
Define a Filter superclass (abstract). Create function-specific subclasses. Create a collection of subclass instances in ImageViewer. Define a generic applyFilter method. See imageviewer2-0. © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

13 imageviewer2-0 Ex 13.38 © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

14 Buttons and nested layouts
A GridLayout inside a FlowLayout inside a BorderLayout. Ex 13.45 13.46 , , 13.48 © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

15 Borders Used to add decoration around components.
Defined in javax.swing.border BevelBorder, CompoundBorder, EmptyBorder, EtchedBorder, TitledBorder. © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

16 Adding spacing JPanel contentPane = (JPanel)frame.getContentPane();
contentPane.setBorder(new EmptyBorder(6, 6, 6, 6)); // Specify the layout manager with nice spacing contentPane.setLayout(new BorderLayout(6, 6)); imagePanel = new ImagePanel(); imagePanel.setBorder(new EtchedBorder()); contentPane.add(imagePanel, BorderLayout.CENTER); © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

17 Other components Slider
Spinner Tabbed pane Scroll pane © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

18 Nested class syntax Class definitions may be nested.
public class Enclosing { … private class Inner { … } } This is tight coupling © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

19 Inner classes Instances of the inner class are localized within the enclosing class. Instances of the inner class have access to the private members of the enclosing class. © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

20 Anonymous inner classes
Obey the rules of inner classes. Used to create one-off objects for which a class name is not required. Use a special syntax. The instance is always referenced via its supertype, as it has no subtype name. © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

21 Anonymous action listener
JMenuItem openItem = new JMenuItem("Open"); openItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { openFile(); } }); Compare with the lambda version © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

22 Lambda for ActionListener
JMenuItem openItem = new JMenuItem("Open"); ... openItem.addActionListener( (ActionEvent ev) -> { openFile(); } ); General form item.addActionListener(ev -> { actions }); © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

23 Why use inner classes? The Lambda notations only works with functional interface (one abstract message) Most listener(s) have more than one interface Sometime we use adapters instead of listeners Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling

24 Anonymous class elements
Anonymous object creation openItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) openFile(); } ); Class definition Actual parameter © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

25 Exit on window close frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); WindowAdapter provides a no-op implementation of the WindowListener interface. © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

26 Review Aim for cohesive application structures.
Endeavor to keep GUI elements separate from application functionality. Pre-defined components simplify creation of sophisticated GUIs. Layout managers handle component juxtaposition. Nest containers for further control. © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.

27 Review Many components recognize user interactions with them.
Reactive components deliver events to listeners. Lambdas are commonly used to implement listeners. Anonymous inner classes are used where lambdas are not possible. © 2017 Pearson Education, Inc. Hoboken, NJ. All rights reserved.


Download ppt "COS 260 DAY 23 Tony Gauvin."

Similar presentations


Ads by Google