CS 112 - Fall 2012, Lab 09 Haohan Zhu. Boston University Slideshow Title Goes Here CS 112 - Fall...

11
CS 112 - Fall 2012, Lab 09 Haohan Zhu

Transcript of CS 112 - Fall 2012, Lab 09 Haohan Zhu. Boston University Slideshow Title Goes Here CS 112 - Fall...

Page 1: CS 112 - Fall 2012, Lab 09 Haohan Zhu. Boston University Slideshow Title Goes Here CS 112 - Fall 2012, Lab 09 2 11/20/2015 GUI - Graphical User Interface.

CS 112 - Fall 2012, Lab 09

Haohan Zhu

Page 2: CS 112 - Fall 2012, Lab 09 Haohan Zhu. Boston University Slideshow Title Goes Here CS 112 - Fall 2012, Lab 09 2 11/20/2015 GUI - Graphical User Interface.

Boston University Slideshow Title Goes Here

CS 112 - Fall 2012, Lab 09

2

04/20/23

GUI - Graphical User Interface

JFC - Java Foundation Classes

An API for providing a graphical user interface (GUI) for Java programs.

Include AWT, Swing and Java 2D.

Page 3: CS 112 - Fall 2012, Lab 09 Haohan Zhu. Boston University Slideshow Title Goes Here CS 112 - Fall 2012, Lab 09 2 11/20/2015 GUI - Graphical User Interface.

Boston University Slideshow Title Goes Here

CS 112 - Fall 2012, Lab 09

3

04/20/23

GUI widget toolkit

Swing Primary Java GUI widget toolkit

AWT Original platform-independent windowing, graphics,

and user-interface widget toolkit.

SWT

Page 4: CS 112 - Fall 2012, Lab 09 Haohan Zhu. Boston University Slideshow Title Goes Here CS 112 - Fall 2012, Lab 09 2 11/20/2015 GUI - Graphical User Interface.

Boston University Slideshow Title Goes Here

CS 112 - Fall 2012, Lab 09

4

04/20/23

Swing

Top-Level Containers JFrame, JDialog, and Japplet

Page 5: CS 112 - Fall 2012, Lab 09 Haohan Zhu. Boston University Slideshow Title Goes Here CS 112 - Fall 2012, Lab 09 2 11/20/2015 GUI - Graphical User Interface.

Boston University Slideshow Title Goes Here

CS 112 - Fall 2012, Lab 09

5

04/20/23

Swing

General-Purpose Containers JPanel, JScrollPane, JSplitPane, and so on

Special-Purpose Containers JInternalFrame, JLayeredPane and Root pane

Page 6: CS 112 - Fall 2012, Lab 09 Haohan Zhu. Boston University Slideshow Title Goes Here CS 112 - Fall 2012, Lab 09 2 11/20/2015 GUI - Graphical User Interface.

Boston University Slideshow Title Goes Here

CS 112 - Fall 2012, Lab 09

6

04/20/23

JPanel

JPanel() Creates a new JPanel with a double buffer and a flow layout.

JPanel(LayoutManager layout) Create a new buffered JPanel with the specified layout manager

setLayout(LayoutManager layout)

Page 7: CS 112 - Fall 2012, Lab 09 Haohan Zhu. Boston University Slideshow Title Goes Here CS 112 - Fall 2012, Lab 09 2 11/20/2015 GUI - Graphical User Interface.

Boston University Slideshow Title Goes Here

CS 112 - Fall 2012, Lab 09

7

04/20/23

LayoutManage

Interface

FlowLayout BorderLayout GridLayout …

Page 8: CS 112 - Fall 2012, Lab 09 Haohan Zhu. Boston University Slideshow Title Goes Here CS 112 - Fall 2012, Lab 09 2 11/20/2015 GUI - Graphical User Interface.

Boston University Slideshow Title Goes Here

CS 112 - Fall 2012, Lab 09

8

04/20/23

Jcomponent

All Swing components whose names begin with "J" descend from the JComponent class

JButton JCheckBox JComboBox JRadioButton JTextField Jtable …

Page 9: CS 112 - Fall 2012, Lab 09 Haohan Zhu. Boston University Slideshow Title Goes Here CS 112 - Fall 2012, Lab 09 2 11/20/2015 GUI - Graphical User Interface.

Boston University Slideshow Title Goes Here

CS 112 - Fall 2012, Lab 09

9

04/20/23

Jbutton

ActionListener Interface http://

docs.oracle.com/javase/7/docs/api/java/awt/event/ActionListener.html

actionPerformed(ActionEvent e)

ActionEvent Class Click a button, create an event

Page 10: CS 112 - Fall 2012, Lab 09 Haohan Zhu. Boston University Slideshow Title Goes Here CS 112 - Fall 2012, Lab 09 2 11/20/2015 GUI - Graphical User Interface.

Boston University Slideshow Title Goes Here

CS 112 - Fall 2012, Lab 09

10

04/20/23

JOptionPane

JOptionPane.showMessageDialog();

Page 11: CS 112 - Fall 2012, Lab 09 Haohan Zhu. Boston University Slideshow Title Goes Here CS 112 - Fall 2012, Lab 09 2 11/20/2015 GUI - Graphical User Interface.

Boston University Slideshow Title Goes Here

CS 112 - Fall 2012, Lab 09

11

04/20/23

Practice

Finish the code

Learn how to write a GUI