package Chap13;import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;public class TxtBrowser extends JFrame implements ActionListener {
JTextField jtf1;
JTextArea jta1;
Scanner scaner; public TxtBrowser() { JButton jb1 = new JButton("View");
jb1.addActionListener(this); Container container = this.getContentPane();
setTitle("文本浏览器");
setSize(600, 500);
JPanel jp1 = new JPanel();
jp1.setLayout(new GridLayout(1, 3, 10, 10));
JLabel jlb1 = new JLabel("Filename:");
jtf1 = new JTextField();
jp1.add(jlb1);
jp1.add(jtf1);
jp1.add(jb1);
container.add(jp1, BorderLayout.SOUTH);
jta1 = new JTextArea();
JScrollPane jsp1 = new JScrollPane(jta1);
container.add(jsp1, BorderLayout.CENTER); } public static void main(String[] args) {
TxtBrowser tbr1 = new TxtBrowser();
tbr1.setVisible(true); } public void actionPerformed(ActionEvent e) { File file = new File(jtf1.getText()); try {
scaner = new Scanner(file);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
System.out.println(jtf1.getText());
} // TODO Auto-generated catch block String str1 = null;
while (scaner.hasNextLine()) {
str1 += scaner.nextLine(); jta1.setText(str1);
scaner.close(); } }
}
在线等!
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;public class TxtBrowser extends JFrame implements ActionListener {
JTextField jtf1;
JTextArea jta1;
Scanner scaner; public TxtBrowser() { JButton jb1 = new JButton("View");
jb1.addActionListener(this); Container container = this.getContentPane();
setTitle("文本浏览器");
setSize(600, 500);
JPanel jp1 = new JPanel();
jp1.setLayout(new GridLayout(1, 3, 10, 10));
JLabel jlb1 = new JLabel("Filename:");
jtf1 = new JTextField();
jp1.add(jlb1);
jp1.add(jtf1);
jp1.add(jb1);
container.add(jp1, BorderLayout.SOUTH);
jta1 = new JTextArea();
JScrollPane jsp1 = new JScrollPane(jta1);
container.add(jsp1, BorderLayout.CENTER); } public static void main(String[] args) {
TxtBrowser tbr1 = new TxtBrowser();
tbr1.setVisible(true); } public void actionPerformed(ActionEvent e) { File file = new File(jtf1.getText()); try {
scaner = new Scanner(file);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
System.out.println(jtf1.getText());
} // TODO Auto-generated catch block String str1 = null;
while (scaner.hasNextLine()) {
str1 += scaner.nextLine(); jta1.setText(str1);
scaner.close(); } }
}
在线等!
解决方案 »
- 请教SSH登陆验证方案
- >java.io.IOException: Server returned HTTP response code: 400 for URL: http://localhost:8888/Archives/webservice/incept.asmx
- 我的伟大想法
- 一个让我找了一上午的SQL语句小错误,但不知为什么,请高手们说说看。
- hibernate 创建表问题~~~~~~
- 一个Weblogic域可以同时布暑两个Web应用吗?顶者有分!
- 你们好,我刚刚开始学jsp。以后请大家多多帮忙。
- 用weblogic + J2EE的数据库连接问题,高手帮忙
- Jdbc连接access oracle数据的问题??
- java.util.concurrent.TimeoutException: Idle timeout expired: 30000/30000 ms
- hibernate 外键对应多个表
- 征求建议:在tomcat上的web应用和java应用之间的双向数据交互方式
package Chap13;import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;public class TxtBrowser extends JFrame implements ActionListener {
JTextField jtf1;
JTextArea jta1;
Scanner scaner; public TxtBrowser() { JButton jb1 = new JButton("View");
jb1.addActionListener(this); Container container = this.getContentPane();
setTitle("文本浏览器");
setSize(600, 500);
JPanel jp1 = new JPanel();
jp1.setLayout(new GridLayout(1, 3, 10, 10));
JLabel jlb1 = new JLabel("Filename:");
jtf1 = new JTextField();
jp1.add(jlb1);
jp1.add(jtf1);
jp1.add(jb1);
container.add(jp1, BorderLayout.SOUTH);
jta1 = new JTextArea();
JScrollPane jsp1 = new JScrollPane(jta1);
container.add(jsp1, BorderLayout.CENTER); } public static void main(String[] args) {
TxtBrowser tbr1 = new TxtBrowser();
tbr1.setVisible(true);
} public void actionPerformed(ActionEvent e) { File file = new File(jtf1.getText()); try {
scaner = new Scanner(file);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
System.out.println(jtf1.getText());
} // TODO Auto-generated catch block String str1 = null;
while (scaner.hasNextLine()) {
str1 += scaner.nextLine(); jta1.setText(str1);
}
scaner.close();
}
}
只不过在scanner关闭之后继续使用会报IllegalStateExceptionAttempting to perform search operations after a scanner has
been closed will result in an {@link IllegalStateException}