Java Desktop Application - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Java Desktop Application

Description:

????????? File. ????? New Project. ????? Java Desktop Application. ?????????????????????? ... null // Icon (none) , choices // Button text as above. , 'None of ... – PowerPoint PPT presentation

Number of Views:317
Avg rating:3.0/5.0
Slides: 21
Provided by: siam4
Category:

less

Transcript and Presenter's Notes

Title: Java Desktop Application


1
Java Desktop Application 5
  • ???????????? ???????????? jList , jRadioButton
  • ?? NetBean 6.0 swing set
  • ??? ?. ??????? ????????
  • http//www.siam2dev.com

2
??????????????????? ??????
???????????? ????????????????????????????????????
? ? ???????????????????????????? ComboBox
??????????? ??? ComboBox ???? ??
???????????????????????????? ?? ???? OK
??????????????????????? ??????? ??????? ?????
?????? ???????????????????????????????????????????
????? ??? ????????? jList jRadioButton jButtonG
roup jPanel ButtonGroup
3
(No Transcript)
4
????? ?????????????
  • ????????? File
  • ????? New Project
  • ????? Java Desktop Application
  • ?????????????????????? desktop_app5

5
control ???? ???????????????????????
  • jLabel
  • jTextField
  • jButton
  • jList
  • jRadioButton
  • jButtonGroup
  • jPanel
  • jOptionPane

6
???????????????????
jLabel
jTextField
jList
7
??????????????????? (???)
Button
jPanel
jRadioButton
8
??????? jList ???????? jFrame
  • ?????????????????
  • ??????????? Swing ????? Swing Control
  • ??????????????? List
  • ????? Drage mouse ??????? Frame ????????? mouse
  • ??????????? List ?????????? ??? ?.?.
    ????????????????

9
???????????????????? jList1
  • ???????????????????? jList ???
  • - model ??????????????/?????
    ??????????????? jList1
  • - selectedItem ???????????????????????????????
    ????????????????????? model
  • ????????????????? ?????????????????
  • Click ???????? jList1
  • ?????????? Properties ??? ????? model
  • ??????????????????????????????? ?????????????
  • ??????????????????????? ?????????????????????
  • item ???????? ???? add ????????????????

???????? ??????????????????????? ????? ?????????
?????????????????????????????????????
10
???????????????? jPanel
  • jPanel ?????????????????????????? ??????????????
    ????????????????????????????????????????????
    ????????????????????????????? jRadioButton
    ?????????????????????
  • ??????????? Swing ????? Swing Containers
  • ??????????????? Panel
  • ????? Drage mouse ??????? Frame ????????? mouse
  • ??????????? Panel ?????????? ??? ?.?.
    ????????????????

11
????????????????? Border ??? jPanel
  • ???????????????????? Border ???? ??????? jPanel
    ??? ??????????
  • ??????
  • ????????????????? Panel ??????????
  • ?????????? Properties ?????
  • ????? Border ????????? ??????????????
  • ????????????????????????????????????????????
  • ???????? ??????? TitleBorder
  • ??????????????????????????

12
???????????????? jRadioButton
  • ?????????????????
  • ??????????? Swing ????? Swing Control
  • ??????????????? RadioButton
  • ????? Drage mouse ??????? jPanel ????????? mouse
  • ??????????? jRadioButton ?????????? ??? ?.?.
    ????????????????
  • ??????????? ????? jRadioButton ??????? 5
    ???????????

13
???????????????????? RadioButton
  • Text ??????????????????????? RadioButton
  • ButtonGroup ???????????????????? RadioButton

???????????????????????? RadioButton
???????????????????????????? ???? ????
ButtonGroup ??? pallete?????????? ???? ???? ?????
Properties ButtonGroup ??????? ButtonGroup1
14
Code ?????? btnOK
  • ??????????????????????????????? btnOKMouseClicked
    ???????????
  • Click ?????? jButton1
  • ????? Event
  • ????? mouse
  • ????? mouseclick
  • ??????????????????????

15
?????????? btnOK
  • private void btnOKMouseClicked(java.awt.event.Mou
    seEvent evt)
  • // TODO add your handling code here
  • lstModel new DefaultListModel()
  • if(jRadioButton1.isSelected() )
  • int n Integer.parseInt(txtNumber.getText
    ())
  • for(int i 1iltni)
  • if(i 2 0)
  • else
  • lstModel.addElement(i)
  • lst1.setModel(lstModel)
  • else if (jRadioButton2.isSelected() )
  • int n Integer.parseInt(txtNumber.getTe
    xt())
  • for(int i 1iltni)
  • if(i 2 0)
  • lstModel.addElement(i)
  • else

16
Code ?????? btnRemove
  • ???????????????????????????????
    jButton2MouseClicked ???????????
  • Click ?????? jButton2
  • ????? Event
  • ????? mouse
  • ????? mouseclick
  • private void btnRemoveMouseClicked(java.awt.event
    .MouseEvent evt)
  • // TODO add your handling code here
  • if(lst1.getSelectedIndex() ! -1)
  • // ???????? ?????????????
    ????????????????? ?
  • lstModel.remove(lst1.getSelectedIndex(
    ))
  • else
  • // ????????? ????? ???????? ? ??? ???
    ?????????
  • lstModel.clear()

17
Code ?????? btnExit
  • ???????????????????????????????
    jButton3MouseClicked ???????????
  • Click ?????? jButton3
  • ????? Event
  • ????? mouse
  • ????? mouseclick
  • ????????????????? ?????

18
Code ?????? Exit
  • private void btnExitMouseClicked(java.awt.event.M
    ouseEvent evt)
  • // TODO add your handling code here
  • String choices "Yes", "No",
    "Quit"
  • int response jOptionPane1.showOptionDia
    log(
  • null
    // Center in window.
  • , "??????????????????
    ???????????? ?" // Message
  • , "MyTitle"
    // Title in titlebar
  • , jOptionPane1.YES_NO
    _OPTION // Option type
  • , jOptionPane1.PLAIN_
    MESSAGE // messageType
  • , null
    // Icon (none)
  • , choices
    // Button text as above.
  • , "None of your
    business" // Default button's label
  • )
  • switch (response)
  • case 0
  • break
  • case 1
  • break

19
???????????????????? ???????????????? jLabel
  • ?????????????????????????????? Label ?? ? ?????
    method setText() ??? ????????
  • ??????????????? ????? Hello ?? jLabel1
    ???????????????? ??????
  • ???????????????????????????????????????????????
    ?? ????????????????????? ???????????

jLabel1.setText(Hello)
String str Hello jLabel1.setText(str)
20
????????????????????????????
String choices "Yes", "No", "Quit"
int response jOptionPane1.showOptionD
ialog( null
// Center in window.
, "?????????????????????????????? ?"
// Message ,
"MyTitle" // Title in titlebar
, jOptionPane1.YES_NO_OPTI
ON // Option type ,
jOptionPane1.PLAIN_MESSAGE // messageType
, null
// Icon (none) ,
choices // Button text as
above. , "None of
your business" // Default button's label
) switch (response)
case 0 break case
1 break case
2 System.exit(0) // It would be better to
exit loop, but... break
case -1 System.exit(0) // It
would be better to exit loop, but...
default jOptionPane1.showMessageDialog(null,
"Unexpected response ")
???????
Write a Comment
User Comments (0)
About PowerShow.com