简易记事本java源代码 记事本怎么编写java( 八 )


Transferable content = clipboard.getContents(this);
try {
if (content.getTransferData(DataFlavor.stringFlavor) instanceof String) {
b = true;
}
} catch (Exception e) {
}
return b;
}
/**
* 文本组件中是否具备复制的条件
*
* @return true为具备
*/
public boolean isCanCopy() {
boolean b = false;
int start = this.getSelectionStart();
int end = this.getSelectionEnd();
if (start != end)
b = true;
return b;
}
public void mouseClicked(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON3) {
copy.setEnabled(isCanCopy());
paste.setEnabled(isClipboardString());
cut.setEnabled(isCanCopy());
pop.show(this, e.getX(), e.getY());
}
}
public void mouseReleased(MouseEvent e) {
}
}
求一个用Java编写的简易笔记本代码 。跪求import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.*;
public class MyNotepad implements ActionListener
{
private JFrame frame=new JFrame("新记事本");
private JTextArea jta=new JTextArea();
private String result="";
private boolean flag=true;
private File f;
private JButton jb=new JButton("开始");
private JTextField jtf=new JTextField(15);
private JTextField jt=new JTextField(15);
private JButton jbt=new JButton("替换为");
private JButton jba=new JButton("全部替换");
private Icon ic=new ImageIcon("D:\\java课堂笔记\\GUI\\11.gif");
private String value;
private int start=0;
private JFrame jf=new JFrame("查找");
private JFrame jfc=new JFrame("替换");
@Override
public void actionPerformed(ActionEvent e)
{
String comm=e.getActionCommand();
if("新建".equals(comm))
{
if(!(frame.getTitle().equals("新记事本")))
{
if(!flag)
{
write();
newNew();
}
else
{
JFileChooser jfc=new JFileChooser("D:\\java课堂笔记");
int returnVal = jfc.showDialog(null,"保存为");
if(returnVal == JFileChooser.APPROVE_OPTION)
{//选择文件后再执行下面的语句,保证了程序的健壮性
f=jfc.getSelectedFile();
flag=false;
write();
}
}
}
else if(!(jta.getText().isEmpty()))
{
JFileChooser jfc=new JFileChooser("D:\\java课堂笔记");
int returnVal = jfc.showDialog(null,"保存为");
if(returnVal == JFileChooser.APPROVE_OPTION)
{//选择文件后再执行下面的语句,保证了程序的健壮性
f=jfc.getSelectedFile();
flag=false;
write();
newNew();
}
}
else
{
newNew();
}
}
else if("打开".equals(comm))
{
JFileChooser jfc=new JFileChooser("D:\\java课堂笔记");
jfc.setDialogType(JFileChooser.OPEN_DIALOG);
int returnVal = jfc.showOpenDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION)
{//选择文件后再执行下面的语句,保证了程序的健壮性
f=jfc.getSelectedFile();
frame.setTitle(f.getName());
result=read();
flag=false;
value=https://www.04ip.com/post/result;
jta.setText(result);
}
}else if("保存".equals(comm))
{
JFileChooser jfc=new JFileChooser("D:\\java课堂笔记");
if(flag)
{
int returnVal = jfc.showDialog(null,"保存为");
if(returnVal == JFileChooser.APPROVE_OPTION)
{//选择文件后再执行下面的语句,保证了程序的健壮性
f=jfc.getSelectedFile();
flag=false;
write();
}
}
else

推荐阅读