📄 np.java
字号:
}
else{
ji2_1.setEnabled(false);
ji2_2.setEnabled(false);
ji2_3.setEnabled(false);
ji2_5.setEnabled(false);
ji2_6.setEnabled(false);
ji2_7.setEnabled(false);
}
}
public void mouseReleased(MouseEvent e) {
if(jta.getSelectedText() != null && !jta.getSelectedText().equals("")){
ji2_1.setEnabled(true);
ji2_2.setEnabled(true);
ji2_3.setEnabled(true);
ji2_5.setEnabled(true);
ji2_6.setEnabled(true);
ji2_7.setEnabled(true);
}
else{
ji2_1.setEnabled(false);
ji2_2.setEnabled(false);
ji2_3.setEnabled(false);
ji2_5.setEnabled(false);
ji2_6.setEnabled(false);
ji2_7.setEnabled(false);
}
}
@Override
public void mouseMoved(MouseEvent e) {
}
}
//按钮类
class Note_jButtonNew_actionAdapter implements ActionListener {
private Np adaptee;
Note_jButtonNew_actionAdapter(Np adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButtonNew_actionPerformed(e);
}
}
class Note_jButtonOpen_actionAdapter implements ActionListener {
private Np adaptee;
Note_jButtonOpen_actionAdapter(Np adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButtonOpen_actionPerformed(e);
}
}
class Note_jButtonSave_actionAdapter implements ActionListener {
private Np adaptee;
Note_jButtonSave_actionAdapter(Np adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.jButtonSave_actionPerformed(e);
}
}
//处理选择字体的ActionListener
class SelectFont implements ActionListener{
public void actionPerformed(ActionEvent event){
final String str[];
Toolkit kit = Toolkit.getDefaultToolkit();
Dimension screenSize = kit.getScreenSize();
JDialog dialog = new JDialog(th,"字体选择",true);
Point point = new Point();
point = jta.getLocation();
dialog.setLocation((screenSize.width-point.x)/2,(screenSize.height-point.y)/2);
dialog.setLayout(new FlowLayout());
GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
str = environment.getAvailableFontFamilyNames();
final JComboBox comboBox = new JComboBox(str);
comboBox.addItemListener(
new ItemListener(){
public void itemStateChanged(ItemEvent event){
if(event.getStateChange() == ItemEvent.SELECTED){
int style = jta.getFont().getStyle();
int size = jta.getFont().getSize();
jta.setFont(new Font(str[comboBox.getSelectedIndex()],style,size));
}
}
}
);
JLabel label = new JLabel("请选择您喜爱的字体:");
dialog.add(label);
dialog.add(comboBox);
dialog.setSize(250,100);
dialog.setVisible(true);
}
}
//处理放大、缩小字体的ActionListener
class fontChange implements ActionListener{
public void actionPerformed(ActionEvent event){
if(event.getActionCommand().equals("放大字体")){
String fontName = jta.getFont().getFontName();
int fontSize = jta.getFont().getSize();
int style = jta.getFont().getStyle();
if(fontSize<=64)
jta.setFont(new Font(fontName,style,fontSize+1));
}
else if(event.getActionCommand().equals("缩小字体")){
String fontName = jta.getFont().getFontName();
int fontSize = jta.getFont().getSize();
int style = jta.getFont().getStyle();
if(fontSize>10)
jta.setFont(new Font(fontName,style,fontSize-1));
}
}
}
/***调用各种自定义函数,实现各种行为事件*********************************************************/
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == ji2_6)
{
FileFindNext(e);
}
else if(e.getSource() ==ji2_10)
{
AllSelect(e);
}
else if (e.getSource() ==ji2_11)
{
FileTime(e);
}
else if(e.getSource()==ji3_1)
{
if(check){
FileLine(e);
}
}
else if(e.getSource()==ji4_1)
{
statu(ji4_1.getState());
}
else if (e.getSource()==jMenuMouseCut)
{
FileCut(e);
}
else if (e.getSource()==jMenuMouseCopy)
{
FileCopy(e);
}
else if (e.getSource()==jMenuMousePaste)
{
FilePaste(e);
}
else if (e.getSource()==jMenuMouseDel)
{
FileDel(e);
}
else if (e.getSource() == jcolor)
{
fcolor(e);
}
}
public void jButtonNew_actionPerformed(ActionEvent e) {
newFile();
}
public void jButtonOpen_actionPerformed(ActionEvent e) {
openFile();
}
public void jButtonSave_actionPerformed(ActionEvent e) {
saveFile();
}
/***定义各种函数,实现各种行为事件*************************************************************/
void notepad() throws Exception{
//新建
ji1_1.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent e){
newFile();
}
});
//打开
// ji1_2.addActionListener( new ActionListener(){
// public void actionPerformed(ActionEvent e)
// {
// FileDialog d=new FileDialog(th , "打开文件" , FileDialog.LOAD );//创建 打开文件对话框这个对象
// d.addWindowListener( new WindowAdapter(){ //关闭文件对话框窗口
// public void windowClosing(WindowEvent ee)
// {
// System.exit(0);
// }
// });
// d.setVisible(true); //文件对话框可见
// File f = new File( d.getDirectory()+d.getFile() ); //建立新文件
// fileName = d.getDirectory()+d.getFile();//得到文件名和路径
// char ch[] = new char [(int)f.length()];///用此文件的长度建立一个字符数组
//
// try//异常处理
// {
// //读出数据,并存入字符数组ch中
// BufferedReader bw = new BufferedReader( new FileReader(f) );
// bw.read(ch); //读取数据
// bw.close();
// }
// catch( FileNotFoundException fe ){
// System.out.println("file not found");
// System.exit(0);
// }
// catch( IOException ie){
// System.out.println("IO error");
// System.exit(0);
// }
// String s =new String (ch); //将读到的数据赋值给s
// jta.setText(s);//设置文本区为所打开文件的内容
// updateFname(); //更新标题栏
// }
// });
// //打开
ji1_2.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
openFile();
}
});
//保存
// ji1_3.addActionListener( new ActionListener(){
// public void actionPerformed(ActionEvent e) {
// if( fileName.equals("") ){ //如果文件没有被保存过,即文件名为空,用equals比较的是内容,用==比较的是内存,用于判断是否指向同一个对象
// FileDialog d = new FileDialog(mainFrame, "保存文件" , FileDialog.SAVE );//创建 保存文件对话框对象
// d.addWindowListener( new WindowAdapter(){ //关闭文件对话框窗口
// public void windowClosing(WindowEvent ee){
// System.exit(0);
// }
// });
// d.setVisible(true);
//
// String s = jta.getText();//得到所输入的文本内容
//
// try//异常处理
// {
// File f = new File( d.getDirectory()+d.getFile());//新建文件
//
// fileName = d.getDirectory()+d.getFile();//得到文件名
//
// BufferedWriter bw = new BufferedWriter( new FileWriter (f));//输入到文件中
// bw.write(s , 0 , s.length());
// bw.close();
// }
// catch(FileNotFoundException fe_){
// System.out.println("file not found");
// System.exit(0);
// }
// catch( IOException ie_)
// {
// System.out.println(" IO error");
// System.exit(0);
// }
// }
// else //如果文件已经保存过
// {
// String s = jta.getText();//得到所输入的文本内容
// try//异常处理
// {
// File f = new File( fileName );//新建文件
// BufferedWriter bw = new BufferedWriter( new FileWriter (f));//输入到文件中
// bw.write(s , 0 , s.length());
// bw.close();
// }
// catch(FileNotFoundException fe_){
// System.out.println("file not found");
// System.exit(0);
// }
// catch( IOException ie_)
// {
// System.out.println(" IO error");
// System.exit(0);
// }
// }
// updateFname();
// }
// });
//保存
ji1_3.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
saveFile();
}
});
//另存为
ji1_4.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent e) {
FileDialog d=new FileDialog(mainFrame , "另存为文件" , FileDialog.SAVE );//创建 另存为文件对话框对象
d.addWindowListener( new WindowAdapter(){ //关闭文件对话框窗口
public void windowClosing(WindowEvent ee){
System.exit(0);
}
});
d.setVisible(true);
String s = jta.getText();//得到所输入的文本内容
try//异常处理
{
File f = new File( d.getDirectory()+d.getFile());//新建文件
fileName = d.getDirectory()+d.getFile();//得到文件名和路径
BufferedWriter bw = new BufferedWriter( new FileWriter (f));//输入到文件中
bw.write(s , 0 , s.length());
bw.close();
}
catch(FileNotFoundException fe_){
System.out.println("file not found");
System.exit(0);
}
catch( IOException ie_)
{
System.out.println(" IO error");
System.exit(0);
}
updateFname();
bsaved = true;
}
});
//关闭
ji1_7.addActionListener( new ActionListener(){ ///退出程序
public void actionPerformed(ActionEvent e){
String s = jta.getText();
if(bsaved == true){
System.exit(0);
}
else if(s.equals("") && fileName.equals("")){
System.exit(0);
}
else if(s.equals(ss)){
System.exit(0);
}
else{
int i = JOptionPane.showConfirmDialog(null, "您的文本内容已经改变,是否保存?");
if(i == 0){
jfc.setCurrentDirectory(new File(""));
int hit = jfc.showSaveDialog(null);
if(hit == 0) {
try {
BufferedWriter bw = new BufferedWriter(new FileWriter(jfc.getSelectedFile().getAbsolutePath()));
String str = jta.getText();
bw.write(str);
bw.close();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e2) {
e2.printStackTrace();
}
System.exit(0);
}
}
else if(i == 1){
System.exit(0);
}
}
}
});
//剪切
ji2_2.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent e){
FileCut(e);
}
});
//复制
ji2_3.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent e){
FileCopy(e);
}
});
//粘贴
ji2_4.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent e){
FilePaste(e);
}
});
//删除
ji2_5.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent e){
FileDel(e);
}
});
//格式
style.addActionListener( new ActionListener(){
public void actionPerformed(ActionEvent e){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -