码迷,mamicode.com
首页 > 编程语言 > 详细

java期末考试 6

时间:2015-03-13 01:51:56      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:java

/**6

 * 利用菜單和窗口編寫一個簡單的文本編輯器

 **/

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.*;
public class Test{
	public static void main(String[] args){
		JFrame exit = new JFrame("簡單的文本編輯器");
		exit.setSize(800, 600);
		exit.setLocation(0, 0);
		exit.setVisible(true);
		
		JTextArea text = new JTextArea(); 	//文本框
		text.setEditable(true);
		exit.getContentPane().add(new JScrollPane(text));
		
		JMenuBar menuBar = new JMenuBar();
		
		JMenu menuFile = new JMenu("File");	//“File”菜單選項
		menuBar.add(menuFile);
		
		JMenu menuEdit = new JMenu("Edit");	//"Edit"菜單選項
		menuBar.add(menuEdit);
		
		JMenu menuHelp = new JMenu("Help");	//"Help"菜單選項
		menuBar.add(menuHelp);
		
		exit.addWindowListener(new WindowAdapter(){		//退出事件監聽
			public void windowClosing(WindowEvent arg0){
				System.exit(1);
			}
		});
		
		exit.setJMenuBar(menuBar);
	}
}


本文出自 “hacker” 博客,请务必保留此出处http://anglecode.blog.51cto.com/5628271/1619888

java期末考试 6

标签:java

原文地址:http://anglecode.blog.51cto.com/5628271/1619888

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!