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

📄 simpleeditor.java

📁 java就业培训教程第五章实例
💻 JAVA
字号:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class SimpleEditor extends MIDlet implements CommandListener{

	Display display;
	TextBox editor;
	String testString = "测试字符串";
	Command exitCmd;
	Command markCmd;
	Command copyCmd;
	Command cutCmd;
	Command pasteCmd;
	boolean hasData = false;
	boolean isMarked = false;
	int head, tail;
	String bufferedData;

	public SimpleEditor(){
		display = Display.getDisplay(this);
		editor = new TextBox("建议编辑器", testString, 20, TextField.ANY);
		exitCmd = new Command("退出", Command.EXIT, 1);
		markCmd = new Command("选取", Command.SCREEN, 1);
		copyCmd = new Command("复制", Command.SCREEN, 2);
		cutCmd = new Command("剪切", Command.SCREEN, 3);
		pasteCmd = new Command("粘贴", Command.SCREEN, 4);
		editor.addCommand(exitCmd);
		editor.addCommand(markCmd);
		editor.addCommand(copyCmd);
		editor.addCommand(cutCmd);
		editor.addCommand(pasteCmd);
		editor.setCommandListener(this);
	}


	public void startApp(){
		display.setCurrent(editor);

	}

	public void pauseApp(){


	}

	public void destroyApp(boolean unconditional){

	}

	public void commandAction(Command c,Displayable d){

		if(c == exitCmd){
			destroyApp(false);
			notifyDestroyed();
		}
		else if(c == markCmd){
			isMarked = true;
			head = editor.getCaretPosition();
		}
		else if(c == copyCmd){
			if(isMarked == true){
				char[] tempString = new char[editor.size()];
				tail = editor.getCaretPosition();
				editor.getChars(tempString);
				bufferedData = String.valueOf(tempString, head, tail-head);
				hasData = true;
				isMarked = false;
			}
		}
		else if(c == cutCmd){
			if(isMarked == true){
				char[] tempString = new char[editor.size()];
				tail = editor.getCaretPosition();
				editor.getChars(tempString);
				bufferedData = String.valueOf(tempString, head, tail-head);
				editor.delete(head, tail-head);
				hasData = true;
				isMarked = false;
			}
		}
		else if(c == pasteCmd){
			if(hasData == true){
				editor.insert(bufferedData,editor.getCaretPosition());
		        hasData = false;
			}
		}
	}

}

⌨️ 快捷键说明

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