Table of Contents

  • How to use awt


How to use awt


Sample code


import java.awt.*;
import java.awt.event.*;
import java.io.*;


public class DispWindow extends Frame {

   public DispWindow() {
       addWindowListener(
           new WindowAdapter() {
               public void windowClosing(WindowEvent e)  {
                   System.exit(0);
               }
           });
   }

   public static void main(String[] args) {
       DispWindow dispWin = new DispWindow();
       dispWin.setTitle("FRAME title");
       dispWin.setSize(200, 100);
       dispWin.setLocation(200, 100);
       dispWin.setVisible(true);




       try {
           BufferedReader bufReader = new BufferedReader(new FileReader("/home/masami/Desktop/hudson.txt"));
           String textBuf = "";
           String line = "";
           while ((line = bufReader.readLine()) != null) {
               textBuf = textBuf + "\n" + line;
           }

           TextArea textArea = new TextArea(textBuf);
           dispWin.add(textArea);
           textArea.setVisible(true);

           bufReader.close();
       } catch (IOException ex) {
           System.out.println(ex);
       }
   }
}





最終更新:2020年10月03日 02:01