请教各位大神,我在public MyJFrame()方法里打印ArrayList q;为什么什么也没有,是为什么呢,困扰了好几天了。。。
import java.awt.*;
import java.awt.event.*;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import javax.swing.*;
public class YeLunshuju {
public static void main(String[] args) throws IOException {
MyJFrame mjf = new MyJFrame();
}
}
class MyJFrame extends JFrame{
ArrayList q = new ArrayList();
String[] a1;
JFrame jf= new JFrame();
JTextArea ja = new JTextArea();
FileDialog f;
JTextField j1 = new JTextField();
public MyJFrame() throws IOException{
JPanel p1 = new JPanel();
j1 = new JTextField(20);
JLabel l1 = new JLabel("选择数据所在位置:");
JButton b1 = new JButton("浏览");
MouL m = new MouL();
b1.addMouseListener(m);
System.out.println(q);
p1.setLayout(new FlowLayout());
p1.add(l1);p1.add(j1);p1.add(b1);
jf.add(p1,BorderLayout.NORTH);
jf.setTitle("叶轮数据计算");
jf.setBounds(300, 300, 500, 500);
jf.setVisible(true);
}
class MouL extends MouseAdapter{
public void mouseClicked(MouseEvent e) {
try {
ReadFile();
} catch (IOException e1) {
e1.printStackTrace();
}
}
public void ReadFile( ) throws IOException{
f = new FileDialog(jf," ",FileDialog.LOAD);
f.setVisible(true);
FileReader in = new FileReader(f.getDirectory()+f.getFile());
BufferedReader bf = new BufferedReader(in);
String line = bf.readLine();
while(line != null){
System.out.println(line);
if(line.startsWith("X1=")){
String[] a = line.split("=");
a1 = a[1].split(",");
for(int i=0;i<a1.length;i++){
q.add(a1[i]);
}
}
if(line.startsWith("Y1=")){
String[] a = line.split("=");
a1 = a[1].split(",");
for(int i=0;i<a1.length;i++){
q.add(a1[i]);
}
}
line = bf.readLine();
}
j1.setText(f.getDirectory()+f.getFile());
}
}
}
------解决思路----------------------
ArrayList q = new ArrayList();
你new了之后,就打印了,内容当然为空