PackageCom.niit.javagui;ImportJava.awt.Color;ImportJava.awt.MenuBar;Importjava.awt.event.InputEvent;Importjava.awt.event.KeyEvent;ImportJavax.swing.JFrame;ImportJavax.swing.JMenu;ImportJavax.swing.JMenuBar;ImportJavax.swing.JMenuItem;ImportJavax.swing.JPanel;ImportJavax.swing.JTabbedPane;ImportJavax.swing.KeyStroke;/** * @author: Annie * @date: May 30, 2016 * @description:*/ Public classJtabbedpanedemoextendsjframe{ Public Static voidMain (string[] args) {NewJtabbedpanedemo (); } 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; PublicJtabbedpanedemo () {setvisible (true); SetSize (400,400); Settitle ("tab Panel Example"); Setdefaultcloseoperation (Jframe.exit_on_close); Instantiationobject (); KeyWord (); AddFunction (); Jp1.setbackground (Color.cyan); Jp2.setbackground (color.red); Jp3.setbackground (Color.Blue); } /*** Instantiation of Object Methods **/ Public voidInstantiationobject () {JP1=NewJPanel (); JP2=NewJPanel (); JP3=NewJPanel (); TabbedPane=NewJTabbedPane (Jtabbedpane.bottom); MenuBar=NewJMenuBar (); Filemenu=NewJMenu ("File (F)"); Editmenu=NewJMenu ("edit (E)"); Formatmenu=NewJMenu ("Format (o)"); Checkmenu=NewJMenu ("View (V)"); Helpmenu=NewJMenu ("Help (H)"); Itemnew=NewJMenuItem ("New File"); Itemopen=NewJMenuItem ("Open"); Itemsave=NewJMenuItem ("Save"); Itemsaveas=NewJMenuItem ("Save As"); Itemset=NewJMenuItem ("Page Setup"); Itemprint=NewJMenuItem ("Print"); Itemexit=NewJMenuItem ("Exit"); Itemautomatic=NewJMenuItem ("Auto Career"); ItemFont=NewJMenuItem ("Font"); Itemastatusbar=NewJMenuItem ("Status bar"); Itemacheckhelp=NewJMenuItem ("View Help"); Itemabout=NewJMenuItem ("About Notepad"); } /*** Add Component Method **/ Public voidaddfunction () {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 (Contact, JP1); Tabbedpane.add (Found, JP2); Tabbedpane.add (I, JP3); Add (TabbedPane); } /*** How to add keywords **/ Public voidKeyWord () {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 Notepad + Toggle Panel