⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 notepad_jmenubarlistener.java

📁 java 编写的代码
💻 JAVA
字号:
package com.edu.sccp.snail.notepad.events;

import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextArea;

import com.edu.sccp.snail.notepad.view.Notepad_Main;

/**
 * JMenuBarListener By inner class
 * 
 * @author Administrator
 * 
 */
public class Notepad_JMenuBarListener implements ActionListener {
	Notepad_Main parner = null;   //父窗体
	JTextArea jta = null;
	JLabel l = null;
	public Notepad_JMenuBarListener(JFrame notepad){
		this.parner = parner;	
	}
	public void actionPerformed(ActionEvent e) {
		String fname = null;
		JFileChooser jfc = null;
		File file = null;
		boolean flags = true;

		if (e.getActionCommand().equals("新建 (N)")) {
		
		}
		// 监听打开
		if (e.getActionCommand().equals("打开 (O)")) {
			jfc = new JFileChooser("c:/");
			jfc.showOpenDialog(null);
			file = jfc.getSelectedFile();
			fname = file.getAbsolutePath();
			String str = "";
			try {
				FileReader fileReader = new FileReader(fname);
				int rd;
				rd = fileReader.read();
				while (rd != -1) {
					str = str + (char) rd;
					rd = fileReader.read();
				}
			} catch (IOException e1) {
				e1.printStackTrace();
			}
			jta.setText(str);
		}
		// 监听保存?做的和另存为一样!要改!!
		if (e.getActionCommand().equals("保存 (S)")) {
			jfc = new JFileChooser("c:/");
			jfc.showSaveDialog(null);
			file = jfc.getSelectedFile();
			fname = file.getAbsolutePath();

			try {
				FileWriter filewriter = new FileWriter(fname);
				String string;
				string = jta.getText();
				filewriter.write(string);
				filewriter.close();

			} catch (IOException e1) {
				e1.printStackTrace();
			}
		}
		if (e.getActionCommand().equals("另存为(A)")) {
			jfc = new JFileChooser("c:/");
			jfc.showSaveDialog(null);
			file = jfc.getSelectedFile();
			fname = file.getAbsolutePath();

			try {
				FileWriter filewriter = new FileWriter(fname);
				String string;
				string = jta.getText();
				filewriter.write(string);
				filewriter.close();

			} catch (IOException e1) {
				e1.printStackTrace();
			}
		}
		if (e.getActionCommand().equals("退出(E)")) {
			System.exit(-1);
		}
		if (e.getActionCommand().equals("撤销(U)")) {
			System.exit(-1);
		}
		if (e.getActionCommand().equals("剪贴(T)")) {
			System.exit(-1);
		}
		if (e.getActionCommand().equals("复制(C)")) {
			System.exit(-1);
		}
		if (e.getActionCommand().equals("粘贴(P)")) {
			System.exit(-1);
		}
		if (e.getActionCommand().equals("查找(F)")) {
			System.exit(-1);
		}
		if (e.getActionCommand().equals("查找下一个(N)")) {
			System.exit(-1);
		}
		if (e.getActionCommand().equals("替换(R)")) {
			System.exit(-1);
		}
		if (e.getActionCommand().equals("自动换行(W)")) {
			jta.setWrapStyleWord(true);
		}
		if (e.getActionCommand().equals("字体(F)")) {
			System.exit(-1);
		}
		if (e.getActionCommand().equals("颜色(C)")) {
			System.exit(-1);
		}
		if (e.getActionCommand().equals("状态栏(Z)")) {	
			/*if(!flags)
			parner.l.setVisible(true);
			else
			l.setVisible(false);
			flags = true? false : true;	*/
		}if (e.getActionCommand().equals("主题")) {
				System.exit(-1);
			}
		
	}
}

⌨️ 快捷键说明

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