import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.nio.file.Path;
import java.nio.file.Files;

public class hello extends JFrame {


  public hello (String [] args) {
    getContentPane().setLayout(new BorderLayout());
    String s = "Hello Java";

    if (args != null) {
        s += " args: ";
        for (String a : args) {
            s += a + ", ";
        }
    }
    JLabel helloLabel = new JLabel(s);
    helloLabel.setHorizontalAlignment(SwingConstants.CENTER);
    getContentPane().add(helloLabel, BorderLayout.NORTH);
    s = "Java version: " + System.getProperty("java.version");
    JLabel verLabel = new JLabel(s);
    verLabel.setHorizontalAlignment(SwingConstants.CENTER);
    getContentPane().add(verLabel, BorderLayout.CENTER);

    JButton goodbye = new JButton("and Goodbye");
    getContentPane().add(goodbye, BorderLayout.SOUTH);
    goodbye.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
	    System.exit(0);
	}
    });  

  }
  public static void main (String[] args) {
    hello frame  = new hello(args);
    frame.setBounds(20,20,200,200);
    frame.setVisible(true);
System.out.println("---- this is for --win-console test");

    frame.addWindowListener ( new WindowAdapter() {
            public void windowClosing( WindowEvent e ) {
                System.exit(0);
            }
        });
    Path outFile = Path.of("test-output.txt");
    ArrayList<String> lines = new ArrayList<String>();
    lines.add("args.length = " + args.length);
    for (String arg : args) {
        lines.add("arg: " + arg);
    }
    try {
        Files.write(outFile, lines);
    } catch (Exception e) {
        e.printStackTrace();
    }
  }

}
