深入浅出JavaSwing程序设计一书的源代码

源代码在线查看: mainframe.java

软件大小: 792 K
上传用户: huanghuanl
关键词: JavaSwing 程序设计 源代码
下载地址: 免注册下载 普通下载 VIP

相关代码

				import javax.swing.*;
				import javax.swing.border.*;
				import javax.swing.text.*;
				import javax.swing.event.*;
				import java.awt.event.*;
				import java.awt.*;
				import java.util.*;
				import java.io.*;
				import java.lang.*;
				import javax.swing.undo.*;
				
				public class MainFrame
				{ 
				    JDesktopPane desktop;
				    JFrame topFrame;
				    JMenuBar menuBar;
				    JPopupMenu popupMenu;
				    
				    public MainFrame()
				    {
				        topFrame = new JFrame("MainFrame-Look and Feel");
				        topFrame.setBounds(100,100,630,400);  // --- setBounds(x畒夹,y畒夹,糴,蔼)
				        buildContent();
				        buildMenuBar();
				        buildToolBar();
				        popupMenu = buildPopupMenu();
				        
				        topFrame.addWindowListener(new WindowAdapter() {
				        	public void windowClosing(WindowEvent e) {
				        	  System.exit(0); 
				            }
				        }); //end of addWindowListener
				        
				        topFrame.setVisible(true);
				    } //end of MainFrame()
				    
				    public void buildContent()
				    {
				        desktop = new JDesktopPane();
				        topFrame.getContentPane().add(desktop);
				    }//end of buildContent()
				    
				    public void buildMenuBar()
				    {
				        String menuName;
				        
				        menuBar = new JMenuBar();
				        menuName = "File";
				        String[] fileFunctions = {"New", "Open", "Close", "Exit"};
				        char[] fileMnemonic = {'N', 'O', 'L', 'X'};
				        JMenu mfile = buildMenu(menuName,fileFunctions,fileMnemonic);
				        
				        menuName = "Edit";
				        String[] editFunctions = {"Undo","Redo","addSeparator","Copy", "Cut", "Paste"};
				        char[] editMnemonic = {'Z','Y','0','T', 'C', 'P'};
				        JMenu medit = buildMenu(menuName,editFunctions,editMnemonic);
				        
				        JMenu malign = buildAlignMenu();
				        
				        menuName = "Insert";
				        String[] insertFunctions = {"Picture", "Object"};
				        char[] insertMnemonic = null;
				        JMenu minsert = buildMenu(menuName,insertFunctions,insertMnemonic);
				        
				        menuName = "Demo";
				        String[] demoFunctions = {"Slider", "Tree Structure", "Table Structure", "Password"};
				        char[] demoMnemonic = {'S', 'T', 'A', 'P'};
				        JMenu mdemo = buildMenu(menuName,demoFunctions,demoMnemonic);
				        
				        menuName = "Help";
				        String[] helpFunctions = {"About this Program", "Open Help Window"};
				        char[] helpMnemonic = {'B', 'H'};     
				        JMenu mhelp = buildMenu(menuName,helpFunctions,helpMnemonic);
				    
				        //砞﹚Hot Key Alt+'?'    
				        mfile.setMnemonic('F');
				        medit.setMnemonic('E');
				        malign.setMnemonic('A');
				        minsert.setMnemonic('I'); 
				        mdemo.setMnemonic('D');
				        mhelp.setMnemonic('H');
				        
				        menuBar.add(mfile); //盢 File 匡兜			

相关资源