java图形界面怎样将文本文件里的数据输入到文本框和将文本框中的数据输入到文本文件 急求解在线等可加分
importjava.awt.HeadlessException;importjava.awt.event.ActionEvent;importjava.awt.even...
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import com.action.JframBank;
/**
* 查询界面
*
* @author Administrator
*
*/
public class BTN1 extends JFrame {
private JButton btn1, btn2;
private JTextField t1;
private JPanel b1 = new JPanel();
private JframBank jfb = null;
public BTN1(String arg0) throws HeadlessException {
super(arg0);
setSize(300, 200);
t1=new JTextField(15);
b1.setName("查询");
btn1 = new JButton("查询余额");
btn1.addActionListener(new B());
btn2 = new JButton("退出");
btn2.addActionListener(new B());
b1.add(btn1);
b1.add(btn2);
b1.add(t1);
setContentPane(b1);
this.setVisible(true);
}
public JTextField getT1() {
return t1;
}
class B implements ActionListener {
public void actionPerformed(ActionEvent arg0) {
Object o = arg0.getSource();
if (o == btn1) {
Query query = new Query();
query.query(jfb);
}
if (o == btn2) {
jfb.setVisible(true);
}
}
}
}
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.swing.JTextField;
/**
* 查询
* @author Administrator
*
*/
public class Query {
private JframBank jframBank;
private JTextField jTextField;
public void query(JframBank jframBank){
this.jframBank=jframBank;
// FileReader fin=null;
try {
// fin=new FileReader("D:/1.txt");
BufferedReader Ia=new BufferedReader(new InputStreamReader(new FileInputStream("D:/1.txt")));
try {
String a=Ia.readLine();
Ia.close();
jTextField=jframBank.getBt1().getT1();
jTextField.setText(a);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} 展开
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import com.action.JframBank;
/**
* 查询界面
*
* @author Administrator
*
*/
public class BTN1 extends JFrame {
private JButton btn1, btn2;
private JTextField t1;
private JPanel b1 = new JPanel();
private JframBank jfb = null;
public BTN1(String arg0) throws HeadlessException {
super(arg0);
setSize(300, 200);
t1=new JTextField(15);
b1.setName("查询");
btn1 = new JButton("查询余额");
btn1.addActionListener(new B());
btn2 = new JButton("退出");
btn2.addActionListener(new B());
b1.add(btn1);
b1.add(btn2);
b1.add(t1);
setContentPane(b1);
this.setVisible(true);
}
public JTextField getT1() {
return t1;
}
class B implements ActionListener {
public void actionPerformed(ActionEvent arg0) {
Object o = arg0.getSource();
if (o == btn1) {
Query query = new Query();
query.query(jfb);
}
if (o == btn2) {
jfb.setVisible(true);
}
}
}
}
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.swing.JTextField;
/**
* 查询
* @author Administrator
*
*/
public class Query {
private JframBank jframBank;
private JTextField jTextField;
public void query(JframBank jframBank){
this.jframBank=jframBank;
// FileReader fin=null;
try {
// fin=new FileReader("D:/1.txt");
BufferedReader Ia=new BufferedReader(new InputStreamReader(new FileInputStream("D:/1.txt")));
try {
String a=Ia.readLine();
Ia.close();
jTextField=jframBank.getBt1().getT1();
jTextField.setText(a);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询