Windows / Graphical User Interface (GUI) - PowerPoint PPT Presentation

1 / 55
About This Presentation
Title:

Windows / Graphical User Interface (GUI)

Description:

Windows / Graphical User Interface (GUI) JFC / AWT / Swing / Java 2D JFC (Java Foundation Class) AWT ... – PowerPoint PPT presentation

Number of Views:163
Avg rating:3.0/5.0
Slides: 56
Provided by: MarkSu
Category:

less

Transcript and Presenter's Notes

Title: Windows / Graphical User Interface (GUI)


1
???? ??????? ???
  • Windows / Graphical User Interface (GUI)

2
JFC / AWT / Swing / Java 2D
  • JFC (Java Foundation Class)
  • ?AWT???,??????GUI??????AWT, Swing, Pluggable Look
    Feel, Accessibility, Java 2D?Grag and Drop????
  • AWT (Abstract Window Toolkit)
  • Java?????????????
  • ????? (Java 2 ??Swing??)
  • ???? (Java 2 ??Java 2D??)

3
JFC / AWT / Swing / Java 2D
  • Swing
  • ???AWT???????,???????????,??????????????????,???Sw
    ing?????????
  • Java 2D
  • ?Graphics 2D??????????????????????????,??????(????
    ??????)

4
AWT??????
  • Package java.awt
  • AWT???GUI??????Component class
  • ???????GUI?????????Container???????Component??,???
    Container?????????
  • Window class
  • Panel class
  • Java?????????Frame class???,Frame class???window
    class,????????????(??????????)?????(title)???

5
?CtrlC??????
6
AWT GUI??
  • Component????

???? ??
Button ??
Canvas ??
Checkbox ????
Choice ?????
Container ???????????
Label ??
List ????
Scrollbar ??
TextComponent ????
7
(No Transcript)
8
(No Transcript)
9
AWT ????????
  • ????????????
  • ????Panel?Label???,?????????
  • ???????????????????

10
Swing??????
  • Swing????????Java??????AWT??(AWT??????Java?????)
  • ???AWT???????,Swing?????J???(Jbutton, Jlabel, )
  • ???Swing?????????javax.swing?????

11
(No Transcript)
12
Swing?GUI??
JButton ???? JProgressBar ??????
JMenuItem ???? JRootPane ??????
JCheckBox ???? JScrollBar ?????
JRadioButton ????? JScrollPane ??????
JColorChooser ?????? JSlider ?????
JComboBox ?????? JSpinner ???????
JFileChooser ?????? JSplitPane ???????
JInternalFrame ????? JTabbedPane ??????
JLabel ???? JTable ????
JLayeredPane ?????? JTableHeader ????????
JDesktopPane ?????? JTextArea ??????
JList ???? JTextField ??????
JMenuBar ????? JToolBar ?????
JOptionPane ????? JToolTip ????
JPanel ???? JTree ????????
JPopupMenu ???????? JViewport ????
13
Swing ??????GUI??
  • Swing????????AWT??
  • AWT????add()?????????Frame?
  • Swing?????JFrame?????????(contentPane)
    ,???????????????

JFrame frame1new JFrame(??title) Container
cframe1.getContentPane() c.add(new
JButton(????),2)
14
(No Transcript)
15
???????
  • Java???????????
  • FlowLayout
  • ???????
  • BorderLayout
  • ???????
  • GridLayout
  • ???????
  • CardLayout
  • ???????
  • GridBagLayout
  • ?????????
  • BoxLayout
  • ???????

16
FlowLayout
  • ??????????????
  • ????
  • Container cframe1.getContentPane()
  • FlowLayout f1new FlowLayout()
  • c.setLayout(f1)
  • ??????

FlowLayout f1new FlowLayout(1)
???? ?? ?? ???? ?? ??
FlowLayout.CENTER ???? 1 FlowLayout.RIGHT ???? 2
FlowLayout.LEADING ????? 3 FlowLayout.TRAILING ????? 4
FlowLayout.LEFT ???? 0
17
(No Transcript)
18
BorderLayout
  • ??????????????????
  • ????
  • Container cframe1.getContentPane()
  • BorderLayout b1new BorderLayout(15,10)
  • c.setLayout(b1)
  • ???? ????

15???? 10????
b1.setHgap(15) b1.setVgap(10)
int gxb1.getHgap() int gyb1.getVgap()
???? ?? ???? ???? ?? ????
BorderLayout.CENTER ?? Center BorderLayout.SOUTH ?? South
BorderLayout.EAST ?? East BorderLayout.WEST ?? West
BorderLayout.NORTH ?? North
19
(No Transcript)
20
GridLayout
  • ?????????
  • ????
  • Container cframe1.getContentPane()
  • GridLayout g1new GridLayout(2,3)
  • c.setLayout(g1)
  • ????
  • Container cframe1.getContentPane()
  • GridLayout g1new GridLayout(2,3,10,15)
  • c.setLayout(g1)

2?????? 3??????
2?????? 3?????? 10???? 15????
21
(No Transcript)
22
CardLayout
  • ??????????,????????????????
  • ????
  • Container cframe1.getContentPane()
  • CardLayout c1new CardLayout(15,10)
  • c.setLayout(c1)
  • c.add(new JButton(????),????)
  • ????????

15???? 10????
?? ?? ?? ?? ?? ??
first() ????? c1.first(c) last() ?????? c1.last(c)
next() ????? c1.next(c) show() ???????? c1.show(c, card1)
previous() ????? c1.previous(c) show() ???????? c1.show(c, card1)
23
(No Transcript)
24
GridBagLayout
  • ???????????
  • ??????????????GridBagConstraints??
  • ????
  • Container cframe1.getContentPane()
  • GridBagLayout gnew GridBagLayout()
  • c.setLayout(g)
  • GridBagConstraints g1new GridBagConstratints()
  • g1.fillGridBagConstraints.BOTH//???????,????
  • g1.insetsnew Insets(6,6,6,6)//????????????
  • g1.gridx1//???????????
  • g1.gridy1//???????????
  • g1.gridwidth3//??????????
  • g1.gridheigth1//??????????
  • g1.weightx1.0//???????
  • g1.weighty1.0//???????
  • c.add(new JButton(????),g1)

25
(No Transcript)
26
BoxLayout
  • ???????????,?????????????????

27
????????
  • setLocation(x,y)
  • ????
  • Container cframe1.getContentPane()
  • c.setLayout(null)
  • JButton bt1new JButton(???)
  • bt1.setSize(80,40)//??????
  • bt1.setLocation(150,150)//????????
  • c.add(bt1)

28
(No Transcript)
29
????????
  • ????????
  • ??(Property)
  • ???????????????
  • ?????????
  • ??(Event)
  • ?????????????????
  • ??????????????

30
????????(?)
  • ??????
  • ??????(???????????)
  • setToolTipText(??????)
  • ????
  • setFont(new Font(????,Font.BOLD,16))
  • ??????
  • ??(BOLD) ???(ITALIC)
  • ????
  • ?????
  • setForeground(Color.blue)
  • ????????
  • ??????
  • setHorizontalAlignment(SwingConstants.LEFT)
  • ??????
  • setVerticalAlignment(SwingConstants.TOP)

31
????????(?)
  • ??????
  • ?????
  • setBackground(new Color(255,255,128))
  • ??????
  • setSize(?,?)
  • ??????
  • setLocation(X???,Y???)
  • ??????
  • setBorderPainted(true)

32
????????(?)
  • ??????
  • ??????
  • setEnabled(true)
  • ??????
  • setFocusable(false)
  • ??????
  • setVisible(true)

33
???????
  • JLabel
  • ????,???????????
  • JTextField
  • ??????,??????????
  • JPasswordField
  • ??????,??????????
  • JTextArea
  • ??????,??????????

34
(No Transcript)
35
???????
  • JCheckBox
  • ????,???????????
  • JRadioButton
  • ????,????????????
  • JComboBox
  • ??????,????????????
  • JList
  • ????,???????????

36
(No Transcript)
37
(No Transcript)
38
????
  • JSlider???
  • ?????????
  • ????????

???? ??
JSlider() ??????,???0-100,???50
JSlider(BoundedRangeModel brm) ??BoundedRangeModel???????????
JSlider(int orientation) ????(SwingConstants.HORIZONTAL)???(Swing.Constants.VERTICAL)???,???0-100,???50
JSlider(int min, int max) ???????,???minmax
JSlider(int min, int max, int value) ???????,???minmax,???value
JSlider(int orientation, int min, int max, int value) ??????????,???minmax,???value
39
????(?)
  • ?JSlider???????

??(Method) ?? ??(Method) ??
addChangeListener(ChangeListener I) ?ChangeListener??I????????? setMajorTickSpacing(int n) ??????????n
getMajorTickSpacing() ?????????? setMaximum(int maximum) ??????maximum
getMaximum() ????? setMinimum(int minimum) ??????minimum
getMinimum() ????? setPaintTicks(boolean b) ????????
getPaintTrack() ???????? setValue(int n) ?????????n
getValue() ????????
40
(No Transcript)
41
????(?)
  • JScrollBar???
  • ???????????
  • ????????

???? ??
JScrollBar() ???????,???0100,???10,?????????10
JScrollBar(int orientation) ??????????,???0100,???10,?????????10
JScrollBar(int orientation, int value, int extent, int min, int max) ??????????,???minmax,???value,?????????extent
42
????(?)
  • ?JScrollBar???????

??(Method) ?? ??(Method) ??
addAdjustmentListener(AdjustmentListener I) ???????I????????? getValue() ???????
getBlockIncrement() ????????? removeAdjustmentListener(AdjustmentListener I) ???????I??????????
getBlockIncrement(int direction) ????direction????????? setBlockIncrement(int n) ??????????n
getMaximum() ????? setEnabled(boolean x) ???????x
getMaximumSize() ?????? setMaximum(int max) ??????max
getMinimum() ????? setMinimum(int min) ??????min
getMinimumSize ?????? setOrientation(int orient) ????(VERTICAL / HORIZONTAL)
getOrientation() ????(VERTICAL / HORIZONTAL) setUnitIncrement(int u) ??????????u
getUnitIncrement() ????????? setValue(int n) ????????n
getUnitIncrement(int direction) ??????????? setValues(int newvalue, int newextent,int newmin, int newmax) ?????
43
(No Transcript)
44
????
  • JOptionPane????????
  • showInputDialog()
  • ????
  • showMessageDialog()
  • ????
  • showConfirmDialog()
  • ????
  • showOptionDialog()
  • ????

45
(No Transcript)
46
(No Transcript)
47
????(?)
  • ????(messageType)
  • JOptionPane.ERROR_MESSAGE
  • JOptionPane.INFORMATION_MESSAGE
  • JOptionPane.WARNING_MESSAGE
  • JOptionPane.QUESTION_MESSAGE
  • JOptionPane.PLAIN_MESSAGE

48
???????
  • ?????????
  • JMenuBar
  • ???
  • JMenu
  • ??
  • JMenuItem
  • ????

???(JMenu)????????? ??(JMenuItem)?,?????? ???(JRad
ioButtonMenuItem), ?????(JCheckBoxMenuItem)
49
(No Transcript)
50
(No Transcript)
51
????
  • ?????????
  • JLabel
  • JButton
  • ??????
  • ImageIcon icon1new ImageIcon(pic.jpg)
  • ??????/??
  • ??
  • JLabel lb1new JLabel(icon1)
  • JButton bt1new JButton(icon1)
  • ??
  • lb1.setIcon(icon1)
  • bt1.setIcon(icon1)

52
(No Transcript)
53
???
  • JToolBar
  • ???setFloatable()????????????

54
????
  • JLayeredPane

55
??????
  • JTabbedPane
  • ???JPanel????????????
Write a Comment
User Comments (0)
About PowerShow.com