JAVA????? JAVA?Swing????? - PowerPoint PPT Presentation

About This Presentation
Title:

JAVA????? JAVA?Swing?????

Description:

JAVA JAVA Swing Swing 1 Swing GUI (Graphical User Interface) javax.swing 2 – PowerPoint PPT presentation

Number of Views:117
Avg rating:3.0/5.0
Slides: 29
Provided by: watanabe
Category:
Tags: java | slides | swing

less

Transcript and Presenter's Notes

Title: JAVA????? JAVA?Swing?????


1
JAVA?????JAVA?Swing?????
2
Swing??
  • 1.Swing ?? GUI (Graphical User Interface) ??????
  • ??????? javax.swing
  • 2. AWT (Abstract Java Toolkit) ???????? GUI ??
  • ???
  • ????????????
  • AWT ??????????(swing ????????
  • awt ??????????????????)
  • 3.Swing????????
  • AWT ?? ? GUI ??????????????????
  • ???????????????????????????????????????(
    heavyweight ?????)
  • Swing ?????? Java ??????????????
  • ???????????????????( lightweight ?
  • ????)

3
Swing?????????????
  • 1.Swing ????
  • ???????????(????)
  • ?? Swing ???????????????????
  • Frame JFrame???
  • Dialog JDialog???
  • Applet JApplet???
  • ???????(????)
  • ??Swing???????????????????
  • Panel Jpanel???
  • Scroll pane JScrollPane??? ??
  • ????????
  • ????????
  • JButton, JComboBox, JTextField, JTextArea,
    JLabel, JFileChooser, JTable ??

4
Swing????????????
  • 1.????? java.awt., javax.swing. ??????
  • 2.??????????????????????????
  • 3.??????????
  • 3.1 ??????????????????
  • 3.2 ??????????????
  • 3.3 ???????????????
  • 4.??????????
  • 4.1 ?????????????????????
  • 4.2 ??????????
  • 5.????????????????????

5
Swing????????????
  • 6.?????????
  • 6.1 ???????????????????????
  • 6.2 ???????????????????????
  • 6.3 ??????????????????
  • 7.??????????????
  • 7.1 ??????????????
  • 7.2 ????????????
  • 7.3 ????????????????
  • 8.?????????????????????
  • 9.??????????????
  • 10.?????????????????

6
Swing????????????
  • 11.??????(???????????????????)
  • ??????????????????????????
  • ??
  • ???? Swing ?????????????????
  • ??????????????????????????
  • ???
  • ????
  • ???????????????????????????
    ???????????????????
  • ?????????????????????????

7
????
  • import java.awt.
  • import javax.swing.
  • public class HelloSwing extends JFrame
  • // ????????????????
  • private JFrame frame
  • private JLabel label
  • // ????????(??????????????)
  • HelloSwing(String title)
  • // JFrame????????
  • frame new JFrame(title)
  • // JLabel????????
  • label new JLabel("Hello Swing!")

8
????
  • // JFrame????????????
  • Container con frame.getContentPane()
  • // ?????????JLabel???
  • // (????????????????????)
  • con.add(label)
  • // ???????????
  • frame.setDefaultCloseOperation(
  • JFrame.EXIT_ON_CLOSE)
  • frame.pack()
  • frame.setVisible(true)

9
????
10
????(??)
  • 1.???????????
  • import java.awt.
  • import javax.swing.
  • 2.??????????????????????????
  • public class HelloSwing extends JFrame
  • // ????????????????
  • private JFrame frame
  • private JLabel label
  • // ????????(??????????????)
  • HelloSwing(String title)

11
????(??)
  • 3.??????????
  • // JFrame????????
  • frame new JFrame(title)
  • // JLabel????????
  • label new JLabel("Hello World!")
  • 4.??6.??????????
  • // JFrame????????????
  • Container con frame.getContentPane()
  • // ?????????JLabel???
  • // (????????????????????)
  • con.add(label)

12
????(??)
  • 10.?????????????????
  • // ???????????
  • frame.setDefaultCloseOperation(
  • JFrame.EXIT_ON_CLOSE)
  • frame.pack()
  • frame.setVisible(true)
  • ???
  • ????????(???????????)???(???????????)
  • ???????????????
  • ??????????
  • ???

13
???????????
  • AWT??????????????????????????
  • ????????????????????
  • Swing??????????????????????????
  • ?????????????
  • ??????????????????AWT?????????
  • ??
  • (Swing????????????????????????)
  • ???????AWT?????FlowLayout????

14
??????????(??)
?? ??
FlowLayout ???????????
BorderLayout ?????????????5????
CardLayout ??????????????????????
GirdLayout ??????
GirdBagLayout ????????????????
15
FlowLayout (??)
  • ?????????????????
  • ?? FlowLayout(int alignment, int hgaps, int
    vgaps)
  • alignment ???????????? ????????
  • FlowLayout.CENTER ???????
  • FlowLayout.RIGHT ??????
  • FlowLayout.LEFT ??????
  • FlowLayout.TRAILING ???????
  • FlowLayout.LEADING ???????
  • hgaps ???????????????
  • vgaps ???????????????

16
FlowLayout (??)
  • ????????
  • con.setLayout(new FlowLayout())
  • ?
  • con.setLayout(new FlowLayout(FlowLayout.CENTER,
    5, 5)
  • ??????

17
BoaderLayout (??)
  • ?????????????????????????
  • ?? BoaderLayout(int hgaps, int vgaps)
  • hgaps???????
  • vgaps???????
  • ??????
  • con.setLayout(new BoaderLayout(5, 5))
  • Button bt1 new Button(button-North)
  • con.add(bt1, BoaderLayout.NORTH )

North
West
East
Center
South
18
BoaderLayout (??)
????? ???
? North ????BorderLayout.NORTH
?? Center????BorderLayout.CENTER
? South ????BorderLayout.SOUTH
? East ????BorderLayout.EAST
? West ????BorderLayout.WEST
19
GridLayout (??)
  • ???????????????????????
  • ??
  • GridLayout(int rows, int colums int haps, int
    vgaps)
  • rows ???
  • colums ???
  • haps ???????
  • vgaps ???????
  • ????????add?????????????????
  • ??????gt?????????????????
  • ??????lt????????????????????

20
??????????????
  • import java.awt.
  • import javax.swing.
  • public class HelloSwing extends JFrame
  • // ????????????????
  • private JFrame frame
  • private JLabel label
  • private JButton button
  • // ????????(??????????????)
  • HelloSwing(String title)
  • // JFrame????????
  • frame new JFrame(title)
  • // JLabel????????
  • label new JLabel("Hello Swing!")

21
??????????????
  • // JButton????????
  • button new JButton("OK")
  • // JFrame????????????
  • Container con frame.getContentPane()
  • // ?????????JLabel,JButton???
  • con.setLayout(new FlowLayout())
  • con.add(label)
  • con.add(button)
  • // ???????????
  • frame.setDefaultCloseOperation(
  • JFrame.EXIT_ON_CLOSE)
  • frame.pack()
  • frame.setVisible(true)

22
????
23
??????
  • ?????????????????????????????
  • ?????????????????????????????
  • ?????????????????????????????
  • ?????????????????????????
  • ??????????????????????????
  • ????????
  • JPanel ??????????????????
  • JScrollPane ?????????????????????
  • ?????

24
?????????
  • import java.awt.
  • import javax.swing.
  • public class HelloSwing extends JFrame
  • // ????????????????
  • private JFrame frame
  • private JPanel panel
  • private JScrollPane scroll
  • private JLabel label
  • private JButton button
  • private JTextArea textArea
  • // ????????(??????????????)
  • HelloSwing(String title)
  • // JFrame????????
  • frame new JFrame(title)

25
?????????
  • // JTextArea????????
  • textArea new JTextArea(
  • "???????????", 10, 30)
  • // JScrollPane ????????
  • scroll new JScrollPane(textArea)
  • scroll.setVerticalScrollBarPolicy(
  • JScrollPane.VERTICAL_SCROLLBAR_ALWAYS)
  • scroll.setPreferredSize(
  • new Dimension(500, 250))
  • // JPanel????????
  • panel new JPanel()
  • // JLabel????????
  • label new JLabel("Hello Swing!")

26
?????????
  • // JButton????????
  • button new JButton("OK")
  • // ??????????
  • panel.setLayout(new FlowLayout())
  • panel.add(label)
  • panel.add(button)
  • // JFrame????????????
  • Container con frame.getContentPane()
  • // ?????????JPanel, JScrollPane???
  • con.setLayout(new BorderLayout())
  • con.add(panel, BorderLayout.NORTH)
  • con.add(scroll, BorderLayout.CENTER)

27
?????????
  • // ???????????
  • frame.setDefaultCloseOperation(
  • JFrame.EXIT_ON_CLOSE)
  • frame.pack()
  • frame.setVisible(true)

28
????
Write a Comment
User Comments (0)
About PowerShow.com