欢迎来到天天文库
浏览记录
ID:37922261
大小:57.00 KB
页数:10页
时间:2019-06-02
《java swing 组件大全》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、javaswing组件大全(新手快进)importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;importjavax.swing.tree.*;importjavax.swing.event.*;importjavax.swing.border.*;importjavax.swing.table.*;/***Swing组件测试程序*测试Swing所有组件及其相应的事件*@author天翼.李2003.4.17晚23:14*@linkhttp://www.roboc
2、hina.org*@linkrobococde@etang.com*/publicclassSwingTestextendsJFrame{/***主模块,初始化所有子模块,并设置主框架的相关属性*/publicSwingTest(){//初始化所有模块MenuTestmenuTest=newMenuTest();LeftPanelleftPanel=newLeftPanel();RightPanelrightPanel=newRightPanel();BottomPanelbottomPanel=newBottomPanel(
3、);CenterPanelcenterPanel=newCenterPanel();//设置主框架的布局Containerc=this.getContentPane();//c.setLayout(newBorderLayout())this.setJMenuBar(menuTest);c.add(leftPanel,BorderLayout.WEST);c.add(rightPanel,BorderLayout.EAST);c.add(centerPanel,BorderLayout.CENTER);c.add(bottom
4、Panel,BorderLayout.SOUTH);//利用无名内隐类,增加窗口事件this.addWindowListener(newWindowAdapter(){publicvoidWindowClosing(WindowEvente){//释放资源,退出程序dispose();System.exit(0);}});setSize(700,500);setTitle("Swing组件大全简体版");//隐藏frame的标题栏,此功暂时关闭,以方便使用window事件//setUndecorated(true);setLo
5、cation(200,150);show();}/////////////////////////////////////////////////////////////////////////////***菜单栏处理模块*JMenuBar--+*--JMenu--+*--JMenuItem--ActionListener**/classMenuTestextendsJMenuBar{privateJDialogaboutDialog;/***菜单初始化操作*/publicMenuTest(){JMenufileMenu=ne
6、wJMenu("文件");JMenuItemexitMenuItem=newJMenuItem("退出",KeyEvent.VK_E);JMenuItemaboutMenuItem=newJMenuItem("关于...",KeyEvent.VK_A);fileMenu.add(exitMenuItem);fileMenu.add(aboutMenuItem);this.add(fileMenu);aboutDialog=newJDialog();initAboutDialog();//菜单事件exitMenuItem.add
7、ActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){dispose();System.exit(0);}});aboutMenuItem.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){//"关于"对话框的处理aboutDialog.show();}});}/***返回关于对话框*/publicJDialoggetAbout
8、Dialog(){returnaboutDialog;}/***设置"关于"对话框的外观及响应事件,操作和JFrame一样都是在内容*框架上进行的*/publicvoidinitAboutDialog(){aboutDialog.setTitle("关于");Containe
此文档下载收益归作者所有