资源描述:
《图像界面组件》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、第15讲.图像界面组件常用用户界面组件JButton按钮jbtJCheckBox复选框jchkJRadioButton单选框jrbJLabel标签jlblJTextField文本域jtfJTextArea文本区域jtaJComboBox组合框jcboJList列表jlstGUIClassHierarchy(Swing)GUI类的继承关系常用用户界面组件Java事件对象的层次结构用户行为、源对象和事件对应关系SourceEventTypeUserActionObjectGeneratedClickabutton点击按钮JButtonActio
2、nEventClickacheckbox点击复选框JCheckBoxItemEvent,ActionEventClickaradiobutton单击单选框JRadioButtonItemEvent,ActionEventPressreturnonatextfield文本回车JTextFieldActionEventSelectanewitem选一个新项JComboBoxItemEvent,ActionEventSelectalistnewitem选多项JListJSelectionListEventWindowopened,closed,etc
3、.WindowWindowEventMousepressed,released,etc.ComponentMouseEventKeyreleased,pressed,etc.ComponentKeyEventAbstractButton1JButtonJButtonConstructors构造方法ThefollowingareJButtonconstructors:JButton()JButton(Stringtext)JButton(Stringtext,Iconicon)JButton(Iconicon)JButtonProperties常
4、用属性texticonmnemonichorizontalAlignmentverticalAlignmenthorizontalTextPositionverticalTextPositionDefaultIcons,PressedIcon,andRolloverIcon默认图标、按下图标和翻转图标Aregularbuttonhasadefaulticon,pressedicon,androllovericon.Normally,youusethedefaulticon.Allothericonsareforspecialeffects.Ap
5、ressediconisdisplayedwhenabuttonispressedandarollovericonisdisplayedwhenthemouseisoverthebuttonbutnotpressed.(A)Defaulticon(B)Pressedicon(C)RollovericonDemoTestButtonIcons.javaimportjavax.swing.*;publicclassTestButtonIconsextendsJFrame{publicstaticvoidmain(String[]args){//Cr
6、eateaframeandsetitspropertiesJFrameframe=newTestButtonIcons();frame.setTitle("ButtonIcons");frame.setSize(165,80);frame.setLocationRelativeTo(null);//Centertheframeframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setVisible(true);}publicTestButtonIcons(){ImageIconu
7、sIcon=newImageIcon("image/usIcon.gif");ImageIconcaIcon=newImageIcon("image/caIcon.gif");ImageIconukIcon=newImageIcon("image/ukIcon.gif");JButtonjbt=newJButton("Clickit",usIcon);jbt.setPressedIcon(caIcon);jbt.setRolloverIcon(ukIcon);add(jbt);}}HorizontalAlignments水平对齐Horizont
8、alalignmentspecifieshowtheiconandtextareplacedhorizontallyonabutton.Youcans