具体不大清楚,好象先建立一个模式,当然模式中包含要匹配的字符串,之后调用
该模式的match方法,该方法有一个参数就是你的计事本中的字符串。
该模式的match方法,该方法有一个参数就是你的计事本中的字符串。
解决方案 »
- 我的代码有什么错误,为什么报java.lang.String cannot be cast to java.util.Vector
- 发段有意思的代码共同学习下
- 如何进行数组和字符窜的对比,“==”和"equals"好象不行呀,还是怎么使用?
- 请大家多指教
- 编写程序,将两个有序链表合并成一个有序的链表,请大家帮忙分析
- 紧急!!如何使rs.getFloat().toString()在获取很大decimal类型字段时返回正常的字符显示,而不是科学计数方式??
- 现在JAVA主要用来干什么?(内同)
- 如何获得系统支持字体?
- 除了RealPlayer8之外,有什么软件可以运行SMIL。
- 哪位大神能帮忙解释一下这段代码吗,我知道这个程序的功能,但是每行代码的作用我不知道,能每行注释说明一下吗,详细解说一下吗?跪谢!
- sos,如何制作W2K的启动盘,十分重要,谢谢
- 请看这段程序如何运行?
JDialog ds = new JDialog(this, "Find", true);
ds.getContentPane().setLayout(new FlowLayout());
ds.setResizable(false);
final JLabel dsMessage1 = new JLabel(" Found counts: ");
final JLabel dsMessage2 = new JLabel(" 0");
final Checkbox dsLoop = new Checkbox("Loop ");
dsLoop.setState(findingLoop);
final Checkbox dsMatchCase = new Checkbox("Match Case ");
final TextField tfs = new TextField(15);
ds.getContentPane().add(tfs);
tfs.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int a = 0, b = 0;
String str1, str2, str3, str4, strA, strB;
str1 = ta.getText();
str2 = str1.toLowerCase();
str3 = tfs.getText();
str4 = str3.toLowerCase();
if(dsMatchCase.getState()) {
strA = str1;
strB = str3;
}
else {
strA = str2;
strB = str4;
}
a = strA.indexOf(strB, FindStartPos);
if(a > -1) {
ta.setCaretPosition(a);
b = tfs.getText().length();
ta.select(a, a + b);
FindStartPos = a + b;
foundCount++;
dsMessage2.setText(foundCount + "");
}
else {
if(dsLoop.getState()) {
JOptionPane.showMessageDialog(null, "End of file.", "Find result", JOptionPane.INFORMATION_MESSAGE);
FindStartPos = 0;
}
else {
JOptionPane.showMessageDialog(null, "End of file.", "Find result", JOptionPane.INFORMATION_MESSAGE);
}
foundCount = 0;
}
}
});
Button bs = new Button(" Find ");
//same as tfs.addActionListener(new ActionListener() {
bs.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int a = 0, b = 0;
String str1, str2, str3, str4, strA, strB;
str1 = ta.getText();
str2 = str1.toLowerCase();
str3 = tfs.getText();
str4 = str3.toLowerCase();
if(dsMatchCase.getState()) {
strA = str1;
strB = str3;
}
else {
strA = str2;
strB = str4;
}
a = strA.indexOf(strB, FindStartPos);
if(a > -1) {
ta.setCaretPosition(a);
b = tfs.getText().length();
ta.select(a, a + b);
FindStartPos = a + b;
foundCount++;
dsMessage2.setText(foundCount + "");
}
else {
if(dsLoop.getState()) {
JOptionPane.showMessageDialog(null, "End of file.", "Find result", JOptionPane.INFORMATION_MESSAGE);
FindStartPos = 0;
}
else {
JOptionPane.showMessageDialog(null, "End of file.", "Find result", JOptionPane.INFORMATION_MESSAGE);
}
foundCount = 0;
}
}
});
Button bsc = new Button("Cancel");
bsc.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dispose();
foundCount = 0;
}
});
ds.getContentPane().add(bs);
ds.getContentPane().add(bsc);
ds.getContentPane().add(dsLoop);
ds.getContentPane().add(dsMatchCase);
ds.getContentPane().add(dsMessage1);
ds.getContentPane().add(dsMessage2);
ds.setLocation(120, 120);
ds.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
FindStartPos = 0;
}
});
ds.setSize(260,110);
ds.setVisible(true);
}