知識
不管是網(wǎng)站,軟件還是小程序,都要直接或間接能為您產(chǎn)生價值,我們在追求其視覺表現(xiàn)的同時,更側(cè)重于功能的便捷,營銷的便利,運營的高效,讓網(wǎng)站成為營銷工具,讓軟件能切實提升企業(yè)內(nèi)部管理水平和效率。優(yōu)秀的程序為后期升級提供便捷的支持!
學(xué)習(xí)筆記二十二:GUI(三)
發(fā)表時間:2020-10-19
發(fā)布人:葵宇科技
瀏覽次數(shù):48
形成天才的決定身分應(yīng)當曲直奮?!?
本講內(nèi)容:常用組件
一、面板組件JPanel(非頂層組件)
一個界面只可以有一個JFrame窗體組件,但可以有多個JPanel面板組件,而JPanel上也可應(yīng)用FlowLayout,BorderLayout,GridLayout等各類構(gòu)造治理器,如許可以組合應(yīng)用達到較為復(fù)雜的構(gòu)造效不雅。
JPanel是JComponent的子類,屬于容器類組件,可以參加其余組件,默認是流式構(gòu)造。
public class Text extends JFrame{ //定義組件 JPanel jp1,jp2; JButton jb1,jb2,jb3,jb4,jb5; public static void main(String[] args) { Text t=new Text(); } public Text() { //創(chuàng)建組件 jp1=new JPanel();//JPanel構(gòu)造默認是FlowLayout jp2=new JPanel(); jb1=new JButton("雪梅"); jb2=new JButton("志豪"); jb3=new JButton("健美"); jb4=new JButton("志華"); jb5=new JButton("曉靜"); //增長組件 先將JPanel上的組件添加完畢,再添加JFrame的組件 jp1.add(jb1); jp1.add(jb2); jp2.add(jb3); jp2.add(jb4); this.add(jp1,BorderLayout.SOUTH); this.add(jp2,BorderLayout.NORTH); this.add(jb5); //設(shè)置窗體屬性 this.setTitle("構(gòu)造Layout—小勁"); this.setLocation(300, 300); this.setSize(400,300); this.setResizable(false); this.setVisible(true); this.setDefaultClo搜刮引擎優(yōu)化peration(JFrame.EXIT_ON_CLOSE); } }
[img]http://img.blog.csdn.net/20150105230050765?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGlndW9qaW4xMjMw/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
二、文本框(JTextField)、暗碼框(JPasswordField)、標簽(JLable)、按鈕(JButton)
import java.awt.*; import javax.swing.*; public class Text extends JFrame{ //定義組件 JPanel jp1,jp2,jp3; JButton jb1,jb2; JLabel jlb1,jlb2; JTextField wbk1; JPasswordField pwd1; public static void main(String[] args) { Text t=new Text(); } public Text() { //創(chuàng)建組件 jp1=new JPanel(); jlb1=new JLabel("用戶名"); wbk1=new JTextField(10); jp1.add(jlb1); jp1.add(wbk1); jp2=new JPanel(); jlb2=new JLabel("密 碼"); pwd1=new JPasswordField(10); jp2.add(jlb2); jp2.add(pwd1); jp3=new JPanel(); jb1=new JButton("登錄"); jb2=new JButton("撤消"); jp3.add(jb1); jp3.add(jb2); this.setLayout(new GridLayout(3,1)); //增長組件 this.add(jp1); this.add(jp2); this.add(jp3); //設(shè)置窗體屬性 this.setTitle("構(gòu)造Layout—小勁"); this.setLocation(300, 300); this.setSize(400,300); this.setResizable(false); this.setVisible(true); this.setDefaultClo搜刮引擎優(yōu)化peration(JFrame.EXIT_ON_CLOSE); } }
[img]http://img.blog.csdn.net/20150105231537167?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGlndW9qaW4xMjMw/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
三、復(fù)選框組件(JCheckBox)、單選框組件(JRadioButton)
留意:同一組單選按鈕必須先創(chuàng)建ButtonGroup,然后把單選框組件放入到ButtonGroup中。
public class Text extends JFrame{ //定義組件 JPanel jp1,jp2,jp3; JButton jb1,jb2; JLabel jlb1,jlb2; JCheckBox jcb1,jcb2,jcb3; JRadioButton jrb1,jrb2; ButtonGroup bg1;//把單選按鈕放進一個組里 public static void main(String[] args) { Text t=new Text(); } public Text() { //創(chuàng)建組件 jp1=new JPanel(); jlb1=new JLabel("特長"); jcb1=new JCheckBox("音樂"); jcb2=new JCheckBox("體育"); jcb3=new JCheckBox("技藝"); jp1.add(jlb1); jp1.add(jcb1); jp1.add(jcb2); jp1.add(jcb3); jp2=new JPanel(); jlb2=new JLabel("性別"); jrb1=new JRadioButton("男"); jrb2=new JRadioButton("女"); bg1=new ButtonGroup(); bg1.add(jrb1); bg1.add(jrb2);//增長進組,使其只能選一個 jp2.add(jlb2); jp2.add(jrb1); jp2.add(jrb2);//不是把組添加進去 jp3=new JPanel(); jb1=new JButton("注冊"); jb2=new JButton("撤消"); jp3.add(jb1); jp3.add(jb2); this.setLayout(new GridLayout(3,1)); //增長組件 this.add(jp1); this.add(jp2); this.add(jp3); //設(shè)置窗體屬性 this.setTitle("用戶注冊—小勁"); this.setLocation(300, 300); this.setSize(400,300); this.setResizable(false); this.setVisible(true); this.setDefaultClo搜刮引擎優(yōu)化peration(JFrame.EXIT_ON_CLOSE); } }
[img]http://img.blog.csdn.net/20150105233440025?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGlndW9qaW4xMjMw/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
四、下拉框組件(JComboBox)、列表框組件(JList)、滾動窗格組件(JScrollPane)
一般來說,列表框組件+滾動窗格組件是結(jié)合應(yīng)用的
public class Text extends JFrame{ //定義組件 JPanel mb1,mb2; JLabel bq1,bq2; JComboBox xlk; JList lb; JScrollPane gd; public static void main(String[] args) { Text t=new Text(); } public Text() { //創(chuàng)建組件 mb1=new JPanel(); mb2=new JPanel(); bq1=new JLabel("籍貫"); bq2=new JLabel("學(xué)歷"); String[] jg={"陽江","天津","上海","重慶"}; xlk=new JComboBox(jg); String[] xl={"高中","大年夜專","本科","碩士","博士",}; lb=new JList(xl); gd=new JScrollPane(lb);//滾動條 lb.setVisibleRowCount(3);//設(shè)置顯示3個 this.setLayout(new GridLayout(2,1)); //增長組件 mb1.add(bq1); mb1.add(xlk); mb2.add(bq2); mb2.add(gd);//和單選按鈕不合,添加滾動組件 this.add(mb1); this.add(mb2); //設(shè)置窗體屬性 this.setTitle("Layout—小勁"); this.setLocation(300, 300); this.setSize(400,300); this.setResizable(false); this.setVisible(true); this.setDefaultClo搜刮引擎優(yōu)化peration(JFrame.EXIT_ON_CLOSE); } }
[img]http://img.blog.csdn.net/20150106001355421?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbGlndW9qaW4xMjMw/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
本講就到這里,Take your time and enjoy it
相關(guān)案例查看更多
相關(guān)閱讀
- 網(wǎng)站上首頁
- 云南網(wǎng)站設(shè)計
- 網(wǎng)站開發(fā)
- 網(wǎng)頁制作
- 小程序退款
- 報廢車拆解回收管理系統(tǒng)
- 支付寶小程序被騙
- 網(wǎng)站制作
- 云南網(wǎng)站建設(shè)公司地址
- 云南衛(wèi)視小程序
- asp網(wǎng)站
- 云南網(wǎng)站開發(fā)哪家好
- 百度小程序公司
- 百度人工排名
- 報廢車管理系統(tǒng)
- 小程序開發(fā)課程
- 云南網(wǎng)站建設(shè)價格
- 云南軟件開發(fā)
- 小程序商城
- 小程序表單
- 昆明網(wǎng)站設(shè)計
- Web開發(fā)框架
- 云南網(wǎng)站建設(shè)費用
- 制作一個小程序
- 網(wǎng)站建設(shè)哪家強
- 網(wǎng)站建設(shè)公司網(wǎng)站
- 汽車報廢回收管理系統(tǒng)
- 云南網(wǎng)站建設(shè)公司哪家好
- 霸屏推廣
- 英文網(wǎng)站建設(shè)公司