Java online chat Project swt visualization window design redesign Buddy List window add menu bar

Source: Internet
Author: User
Tags password protection

The added menu bar is as follows:

In eclipse, adjust to the design view of SWT

Control area Select Menu Controls

Drag the menu bar to the window title bar

Drag the cascaded menu to the menu Bar

Add multiple menu item to new submenu in turn

Separator is a delimiter

You can also put cascaded menu cascading menus

The code for the Buddy List window is as follows:

 PackageCom.swift.frame;Importjava.awt.BorderLayout;Importjava.awt.Component;Importjava.awt.Dimension;ImportJava.awt.EventQueue;Importjava.awt.FlowLayout;ImportJava.awt.event.MouseAdapter;Importjava.awt.event.MouseEvent;ImportJava.awt.event.WindowAdapter;Importjava.awt.event.WindowEvent;ImportJavax.swing.ImageIcon;ImportJavax.swing.JButton;ImportJavax.swing.JDialog;ImportJavax.swing.JFrame;ImportJavax.swing.JLabel;ImportJavax.swing.JMenu;ImportJavax.swing.JMenuBar;ImportJavax.swing.JMenuItem;ImportJavax.swing.JPanel;ImportJavax.swing.JPopupMenu;ImportJavax.swing.JTabbedPane;Importjavax.swing.SwingConstants;ImportJavax.swing.UIManager;Importjavax.swing.UnsupportedLookAndFeelException; Public classFriendsdialogextendsJDialog { Public Static voidMain (String args[]) {jframe.setdefaultlookandfeeldecorated (true); Jdialog.setdefaultlookandfeeldecorated (true); Try{Uimanager.setlookandfeel ("Javax.swing.plaf.nimbus.NimbusLookAndFeel"); } Catch(ClassNotFoundException E1) {e1.printstacktrace (); } Catch(instantiationexception E1) {e1.printstacktrace (); } Catch(illegalaccessexception E1) {e1.printstacktrace (); } Catch(unsupportedlookandfeelexception E1) {e1.printstacktrace (); } eventqueue.invokelater (NewRunnable () { Public voidrun () {Try{Friendsdialog Dialog=NewFriendsdialog (); Dialog.addwindowlistener (NewWindowadapter () { Public voidwindowclosing (windowevent e) {system.exit (0);                    }                    }); Dialog.setvisible (true); } Catch(Exception e) {e.printstacktrace ();    }            }        }); }     PublicFriendsdialog () {Super(); Settitle ("Swallow Chat"); SetBounds (100, 100, 247, 581); FinalJPanel Panel =NewJPanel (); Panel.setlayout (NewBorderLayout ());        Getcontentpane (). Add (Panel, Borderlayout.north); FinalJLabel label =NewJLabel (NewImageIcon ("Images/logo.jpg")); Label.settext ("New JLabel");        Panel.add (label, borderlayout.west); Label.setpreferredsize (NewDimension (74,74)); FinalJPanel Panel_1 =NewJPanel (); Panel_1.setlayout (NewBorderLayout ());        Panel.add (Panel_1, Borderlayout.center); FinalJLabel Advancingswiftlabel =NewJLabel (); Advancingswiftlabel.settext ("Advancing Swift");        Panel_1.add (Advancingswiftlabel, Borderlayout.center); FinalJLabel Neverwasterlabel =NewJLabel (); Neverwasterlabel.settext ("Never waste time any more");        Panel_1.add (Neverwasterlabel, Borderlayout.south); FinalJPanel panel_2 =NewJPanel (); Panel_2.setlayout (NewBorderLayout ());        Getcontentpane (). Add (panel_2, Borderlayout.south); FinalJPanel Panel_3 =NewJPanel (); FinalFlowLayout FlowLayout =NewFlowLayout ();        Flowlayout.setalignment (Flowlayout.left);        Panel_3.setlayout (FlowLayout);        Panel_2.add (Panel_3); FinalJButton button =NewJButton ();        Panel_3.add (button);        Button.sethorizontaltextposition (Swingconstants.left);        Button.sethorizontalalignment (Swingconstants.left); Button.settext (Settings); FinalJButton button_1 =NewJButton ();        Panel_3.add (button_1); Button_1.settext (Find); FinalJPanel Panel_4 =NewJPanel ();        Panel_2.add (Panel_4, borderlayout.east); FinalJButton button_2 =NewJButton ();        Panel_4.add (button_2); Button_2.settext (Exit); FinalJTabbedPane TabbedPane =NewJTabbedPane ();        Getcontentpane (). Add (TabbedPane, borderlayout.center); FinalJPanel panel_5 =NewJPanel (); Tabbedpane.addtab ("Friends List",NULL, Panel_5,NULL); FinalJPanel panel_6 =NewJPanel (); Tabbedpane.addtab ("Group chat",NULL, Panel_6,NULL); FinalJPanel panel_7 =NewJPanel (); Tabbedpane.addtab ("Chat History",NULL, Panel_7,NULL); FinalJMenuBar MenuBar =NewJMenuBar ();        Setjmenubar (MenuBar); FinalJMenu menu =NewJMenu (); Menu.settext (Operation);        Menubar.add (menu); FinalJMenuItem Newitemmenuitem =NewJMenuItem (); Newitemmenuitem.settext (Settings);        Menu.add (Newitemmenuitem); FinalJMenuItem newitemmenuitem_1 =NewJMenuItem (); Newitemmenuitem_1.settext (Space);        Menu.add (newitemmenuitem_1); FinalJMenuItem newitemmenuitem_2 =NewJMenuItem (); Newitemmenuitem_2.settext (Mailbox);        Menu.add (newitemmenuitem_2); FinalJMenu menu_1 =NewJMenu (); Menu_1.settext (Member);        Menu.add (menu_1); FinalJMenuItem Newitemmenuitem_3 =NewJMenuItem (); Newitemmenuitem_3.settext ("Member's website");        Menu_1.add (Newitemmenuitem_3); FinalJMenuItem Newitemmenuitem_4 =NewJMenuItem (); Newitemmenuitem_4.settext ("Member Area");        Menu_1.add (Newitemmenuitem_4);        Menu.addseparator (); FinalJMenu menu_2 =NewJMenu (); Menu_2.settext (Security);        Menu.add (menu_2); FinalJMenuItem newitemmenuitem_5 =NewJMenuItem (); Newitemmenuitem_5.settext ("Emergency Freeze");        Menu_2.add (newitemmenuitem_5); FinalJMenuItem newitemmenuitem_6 =NewJMenuItem (); Newitemmenuitem_6.settext ("Password protection");        Menu_2.add (Newitemmenuitem_6); FinalJMenuItem newitemmenuitem_7 =NewJMenuItem (); Newitemmenuitem_7.settext (Exit);        Menu.add (newitemmenuitem_7); FinalFlowLayout flowlayout_1 =NewFlowLayout ();    Flowlayout_1.setalignment (Flowlayout.right); }    /*** Windowbuilder generated method.<br> * Please don ' t remove the This method or its invocations.<br> * It used by Windowbuilder to associate the {@linkJavax.swing.JPopupMenu} with parent. */    Private Static voidAddpopup (Component Component,FinalJPopupMenu Popup) {Component.addmouselistener (NewMouseadapter () { Public voidmousepressed (MouseEvent e) {if(E.ispopuptrigger ()) ShowMenu (e); }             Public voidmousereleased (MouseEvent e) {if(E.ispopuptrigger ()) ShowMenu (e); }            Private voidShowMenu (MouseEvent e) {popup.show (E.getcomponent (), E.getx (), e.gety ());    }        }); }}

Java online chat Project swt visualization window design redesign Buddy List window add menu bar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.