GUI記事本+切換面板

來源:互聯網
上載者:User

標籤:

package com.niit.javagui;import java.awt.Color;import java.awt.MenuBar;import java.awt.event.InputEvent;import java.awt.event.KeyEvent;import javax.swing.JFrame;import javax.swing.JMenu;import javax.swing.JMenuBar;import javax.swing.JMenuItem;import javax.swing.JPanel;import javax.swing.JTabbedPane;import javax.swing.KeyStroke;/** * @author: Annie * @date:2016年5月30日 * @description: */public class JTabbedPaneDemo extends JFrame{    public static void main(String[] args) {        new JTabbedPaneDemo();    }    JTabbedPane tabbedPane;    JPanel jp1,jp2,jp3;    JMenuBar menuBar;    JMenu filemenu,editMenu,formatMenu,helpmenu,checkMenu;    JMenuItem itemNew,itemOpen,itemSave,itemSaveAs,itemSet,itemPrint,itemExit,    itemAutomatic,itemFont,itemaStatusBar,itemaCheckHelp,itemAbout;        public JTabbedPaneDemo(){        setVisible(true);        setSize(400,400);        setTitle("選項卡面板例子");        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        instantiationObject();            keyWord();        addFunction();        jp1.setBackground(Color.CYAN);        jp2.setBackground(Color.RED);        jp3.setBackground(Color.BLUE);            }        /**     * 執行個體化對象方法     * */    public void instantiationObject(){        jp1 = new JPanel();        jp2 = new JPanel();        jp3 = new JPanel();        tabbedPane = new JTabbedPane(JTabbedPane.BOTTOM);        menuBar = new JMenuBar();        filemenu = new JMenu("檔案(F)");        editMenu = new JMenu("編輯(E)");        formatMenu = new JMenu("格式(o)");        checkMenu = new JMenu("查看(V)");        helpmenu = new JMenu("協助(H)");                itemNew = new JMenuItem("建立檔案");        itemOpen = new JMenuItem("開啟");        itemSave = new JMenuItem("儲存");        itemSaveAs = new JMenuItem("另存新檔");        itemSet = new JMenuItem("版面設定");        itemPrint = new JMenuItem("列印");        itemExit = new  JMenuItem("退出");                itemAutomatic = new JMenuItem("自動轉行");        itemFont = new JMenuItem("字型");                itemaStatusBar = new JMenuItem("狀態列");                itemaCheckHelp = new JMenuItem("查看協助");        itemAbout = new JMenuItem("關於記事本");                    }        /**     * 添加組件方法     * */    public void addFunction(){        setJMenuBar(menuBar);                menuBar.add(filemenu);        menuBar.add(editMenu);        menuBar.add(formatMenu);        menuBar.add(checkMenu);        menuBar.add(helpmenu);                filemenu.add(itemNew);        filemenu.add(itemOpen);        filemenu.add(itemSave);        filemenu.add(itemSaveAs);        filemenu.addSeparator();        filemenu.add(itemSet);        filemenu.add(itemPrint);        filemenu.add(itemExit);                formatMenu.add(itemAutomatic);        formatMenu.add(itemFont);                checkMenu.add(itemaStatusBar);                helpmenu.add(itemaCheckHelp);        helpmenu.add(itemAbout);                tabbedPane.add("連絡人", jp1);        tabbedPane.add("發現", jp2);        tabbedPane.add("我", jp3);        add(tabbedPane);    }        /**     * 添加關鍵字的方法     * */    public void keyWord(){        itemNew.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,InputEvent.CTRL_MASK));        itemOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,InputEvent.CTRL_MASK));        itemSave.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK));        itemSaveAs.setAccelerator(KeyStroke.getKeyStroke(‘A‘));        itemSet.setAccelerator(KeyStroke.getKeyStroke(‘U‘));        itemPrint.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P,InputEvent.CTRL_MASK));        itemExit.setAccelerator(KeyStroke.getKeyStroke(‘X‘));                itemAutomatic.setAccelerator(KeyStroke.getKeyStroke(‘W‘));        itemFont.setAccelerator(KeyStroke.getKeyStroke(‘F‘));                itemaStatusBar.setAccelerator(KeyStroke.getKeyStroke(‘S‘));                itemaCheckHelp.setAccelerator(KeyStroke.getKeyStroke(‘H‘));        itemAbout.setAccelerator(KeyStroke.getKeyStroke(‘A‘));    }}

 :

GUI記事本+切換面板

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.