Slide 1

Slide 1 text

Dr. Javier Gonzalez-Sanchez [email protected] www.javiergs.info o ffi ce: 14 -227 CSC 305 Individual Software Design and Development Lecture 07. Java Swing

Slide 2

Slide 2 text

Previously

Slide 3

Slide 3 text

Relationships 3

Slide 4

Slide 4 text

Problem public class B implements E { public B() { C c1 = new C(); } public void method() { B b = new B(); b.sleep(); } } public class Y extends B { A [] a = new A[5]; } public class A extends B { C c1, c2; public A() { c1 = new C(); } public void method(D d) { d.working(); } } public class X { private String s; public void m() { B var = new A(); double x – Math.sqrt(5); } }

Slide 5

Slide 5 text

Let’s Work 5

Slide 6

Slide 6 text

Java Swing

Slide 7

Slide 7 text

JFrame 7

Slide 8

Slide 8 text

JFrame 8

Slide 9

Slide 9 text

JMenuBar, JMenu, JMenuItem 9

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

JPanel 11

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

JPanel 14

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

Test Yourselves 16

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

Test Yourselves 18

Slide 19

Slide 19 text

import javax.swing.*; public class Example extends JFrame{ public Example() { super("Hello World Swing"); GridLayout layout = new GridLayout(3,2); 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); } }

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

Listeners

Slide 25

Slide 25 text

Listeners 25 • ActionListener • actionPerformance(ActionEvent e) {} • addActionListener (this);

Slide 26

Slide 26 text

Questions 26

Slide 27

Slide 27 text

Lab.

Slide 28

Slide 28 text

Let’s Work 28 Class Diagram for the kappa version of my Paint App https://github.com/CSC3100/App-Paint/tree/main/ src/main/java/javiergs/paint/Kappa

Slide 29

Slide 29 text

CSC 305 Individual Software Design and Development Javier Gonzalez-Sanchez, Ph.D. [email protected] Summer 2024 Copyright. These slides can only be used as study material for the class CSC305 at Cal Poly. They cannot be distributed or used for another purpose.