2014年2月7日星期五

How to add a menu to the window ?

 This post last edited by proof1 on 2014-01-29 21:30:45
window as follows :

import javax.swing *;. import java.awt *;. import java.awt.event *.;

public class Test implements ActionListener {
public static void main (String [] args) {
JFrame win = new JFrame (" Practice " ) ;
win.setSize (900,900);
win.getContentPane () setBackground (Color.BLACK).;
win.setVisible (true);
}
}


want to add to the window menu bar . For example, a simplified example : file ( open exit ) view ( single-screen , full-screen )
reference code :
JMenuBar menubar = new JMenuBar ();
JMenuItem anItem;

JMenu menu1 = new JMenu (" File" ) ;
anItem = new JMenuItem (" Open "); menu1.add (anItem); anItem.addActionListener (this);
anItem = new JMenuItem (" Exit "); menu1.add (anItem); anItem.addActionListener (this);

JMenu menu2 = new JMenu (" View" ) ;
anItem = new JMenuItem (" single screen "); menu2.add (anItem); anItem.addActionListener (this);
anItem = new JMenuItem (" fullscreen "); menu2.add (anItem); anItem.addActionListener (this);

menubar.add (menu1);
menubar.add (menu2);


How to add a menu bar to the window ? Please use two ways
One is to add code directly in the menu window .
Another is to clear structure , so the menu independent . Create a new menu category , then add a menu to the window object .
------ Solution ---------------------------------------- ----
Okay, I admit here to help you receive points . I learn C + +, , JAVA ignorant .
------ Solution ---------------------------------------- ----
not learned where ,
------ For reference only ------------------------- --------------
help it. Thank you.
------ For reference only -------------------------------------- -
expert help . Come on .
------ For reference only -------------------------------------- -
JMenubar jmb ;/ / Just one , multi- language switch
JMenu jm ;/ / View Favorites Tools Help File
jmb.add (jm);

JMenuItem jmi;
jm.add (jmi);


classes can inherit jmi
JCheckBoxMenuItem
JRadioButtonMenuItem
ButtonGroup
usage and swing almost
------ For reference only ----------------------------- ----------
closing minutes

没有评论:

发表评论