jmenu1.java

来自「100个java小例子」· Java 代码 · 共 42 行

JAVA
42
字号
import javax.swing.*;
import java.awt.event.*;

public class JMenu1 extends JFrame{

	JTextArea theArea = null;

	public JMenu1(){
	  
	  super("JMenu1");
	  theArea = new JTextArea();
	  theArea.setEditable(false);
	  getContentPane().add(new JScrollPane(theArea));
	  JMenuBar MBar = new JMenuBar();
	  
	  JMenu mfile = buildFileMenu();

	  MBar.add(mfile);  
	  setJMenuBar(MBar);
	}//end of JMenu1()

	public JMenu buildFileMenu() {
  	
	  JMenu thefile = new JMenu("File");
	  thefile.setIcon(new ImageIcon("icons/file.gif"));

	  return thefile;
	}//end of buildFileMenu()

	
	public static void main(String[] args){

	  JFrame F = new JMenu1();
	  F.setSize(400,200);
	  F.addWindowListener(new WindowAdapter() {
	    public void windowClosing(WindowEvent e) {
	      System.exit(0); 
	    }
	  });//end of addWindowListener
	  F.setVisible(true); 
	} // end of main
}//end of class JMenu1

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?