?? myframe.java
字號:
if(filedialog_save.getFile()!=null)
{
System.out.println("if"+openname);
String name;
try
{
this.setTitle(filedialog_save.getFile()+" Notepad");
fileWriter=new FileWriter(new File(filedialog_save.getDirectory(),filedialog_save.getFile()));
out=new BufferedWriter(fileWriter);
name=text.getText();
out.write(name,0,name.length());
out.flush();
out.close();
fileWriter.close();
System.out.println("已經執行");
Issave=1;
}
catch(IOException e2)
{
}
}
}
else
{
Issave=1;
System.out.println("else"+openname);
if(openname!=null)
{
String name=openname;
try
{
this.setTitle(name+" Notepad");
fileWriter=new FileWriter(new File(opendir,openname));
out=new BufferedWriter(fileWriter);
System.out.println("運行中");
name=text.getText();
out.write(name,0,name.length());
out.flush();
out.close();
fileWriter.close();
System.out.println("已經執行");
Issave=1;
}
catch(IOException e2)
{
}
}
}
}
if(e.getSource()==saveasFile)
{
filedialog_saveas.setVisible(true);
Issave=1;
}
if(e.getSource()==exitFile)
{
if(text.getText().equals(new String("")))
{
System.exit(0);
}
if(Issave==1 && text.getText()!=null)
{
System.exit(0);
}
if(Issave==0 && text.getText()!=null)
{
int n=JOptionPane.showConfirmDialog(this,"文件內容已改變,需要保存文件嗎?","確認對話框",JOptionPane.YES_NO_CANCEL_OPTION);
if(n==JOptionPane.YES_OPTION)
{
filedialog_save.setVisible(true);
if(filedialog_save.getFile()!=null)
{
String name;
try
{
fileWriter=new FileWriter(new File(filedialog_save.getDirectory(),filedialog_save.getFile()));
out=new BufferedWriter(fileWriter);
name=text.getText();
out.write(name,0,name.length());
out.flush();
out.close();
fileWriter.close();
Issave=1;
}
catch(IOException e2)
{
}
}
}
if(n==JOptionPane.NO_OPTION)
{
System.exit(0);
}
else
{
filedialog_save.setVisible(false);
}
}
}
if(e.getSource()==removeEdit)
{
remove();
}
if(e.getSource()==copyEdit)
{
copy();
}
if(e.getSource()==pasteEdit)
{
paste();
}
if(e.getSource()==cutEdit)
{
cut();
}
if(e.getSource()==findEdit)
{
FindFrame findframe=new FindFrame();
}
if(e.getSource()==replaceEdit)
{
ReplaceFrame replaceframe=new ReplaceFrame();
}
if(e.getSource()==selectallEdit)
{
selectall();
}
if(e.getSource()==deleteEdit)
{
delete();
}
if(e.getSource()==fontFormat)
{
Font f=new Font("宋體",Font.PLAIN,20);
FontPanel.exampleText.setFont(f);
fontdialog.setVisible(true);
}
if(e.getSource()==aboutHelp)
{
imagedialog.setVisible(true);
}
if(e.getSource()==popRemove)
{
remove();
}
if(e.getSource()==popCopy)
{
copy();
}
if(e.getSource()==popPaste)
{
paste();
}
if(e.getSource()==popCut)
{
cut();
}
if(e.getSource()==popDelete)
{
delete();
}
if(e.getSource()==popSelectall)
{
selectall();
}
if(e.getSource()==popDelete)
{
delete();
}
}
public void keyPressed(KeyEvent me)
{
if(me.getKeyCode()==KeyEvent.VK_SPACE || me.getKeyCode()==KeyEvent.VK_ENTER||me.getKeyCode()==KeyEvent.VK_BACK_SPACE||me.getKeyCode()==KeyEvent.VK_CLEAR||me.getKeyCode()==KeyEvent.VK_CANCEL)
{
stack.push(new String(text.getText()));
}
}
public void keyTyped(KeyEvent me1)
{
}
public void keyReleased(KeyEvent me2)
{
}
public void mousePressed(MouseEvent e)
{
if(e.getModifiers()==InputEvent.BUTTON3_MASK)
{
try
{
System.out.println("run");
popupmenu.show(text,e.getX(),e.getY());
}
catch(Exception ee)
{
}
}
}
public void mouseReleased(MouseEvent e)
{
}
public void mouseEntered(MouseEvent e)
{
}
public void mouseExited(MouseEvent e)
{
}
public void mouseClicked(MouseEvent e)
{
}
public void remove()
{
if(!(stack.empty()))
{
String s=(String)stack.pop();
text.setText(s);
}
else
{
text.setText("");
}
}
public void copy()
{
String temp=text.getSelectedText();
StringSelection mytext=new StringSelection(temp);
clipboard.setContents(mytext,null);
}
public void paste()
{
Transferable contents=clipboard.getContents(this);
DataFlavor flavor=DataFlavor.stringFlavor;
if(contents.isDataFlavorSupported(flavor))
{
try
{
String str;
str=(String)contents.getTransferData(flavor);
text.append(str);
}
catch(Exception ee)
{
}
}
}
public void cut()
{
String temp=text.getSelectedText();
StringSelection mytext=new StringSelection(temp);
clipboard.setContents(mytext,null);
int start=text.getSelectionStart();
int end=text.getSelectionEnd();
text.replaceRange("",start,end);
}
public void selectall()
{
text.setSelectionStart(0);
try
{
text.setSelectionEnd(text.getLineEndOffset(text.getRows()-1));
}
catch(Exception e2)
{
}
}
public void delete()
{
MyFrame.text.setText("");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -