import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
public class Test extends JFrame{
String[] s={"文件一","文件二"};
String[] path={"t1.txt","t2.txt"};
private JTextArea t=new JTextArea();
private JComboBox c=new JComboBox();
private JPanel p=new JPanel();;
private Toolkit k=Toolkit.getDefaultToolkit();
private Dimension screen=k.getScreenSize();
private JScrollPane js=new JScrollPane();
public Test(){
setVisible(true);
setSize(500, 500);
setLocation(screen.width/2-250,screen.height/2-250);
setDefaultCloseOperation(EXIT_ON_CLOSE);
p.setVisible(true);
p.setLayout(new BorderLayout());
add(p);
js.add(t);
js.setVisible(true);
js.setViewportView(t);
for(String ss:s){
c.addItem(ss);
}
p.add(c,BorderLayout.NORTH);
p.add(js,BorderLayout.CENTER);
c.addActionListener(new Action());
}
public static void main(String[] arg){
new Test();
}
class Action implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
t.setText("");
String path1=null;
String item=(String) c.getSelectedItem();
if(item.equals(s[0]))
path1=path[0];
else
path1=path[1];
String temp=null;
try {
BufferedReader br=new BufferedReader(new FileReader(path1));
while((temp=br.readLine())!=null){
t.append(temp+"\n");
}
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
}
}
}