Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSE205 Lecture 11

CSE205 Lecture 11

Object-Oriented Programming and Data Structures
Java Swing II
(202202)

Javier Gonzalez-Sanchez
PRO

September 21, 2021
Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. jgs
    CSE 205
    Object-Oriented Programming and
    Data Structures
    Lecture 11: Java Swing II
    Dr. Javier Gonzalez-Sanchez
    [email protected]
    javiergs.engineering.asu.edu | javiergs.com
    PERALTA 230U
    Office Hours: By appointment

    View Slide

  2. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 2
    jgs
    Quiz 04
    § All about Inheritance and related topics
    30 minutes

    View Slide

  3. jgs
    Previously …

    View Slide

  4. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 4
    jgs
    Java API

    View Slide

  5. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 5
    jgs
    A Frame
    import javax.swing.*;
    public class Example extends JFrame{
    public Example() {
    super("Hello World Swing");
    }
    public static void main(String[] args) {
    Example frame = new Example();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(500,500);
    frame.setVisible(true); }
    }

    View Slide

  6. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 6
    jgs
    Widgets
    import javax.swing.*;
    public class Example extends JFrame{
    public Example() {
    super("Hello World Swing");
    JLabel label = new JLabel("Hello World");
    add(label);
    }
    public static void main(String[] args) {
    Example frame = new Example();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(500,500);
    frame.setVisible(true); }
    }

    View Slide

  7. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 7
    jgs
    Widgets
    import javax.swing.*;
    public class Example extends JFrame{
    public Example() {
    super("Hello World Swing");
    FlowLayout layout = new FlowLayout();
    setLayout(layout);
    JLabel label = new JLabel("Hello World");
    add(label);
    JButton button = new JButton("Click Me");
    add(button);
    JTextField text = new JTextField("Text", 10);
    add(text);
    JCheckBox check = new JCheckBox("Option");
    add(check);
    }
    public static void main(String[] args) {
    Example frame = new Example();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(500,500);
    frame.setVisible(true); }
    }

    View Slide

  8. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 8
    jgs
    Layouts
    import javax.swing.*;
    public class Example extends JFrame{
    public Example() {
    super("Hello World Swing");
    GridLayout layout = new GridLayout(3,3);
    setLayout(layout);
    JLabel label = new JLabel("Hello World");
    add(label);
    JButton button = new JButton("Click Me");
    add(button);
    JTextField text = new JTextField("Text", 10);
    add(text);
    JCheckBox check = new JCheckBox("Option");
    add(check);
    }
    public static void main(String[] args) {
    Example frame = new Example();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(500,500);
    frame.setVisible(true); }
    }

    View Slide

  9. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 9
    jgs
    import javax.swing.*;
    public class Example extends JFrame{
    public Example() {
    super("Hello World Swing");
    BorderLayout layout = new BorderLayout();
    setLayout(layout);
    JLabel label = new JLabel("Hello World");
    add(label, BorderLayout.CENTER);
    JButton button = new JButton("Click Me");
    add(button , BorderLayout.SOUTH);
    JTextField text = new JTextField("Text", 10);
    add(text , BorderLayout.NORTH);
    JCheckBox check = new JCheckBox("Option");
    add(check , BorderLayout.EAST);
    }
    public static void main(String[] args) {
    Example frame = new Example();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(500,500);
    frame.setVisible(true); }
    }
    Layouts

    View Slide

  10. jgs
    JPanel

    View Slide

  11. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 11
    jgs
    JPanel

    View Slide

  12. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 12
    jgs
    Pseudo Calculator

    View Slide

  13. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 13
    jgs
    Extending JPanel

    View Slide

  14. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 14
    jgs
    Extending JPanel

    View Slide

  15. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 15
    jgs
    Questions

    View Slide

  16. jgs
    CSE 205 Object-Oriented Programming and Data Structures
    Javier Gonzalez-Sanchez, Ph.D.
    [email protected]
    Fall 2021
    Copyright. These slides can only be used as study material for the class CSE205 at Arizona State University.
    They cannot be distributed or used for another purpose.

    View Slide