import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TextEditTest { public static void main(String[] args) {
TextEditFrame frame=new TextEditFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}
class TextEditFrame extends JFrame
{
public TextEditFrame()
{
setTitle("TextEdit");
setSize(300,300);
Container contenterPane=getContentPane();
JPanel panel=new JPanel();
textArea=new JTextArea(10,20);
JScrollPane scrollPane=new JScrollPane(textArea);
panel.add(scrollPane);
contenterPane.add(panel,BorderLayout.CENTER);
JPanel panell=new JPanel();
replace=new JButton("replace");
label=new JLabel("with");
textfield1=new JTextField(5);
to=new JTextField(5);
panell.add(replace);
panell.add(textfield1);
panell.add(label);
panell.add(to);
replace.addActionListener(new RAction());
contenterPane.add(panell,BorderLayout.SOUTH);
}
JButton replace;
JLabel label;
JTextField textfield1;
JTextField to;
JTextArea textArea;
private class RAction implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
String f=textfield1.getText();
int n=textArea.getText().indexOf(f);
int i;
for(i=0;i<=f.length();i++)
{
textArea.replaceRange(to.getText(),n,n+f.length());
}
}
}
}
提示: 可序列化的类 TextEditFrame 未声明类型为 long 的静态终态 serialVersionUID 字段程序可以正常运行,请问这是怎么回事啊,我应该修改哪里呢?
import java.awt.event.*;
import javax.swing.*;
public class TextEditTest { public static void main(String[] args) {
TextEditFrame frame=new TextEditFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}
class TextEditFrame extends JFrame
{
public TextEditFrame()
{
setTitle("TextEdit");
setSize(300,300);
Container contenterPane=getContentPane();
JPanel panel=new JPanel();
textArea=new JTextArea(10,20);
JScrollPane scrollPane=new JScrollPane(textArea);
panel.add(scrollPane);
contenterPane.add(panel,BorderLayout.CENTER);
JPanel panell=new JPanel();
replace=new JButton("replace");
label=new JLabel("with");
textfield1=new JTextField(5);
to=new JTextField(5);
panell.add(replace);
panell.add(textfield1);
panell.add(label);
panell.add(to);
replace.addActionListener(new RAction());
contenterPane.add(panell,BorderLayout.SOUTH);
}
JButton replace;
JLabel label;
JTextField textfield1;
JTextField to;
JTextArea textArea;
private class RAction implements ActionListener
{
public void actionPerformed(ActionEvent event)
{
String f=textfield1.getText();
int n=textArea.getText().indexOf(f);
int i;
for(i=0;i<=f.length();i++)
{
textArea.replaceRange(to.getText(),n,n+f.length());
}
}
}
}
提示: 可序列化的类 TextEditFrame 未声明类型为 long 的静态终态 serialVersionUID 字段程序可以正常运行,请问这是怎么回事啊,我应该修改哪里呢?
解决方案 »
- 求高手解答
- 请问java随机读取txt中的几个人名
- 关于java用hibernate调用数据库的问题。
- java中的TimerTask用法
- java多线程,运行后机子越来越慢,如何解决
- 向达人求函数:关于汉字GBK,ASCII,二进制,十六进制的
- 如何js中调用VBA?实现多个word文档的合并?
- ArrayList 的问题
- ***MSSQL7的jdbc驱动上哪能下载到?在线等***
- 哭~!!!!再做不完我就死定了 怎样用 “javascript” 实现 “动态删除 上传组件” 求源代码
- 怎么改变JButton中文字的颜色?
- 请教:两个类文件,如何在一个类中改变另外一个类的对象属性?如改变对方jLabel3的文字。
上面的错误只是警告,并无大碍
javac在编译的时候会帮你自动加上一个serialVersionUID,但是如果有一边被重新编译过的话,你就要出错了。(两边的serialVersionUID很可能就不一样了)