當前位置:成語大全網 - 書法字典 - 如何做壹個java圖形界面子窗體?

如何做壹個java圖形界面子窗體?

我給妳壹個我自己用Swing寫的MDI(多文檔用戶界面)的代碼,僅供參考:packagecom。JB . cdjj . y2t 027 . fly dream . HRMS . swing;導入Java . awt . awt event;

導入Java . awt . borderlayout;

導入Java . awt . dimension;

導入Java . awt . flow layout;

導入Java . awt . event . action event;

導入Java . awt . event . action listener;

導入Java . awt . event . component adapter;

導入Java . awt . event . component event;

導入Java . awt . event . window adapter;

導入Java . awt . event . window event;

導入Java . beans . propertyvetoexception;

導入Java . text . simple date format;

導入Java . util . calendar;導入javax . swing . border factory;

導入javax . swing . image icon;

導入javax . swing . jbutton;

導入javax . swing . jdesktoppane;

導入javax . swing . jframe;

導入javax . swing . jinternalframe;

導入javax . swing . jlabel;

導入javax . swing . jmenu;

導入javax . swing . jmenubar;

導入javax . swing . jmenuitem;

導入javax . swing . joptionpane;

導入javax . swing . jpanel;

導入javax . swing . jprogressbar;

導入javax . swing . jscrollpane;

導入javax . swing . jseparator;

導入javax . swing . jtoolbar;

導入javax . swing . timer;

導入javax . swing . border . bevel border;導入com . JB . cdjj . y2t 027 . fly dream . HRMS . POJO . users POJO;

導入com . JB . cdjj . y2t 027 . fly dream . HRMS . swing . component . jdesktopscrollpane;

導入com . JB . cdjj . y2t 027 . fly dream . HRMS . swing . utils . character common;/**

* & ltp & gt描述:FrmMain主界面窗口UI類

* & ltp & gt作者:鄧超

* & ltp & gt班級:Y2T027飛夢集團

* & ltp & gt時間:2009年5月-13

* & ltp & gt地點:宿舍

* & ltp & gt版本:1.0.0.1

*/

公共類FrmMain擴展JFrame { /**

*序列化版本ID

*/

private static final long serial version uid =-6893438572255430328 l;{

//設置UI觀感效果(使用三方jar包:looks-2.1.4.jar)

嘗試{

javax . swing . ui manager . setlookandfeel(" com . jgoodies . looks . plastic . plastic xplookandfeel ");

} catch(異常e) {

e . printstacktrace();

}

} /**

*用戶界面組件

*/

私有JMenuItem mnuItemHelpTopic

列兵JPanel pnlMain

私人JMenu mnuHelp

私有JMenuItem mnuItemDelete

private JPanel pnlTlb

private JSeparator septEdit

private JMenuItem mnuItemPaste

私有JMenuItem mnuItemCopy

私有JMenuItem mnuItemCut

二等兵JMenu mnuEdit

私有JMenuItem mnuItemLock

private JMenuItem mnuItemExit

private JSeparator septSystemBottom;

私有JMenuItem mnuItemAbout

private JMenuItem mnuItemLogout

private JSeparator sept systemtop;

私有JMenuItem mnuItemPermissions

私有JMenuItem mnuItemParamConfig

private JLabel lblLoginUser

私有JScrollPane pnlScrollContent

private JMenuItem mnuCloseAll

私有JSeparator septWindow

private JMenuItem mnuitemclosescurrent;

私有JMenuItem mnuItemSwitch

列兵JMenu mnuWindow

private JLabel lblTime

private JLabel lblProgressMsg

private jprogress bar progress operation;

私有JDesktopPane pnlDsk

private JPanel pnlStatus

私有JButton btnHelp

私有JButton btnExit

私有JButton btnLogout

私有JButton btnLockScreen

private JToolBar tlbMain

私有JMenu mnuSystem

列兵JMenuBar mnuBarMain

私有JButton權限;

私有JButton btnParamConfig

private JLabel lblTlbSpliter2

private JLabel lbltlbspliter 1;

private JMenuItem mnuModifyPwd

私有靜態FrmLogin frmLogin

私有JPanel pnlContent

私有靜態UsersPojo currentLoginUser/**

*獲取當前登錄用戶

* @返回當前登錄的用戶實體

*/

公共靜態UsersPojo getCurrentLoginUser(){

返回currentLoginUser

}

/**

*設置當前登錄的用戶。

* @param currentLoginUser當前登錄的實體。

*/

公共靜態void setCurrentLoginUser(UsersPojo currentLoginUser){

frmmain . current log in user = current log in user;

} /**

*參數構造器

* @ param loginWindow登錄UI實例

*/

公共窗體(窗體登錄登錄窗口){

super();

frmLogin = loginWindow

init GUI();

this . addcomponentlister(new component adapter(){/* *

*組件顯示事件方法

*/

@覆蓋

public void component showed(component event e){

lblLoginUser.setText(" "

+ (currentLoginUser!=空

?(current log in user . getloginaccount()+"/"+current log in user . getusersname())

:“未登錄”)

+ "");

super . component showed(e);

}

});

}

/**

* UI組件初始化方法

*/

私有void initGUI() {

嘗試{

{

BorderLayout this layout = new BorderLayout();

getContentPane()。set layout(this layout);

}

{

mnuBarMain = new JMenuBar();

setJMenuBar(mnuBarMain);

{

mnu system = new JMenu();

mnubarmain . add(mnus system);

mnus system . settext(" system(s)");

mnu system . set mnemonic(Java . awt . event . key event . vk _ S);

mnu system . setname(" mnu system ");

mnus system . setdoublebuffered(false);

{

mnuItemParamConfig = new JMenuItem();

mnus system . add(mnuItemParamConfig);

MnuItemParamConfig.setText("參數設置(p)... ");

Mnuitemparamconfig。Set TooltipText("前臺系統字典及參數設置");

mnuitemparamconfig . set mnemonic(Java . awt . event . key event . vk _ P);

mnuItemParamConfig . setname(" mnuItemParamConfig ");

mnuitemparamconfig . seticon(new image icon(getClass()。getClassLoader()。get resource(" img/param . png "));

mnuitemparamconfig . setdoublebuffered(false);

mnuitemparamconfig . addactionlistener(new action listener(){

/**

*激活參數設置菜單項的事件方法

*/

public void action performed(action event e){

openOnlyOneInternalFrame(frminlparam . getinstance());

}

});

}

{

mnuItemPermissions = new JMenuItem();

mnu system . add(mnuItemPermissions);

MnuItemPermissions.setText("權限管理(e)... ");

mnuittemppermissions。Set TooltipText("系統用戶及其授權管理");

mnuItemPermissions . setname(" mnuItemPermissions ");

mnuitempermissions . set mnemonic(Java . awt . event . key event . vk _ E);

mnuitempermissions . seticon(new image icon(getClass()。getClassLoader()。get resource(" img/permissions . png "));

mnuitempermissions . setdoublebuffered(false);

mnuitempermissions . addactionlistener(new action listener(){

/**

*激活權限管理菜單項的事件方法。

*/

public void action performed(action event e){

openOnlyOneInternalFrame(frminlpermissions . getinstance());

}

});

}

{

sept systemtop = new JSeparator();

mnus system . add(sept systemtop);

sept systemtop . set name(" sept systemtop ");

sept systemtop . setdoublebuffered(false);

}

-字數太多,所以要單獨開發。