package cuoiki;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.sql.Connection;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
import java.sql.DriverManager;
import java.sql.Statement;
/**
*
* @author Tonqt Thonq
*/
public class Bai1 extends JFrame {
JTextField file_name;
JButton load;
TextArea data;
public static void main(String[] args) {
new Bai1();
}
public Bai1(){
this.setTitle("Bai 1");
this.setBounds(400,500,400,400);
this.setLayout(null);
file_name = new JTextField(10);
file_name.setBounds(10, 10, 250, 30);
this.add(file_name);
load = new JButton("Load data");
load.setBounds(270, 10, 100, 30);
this.add(load);
data = new TextArea();
data.setBounds(10, 40, 370, 320);
data.setEditable(false);
this.add(data);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setVisible(true);
addLtn();
}
private void addLtn() {
load.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String fn = file_name.getText().toString();
String readdata = new String("");
try{
File f = new File(fn);
FileInputStream fis = new FileInputStream(f);
BufferedReader bf = new BufferedReader(new InputStreamReader(fis));
String temp;
while((temp = bf.readLine())!=null) readdata+=(temp+"\n");
data.setText(readdata);
} catch(Exception emsg){
data.setText(emsg.toString());
}
}});
}
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.