希望有用吧
創(chuàng)新互聯(lián)服務(wù)項(xiàng)目包括橋西網(wǎng)站建設(shè)、橋西網(wǎng)站制作、橋西網(wǎng)頁(yè)制作以及橋西網(wǎng)絡(luò)營(yíng)銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,橋西網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到橋西省份的部分城市,未來相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
package mm;
import java.io.*;
import java.awt.*;
import javax.swing.*;
public class HelloWorld {
public static void main(String[] args){
JFrame w=new JFrame("SKH");
Container con=w.getContentPane();
//Color
con.setBackground(Color.pink);
//Location
w.setBounds(60, 100, 388, 308);
//可見性
w.setVisible(true);
//單擊右上角容器的行為
w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//創(chuàng)建菜單項(xiàng)
JMenuBar menubar=new JMenuBar();
JMenu menu,submenu;
JMenuItem a,b;
menu=new JMenu("菜單");
submenu=new JMenu("子菜單");
a=new JMenuItem("菜單項(xiàng)1");
b=new JMenuItem("菜單項(xiàng)2");
menu.add(a);
//添加分割符;
menu.addSeparator();
menu.add(b);
menu.addSeparator();
menu.add(submenu);
submenu.add(new JMenuItem("QWQ"));
menubar.add(menu);
w.setJMenuBar(menubar);
}
}
import java.awt.Frame;
import java.awt.Menu;
import java.awt.MenuBar;
import java.awt.MenuItem;
import java.awt.MenuShortcut;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;public class Test_11 extends Frame implements ActionListener{ /**
* @param args
*/
MenuBar mb = null;
Menu m = null;
MenuItem mi = null; public Test_11() {
this.setBounds(100, 100, 400, 300);
this.setVisible(true);
mb = new MenuBar();
m = new Menu("文件");
mi = new MenuItem("打開");
mi.setShortcut(new MenuShortcut(KeyEvent.VK_O));
m.add(mi);
mb.add(m);
setMenuBar(mb);
mi.addActionListener(this);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
} public static void main(String[] args) {
// TODO Auto-generated method stub
new Test_11();
} @Override
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}}
import?java.awt.event.MouseAdapter;
import?java.awt.event.MouseEvent;
import?javax.swing.JFrame;
import?javax.swing.JMenu;
import?javax.swing.JMenuBar;
import?javax.swing.JMenuItem;
import?javax.swing.JPopupMenu;
public?class?TestMenu?extends?JFrame?{
private?JPopupMenu?jPopupMenu;
public?TestMenu(String?title){
super(title);
}
public?void?init(){
JMenuBar?bar?=?new?JMenuBar();
JMenu?menuFile?=?new?JMenu("文件");
JMenuItem?menuFile1?=?new?JMenuItem("新建");
JMenuItem?menuFile2?=?new?JMenuItem("打開");
JMenuItem?menuFile3?=?new?JMenuItem("關(guān)閉");
JMenuItem?menuFile4?=?new?JMenuItem("保存");
menuFile.add(menuFile1);
menuFile.add(menuFile2);
menuFile.add(menuFile3);
menuFile.add(menuFile4);
JMenu?helpMenu?=?new?JMenu("幫助");
JMenuItem?helpMenu1?=?new?JMenuItem("新建");
JMenuItem?helpMenu2?=?new?JMenuItem("打開");
helpMenu.add(helpMenu1);
helpMenu.add(helpMenu2);
bar.add(menuFile);
bar.add(helpMenu);
this.setJMenuBar(bar);
jPopupMenu?=?new?JPopupMenu();
JMenuItem?jPopupMenu1?=?new?JMenuItem("顯示圖片");
JMenuItem?jPopupMenu2?=?new?JMenuItem("顯示缺省圖片");
jPopupMenu.add(jPopupMenu1);
jPopupMenu.add(jPopupMenu2);
this.setBounds(200,?200,?500,?400);
this.setResizable(false);
this.setVisible(true);
this.addMouseListener(new?MouseAdapter()?{
@Override
public?void?mouseClicked(MouseEvent?e)?{
if?(e.getButton()==MouseEvent.BUTTON3)?{??
?//彈出右鍵菜單??
jPopupMenu.show(TestMenu.this,?e.getX(),?e.getY());??
}??
???}?????
});
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public?static?void?main(String[]?args)?{
new?TestMenu("測(cè)試菜單").init();
}
}