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(); } }
}
在线等!
解决方案 »
- MysqlDataTruncation: Data truncation: Truncated incorrect DOUBLE value: '8,10,11
- struts2中这样的 ’href‘ 怎么让action带参?
- 取url请求后想得到所参数和值的准确方法?
- 为什么现在开发网站不用JSP开发?(用最多的是ASP和PHP)
- 大家早上好.请大哥大姐帮帮忙
- 哪里有jsp的主页空间啊?? 收费的也可以
- 为什么我一用lomboz插件, eclipse就卡得要死????有高手赐教没?注:请不要建议小弟用其它的插件
- JDK1.5下面的RMI怎么用的啊,现在好象不要stub那些东西了,知道的进来下吧
- 是关于页面返回的问题。简单,也不简单;难,也不难!
- Weblogic EJBQL 问题?
- 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}