import java.io.*; import java.awt.*; import java.awt.event.*; class HelloYou3 extends Frame { /* A program that prompts for your name then says hello to you personally in a separate window. Closing the window ends the program. */ static String name; public HelloYou3() { } public static void main(String[] args) throws IOException { HelloYou3 f = new HelloYou3(); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Please type your name: "); name=in.readLine(); f.setBackground(Color.magenta); f.setTitle("Graphics demonstration"); f.addWindowListener(new HelloWindowCloser(name)); f.setSize(400,150); f.setVisible(true); System.out.println("\nIf you are in Linux: Close the magenta"); System.out.println("window by clicking on the box in the top"); System.out.println("left-hand corner and choosing Close from"); System.out.println("the menu\n"); } public void paint(Graphics g) { g.setColor(Color.white); g.setFont(new Font("SansSerif",Font.BOLD,20)); g.drawString("Hello "+name,50,90); } } class HelloWindowCloser extends WindowAdapter { String name; HelloWindowCloser(String nm) { name=nm; } public void windowClosing(WindowEvent e) { System.out.println("Goodbye "+name); System.exit(0); } }