//************************************************************* //Java application //「TextLoadTest」 // //          作 成 者:ルート高菜    //          作成開始月:2006/6 //          最終更新月:2006/6 [TN089/J79] //************************************************************* import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.*; public class TextLoadTest extends JFrame implements ActionListener { //Eclipseの場合、シリアライズ可能クラスでこれがないと警告が出る private static final long serialVersionUID=0; // public static void main(String[] args) { TextLoadTest frame=new TextLoadTest(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //右上×印で終了 frame.setVisible(true); frame.setLocationRelativeTo(null); //画面の真ん中に表示 } // JTextArea area=new JTextArea(); // JButton inJar=new JButton("in Jar"); JButton outJar=new JButton("out Jar"); //コンストラクタ public TextLoadTest(){ // setTitle("TextLoadTest"); setSize(300,300); // JScrollPane scPanel=new JScrollPane(area); // JPanel panel=new JPanel(); panel.add(inJar); panel.add(outJar); //コンテナ枠 Container cp=getContentPane(); cp.add(scPanel,BorderLayout.CENTER); cp.add(panel,BorderLayout.SOUTH); // inJar.addActionListener(this); outJar.addActionListener(this); } //ボタンイベント public void actionPerformed(ActionEvent e) { String line; if(e.getSource()==inJar){ try{ //jar内のテキストファイルの入力ストリームを得る InputStream is=getClass().getResourceAsStream("injar.txt"); //Stream(古い系統)からReader(新しい系統)へ変換する BufferedReader br=new BufferedReader(new InputStreamReader(is)); area.setText(""); while((line=br.readLine())!=null){ area.append(line+"\n"); } br.close(); }catch(IOException exc){ area.setText(exc.getMessage()); } }else if(e.getSource()==outJar){ try{ //ローカルでの絶対パスからテキストファイルを開く String dir=System.getProperty("user.dir")+File.separator; BufferedReader br=new BufferedReader(new FileReader(dir+"outjar.txt")); area.setText(""); while((line=br.readLine())!=null){ area.append(line+"\n"); } br.close(); }catch(IOException exc){ area.setText(exc.getMessage()); } } } }