$30 off During Our Annual Pro Sale. View Details »

CSE460 Lecture 15

CSE460 Lecture 15

Software Analysis and Design
Practice
(202103)

Javier Gonzalez-Sanchez
PRO

July 15, 2020
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. jgs
    CSE 460
    Software Analysis and Design
    Lecture 15: Practice
    Dr. Javier Gonzalez-Sanchez
    [email protected]
    javiergs.engineering.asu.edu | javiergs.com
    PERALTA 230U
    Office Hours: By appointment

    View Slide

  2. jgs
    Proctoring
    Respondus LockDown Browser

    View Slide

  3. jgs
    00000001
    Proctoring

    View Slide

  4. jgs
    00000001
    Proctoring
    You need
    A camera

    View Slide

  5. jgs
    00000001
    Proctoring

    View Slide

  6. jgs
    00000001
    Agenda
    § Sample Exam is available. Test your system ASAP
    § Read the Online Proctored Exam Guidelines to know what to do in case of
    a problem during the exam
    § Midterm Exam available March 10
    only during lecture time from 4:30 pm to 5:45 pm.
    § No lecture that day. Go directly to your exam
    § It is a CLOSED BOOK exam. Do not use any material
    § Scratch paper is allowed. Empty White Paper. Show it on camera when you
    show your environment!

    View Slide

  7. jgs
    Previously …

    View Slide

  8. jgs
    00000001
    GoF Patterns

    View Slide

  9. jgs
    Extra Example 1
    Text Mode

    View Slide

  10. jgs
    00000001
    Decorator

    View Slide

  11. jgs
    00000001
    Main

    View Slide

  12. jgs
    00000001
    Companion
    public interface Companion {
    public void doSomething();
    }

    View Slide

  13. jgs
    00000001
    BasicCompanion
    public class BasicCompanion implements Companion {
    @Override
    public void doSomething() {
    System.out.print("Hello Student, ");
    }
    }

    View Slide

  14. jgs
    00000001
    CompanionDecorator
    public class CompanionDecorator implements Companion {
    protected Companion c;
    public void add(Companion c){
    this.c = c;
    }
    @Override
    public void doSomething() {
    this.c.doSomething();
    }
    }

    View Slide

  15. jgs
    00000001
    HelperCompanion
    public class HelperCompanion extends CompanionDecorator {
    @Override
    public void doSomething(){
    super.doSomething();
    System.out.print(" I am here to help you. ");
    }
    }

    View Slide

  16. jgs
    00000001
    AffectiveCompanion
    public class AffectiveCompanion extends CompanionDecorator {
    @Override
    public void doSomething(){
    super.doSomething();
    System.out.print(" I am here to cheer you.");
    }
    }

    View Slide

  17. jgs
    00000001
    Main

    View Slide

  18. jgs
    Extra Example 2
    Adding a GUI

    View Slide

  19. jgs
    00000001
    GUI

    View Slide

  20. jgs
    00000001
    Decorator

    View Slide

  21. jgs
    00000001
    Main
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    public class Main extends JFrame implements ActionListener {
    CompanionPanel panel = new CompanionPanel ();
    JButton b1 = new JButton("standard");
    JButton b2 = new JButton("help");
    JButton b3 = new JButton("affect");
    JButton b4 = new JButton("helper+affect");
    public Main() {
    setLayout(new BorderLayout(3,2));
    add (panel, BorderLayout.CENTER);
    JPanel control = new JPanel(new GridLayout(1,4));
    control.add (b1); b1.addActionListener(this);
    control.add (b2); b2.addActionListener(this);
    control.add (b3); b3.addActionListener(this);
    control.add (b4); b4.addActionListener(this);
    add (control, BorderLayout.SOUTH);
    }

    View Slide

  22. jgs
    @Override
    public void actionPerformed(ActionEvent e) {
    if (e.getSource()==b1) {
    BasicCompanion basic = new BasicCompanion();
    panel.setCompanion(basic); panel.showYourself();
    } else if (e.getSource()==b2) {
    BasicCompanion basic = new BasicCompanion();
    HelperCompanion helper = new HelperCompanion();
    helper.add(basic);
    panel.setCompanion(helper); panel.showYourself();
    } else if (e.getSource()==b3) {
    BasicCompanion basic = new BasicCompanion();
    AffectiveCompanion h = new AffectiveCompanion();
    h.add(basic);
    panel.setCompanion(h); panel.showYourself();
    } else if (e.getSource()==b4) {
    HelperCompanion helper2 = new HelperCompanion();
    AffectiveCompanion affective = new AffectiveCompanion();
    BasicCompanion basic2 = new BasicCompanion();
    helper2.add(affective);
    affective.add(basic2);
    panel.setCompanion(helper2);panel.showYourself();
    }
    }
    public static void main(String[] args) {
    JFrame main = new Main();
    main.setSize(500,500);
    main.setVisible(true);
    main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
    }

    View Slide

  23. jgs
    00000001
    CompanionPanel
    import java.awt.GridLayout;
    import javax.swing.JLayeredPane;
    public class CompanionPanel extends JLayeredPane{
    public Companion brain;
    public void setCompanion(Companion x) {
    brain = x;
    }
    public void showYourself() {
    removeAll();
    setLayout(new GridLayout(1,1));
    brain.doSomething(this);
    revalidate();
    }
    }

    View Slide

  24. jgs
    00000001
    Companion
    import javax.swing.JComponent;
    public interface Companion {
    public void doSomething(JComponent panel);
    }

    View Slide

  25. jgs
    00000001
    BasicCompanion
    import javax.swing.ImageIcon;
    import javax.swing.JComponent;
    import javax.swing.JLabel;
    public class BasicCompanion implements Companion {
    @Override
    public void doSomething(JComponent panel) {
    ImageIcon face = new ImageIcon("src/face.png");
    JLabel label = new JLabel();
    label.setIcon(face);
    label.setHorizontalTextPosition(JLabel.CENTER);
    label.setVerticalTextPosition(JLabel.BOTTOM);
    label.setText("Hello Student, ");
    panel.add(label);
    }
    }

    View Slide

  26. jgs
    00000001
    CompanionDecorator
    import javax.swing.JComponent;
    public class CompanionDecorator implements Companion {
    protected Companion c;
    public void add(Companion c){
    this.c=c;
    }
    @Override
    public void doSomething(JComponent panel) {
    this.c.doSomething(panel);
    }
    }

    View Slide

  27. jgs
    00000001
    AffectiveCompanion
    import javax.swing.ImageIcon;
    import javax.swing.JComponent;
    import javax.swing.JLabel;
    public class AffectiveCompanion extends CompanionDecorator {
    @Override
    public void doSomething(JComponent panel){
    super.doSomething(panel);
    ImageIcon face = new ImageIcon("src/cheer.png");
    JLabel label = new JLabel();
    label.setIcon(face);
    label.setHorizontalTextPosition(JLabel.CENTER);
    label.setVerticalTextPosition(JLabel.BOTTOM);
    label.setText("I am here to cheer you.");
    panel.add(label);
    }
    }

    View Slide

  28. jgs
    00000001
    HelperCompanion
    import javax.swing.ImageIcon;
    import javax.swing.JComponent;
    import javax.swing.JLabel;
    public class HelperCompanion extends CompanionDecorator {
    @Override
    public void doSomething(JComponent panel){
    super.doSomething(panel);
    ImageIcon face = new ImageIcon("src/bubble.png");
    JLabel label = new JLabel();
    label.setIcon(face);
    label.setHorizontalTextPosition(JLabel.CENTER);
    label.setVerticalTextPosition(JLabel.BOTTOM);
    label.setText("I am here to help you.");
    panel.add(label);
    }
    }

    View Slide

  29. jgs
    00000001
    GUI

    View Slide

  30. jgs
    Let us Practice

    View Slide

  31. jgs
    00000001
    Practice

    View Slide

  32. jgs
    00000001
    Part 1

    View Slide

  33. jgs
    00000001
    Part 2

    View Slide

  34. jgs
    CSE 460 Software Analysis and Design
    Javier Gonzalez-Sanchez
    [email protected]
    Fall 2020
    Disclaimer. These slides can only be used as study material for the class CSE460 at ASU. They cannot be distributed or used for another purpose.

    View Slide