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

CSE205 Lecture 09

CSE205 Lecture 09

Object-Oriented Programming and Data Structures
Java Swing
(202109)

B546a9b97d993392e4b22b74b99b91fe?s=128

Javier Gonzalez
PRO

September 19, 2021
Tweet

Transcript

  1. jgs CSE 205 Object-Oriented Programming and Data Structures Lecture 09:

    Java Swing Dr. Javier Gonzalez-Sanchez javiergs@asu.edu javiergs.engineering.asu.edu | javiergs.com PERALTA 230U Office Hours: By appointment
  2. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 2 jgs

    Java API
  3. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 3 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); } }
  4. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 4 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); } }
  5. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 5 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); } }
  6. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 6 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); } }
  7. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 7 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
  8. Javier Gonzalez-Sanchez | CSE205 | Fall 2021 | 8 jgs

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

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

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

    Pseudo Calculator
  12. jgs CSE 205 Object-Oriented Programming and Data Structures Javier Gonzalez-Sanchez,

    Ph.D. javiergs@asu.edu 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.