import java.awt.*; import java.awt.event.*; public class UIExample { Frame f; //a frame to hold our components TextField tf; //a text field to display messages and allow for user input Button b; //a button to generate events public UIExample() { f = new Frame(); //create a new frame f.setLayout(new FlowLayout()); //make the layout of the frame a flowlayout tf = new TextField(50); //create a textfield with 50 columns b = new Button("Get MotD"); //create a button with text "Get MotD" //add an actionlistener that will take action when the button is pushed //pass it the text field so that the listener can get the text out of the textfield //and take appropriate action b.addActionListener(new GetListener(tf)); f.add(tf); //add the text field to the frame f.add(b); //add the button to the frame f.setSize(450, 300); //set the size of the frame //add the windowlistener that will exit the program when the user closes the window f.addWindowListener(new WindowAdapter() { // This method is called after a window is closed public void windowClosing(WindowEvent evt) { System.exit(0); } }); f.show(); //show the frame with the components } //all programs must have a main //this main simply creates a new UIExample object public static void main(String[] args) { new UIExample(); } }