我正在尝试将正则表达式解析的txt文件中的所有输出记录添加到一个JOptionPane窗口。我创建了一个要捕获的字符串,但我继续打印单个窗口。有任何想法吗?感谢
while ((line = br.readLine()) != null) {
if (Pattern.matches(titlePattern, line)) {
String name = "", price="";
String patternName = "title=\".*?(\")";
Pattern r = Pattern.compile(patternName);
Matcher m = r.matcher(line);
if (m.find( )) {
name = m.group(0);
//System.out.println("Title: " + name.substring(7, name.length()-1));
}
String patternPrice = "Suggested Retail Price:.*?\"";
String strOutput;
r = Pattern.compile(patternPrice);
m = r.matcher(line);
if (m.find( )) {
price = m.group(0);
//System.out.println("Title: " + name.substring(7, name.length()-1) + ", " + price.substring(0, price.length()-1));
//JOptionPane.showMessageDialog(null, "Title: " + name.substring(7, name.length()-1) + ", " + price.substring(0, price.length()-1));
final_list.addElement("Title: " + name.substring(7, name.length()-1) + ", " + price.substring(0, price.length()-1));
strOutput = "Title: " + name.substring(7, name.length()-1) + ", " + price.substring(0, price.length()-1);
JOptionPane.showMessageDialog(null, strOutput);
}
}
}
答案 0 :(得分:0)
尝试使用java.swing.TextArea
构建消息,并JOptionPane
显示消息。这是简短的演示:
public static void main(String[] args) {
TextArea textView = new TextArea();
textView.append("dsddd");
textView.append("jsdjsd");
textView.append("qwoqwo");
JOptionPane.showMessageDialog(null, textView);
}