欢迎来到天天文库
浏览记录
ID:43196515
大小:693.50 KB
页数:18页
时间:2019-10-02
《SWING的图形介面元件》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、SWING的圖形介面元件JLabelJLabellabel=newJLabel("關閉");JLabellabel1=newJLabel(newImageIcon("tree.jpg"));JLabel(String,int),JLabel(ImageIcon,int)JLabel.LEFTJLabel.RIGHTJLabel.CENTERJLabel.LEADINGJLabel.TRAILINGJButtonJButtonbutton1=newJButton("切換(Alt_S)");JButto
2、nbutton2=newJButton(newImageIcon("yellow.gif"));button1.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEventevt){//切換標題的文字內容if(flag==0)label.setText("開啟");elselabel.setText("關閉");flag=1-flag;}});JCheckBoxgreenBox=newJCheckBox("綠色
3、(G)");greenBox.setMnemonic(KeyEvent.VK_G);greenBox.setSelected(true);greenBox.addItemListener(this);Ch11_1_2JRadioButtonGroup()add()remove()JRadionButton()setMnemoic()setSelected(boolean)addItemListener(ItemListener)removeItemListener()CH11_1_3JComboBo
4、xString[]items={"程式語言","計算機概論","資料庫系統","網頁設計"};JComboBoxlist=newJComboBox(items);Ch11_1_4JListString[]names={"陳會安","江小魚","小龍女","張三丰"};dlistModel=newDefaultListModel();for(inti=0;i5、(dlistModel);Ch11_1_5JScrollJScrollBar()JScrollBar(int)JScrollBar(int,int,int,int,int)s1=newJScrollBar(JScrollBar.VERTICAL,50,10,0,100);JSliderJSlider()JSlider(int)JSlider(int,int)JSlider(int,int,int)JSlider(int,int,int,int)Ch11_1_6JTextComponentJTextF6、ieldandJPasswordFieldJTextFieldtext=newJTextField(12);JPasswordFieldpassword=newJPasswordField(12);Ch_2_1JTextAreaJTextArea()JTextArea(String)JTextArea(int,int)JTextArea(String,int,int)area=newJTextArea("等待輸入資料...",15,30);JScrollPanescroll=newJScroll7、Pane(area);Ch11_2_2JPopupMenupopup=newJPopupMenu();popup.add(blue=newJMenuItem("藍色"));blue.addActionListener(this);popup.add(yellow=newJMenuItem("黃色"));yellow.addActionListener(this);popup.add(green=newJMenuItem("綠色"));green.addActionListener(this);JPo8、pupMenuaddMouseListener(newMouseAdapter(){publicvoidmousePressed(MouseEventevt){if(evt.isPopupTrigger())//顯示選單popup.show(evt.getComponent(),evt.getX(),evt.getY());}publicvoidmouseReleased(MouseEventevt){if(evt.isPopupTrigger())//顯示選單pop
5、(dlistModel);Ch11_1_5JScrollJScrollBar()JScrollBar(int)JScrollBar(int,int,int,int,int)s1=newJScrollBar(JScrollBar.VERTICAL,50,10,0,100);JSliderJSlider()JSlider(int)JSlider(int,int)JSlider(int,int,int)JSlider(int,int,int,int)Ch11_1_6JTextComponentJTextF
6、ieldandJPasswordFieldJTextFieldtext=newJTextField(12);JPasswordFieldpassword=newJPasswordField(12);Ch_2_1JTextAreaJTextArea()JTextArea(String)JTextArea(int,int)JTextArea(String,int,int)area=newJTextArea("等待輸入資料...",15,30);JScrollPanescroll=newJScroll
7、Pane(area);Ch11_2_2JPopupMenupopup=newJPopupMenu();popup.add(blue=newJMenuItem("藍色"));blue.addActionListener(this);popup.add(yellow=newJMenuItem("黃色"));yellow.addActionListener(this);popup.add(green=newJMenuItem("綠色"));green.addActionListener(this);JPo
8、pupMenuaddMouseListener(newMouseAdapter(){publicvoidmousePressed(MouseEventevt){if(evt.isPopupTrigger())//顯示選單popup.show(evt.getComponent(),evt.getX(),evt.getY());}publicvoidmouseReleased(MouseEventevt){if(evt.isPopupTrigger())//顯示選單pop
此文档下载收益归作者所有