/**
Title: DaytimeGUI.java
*Description: Defines a GUI MVC view * for a client for the TCP/IP daytime service
*Copyright: Copyright (c) 2003
* @author Joel C. Adams * @see DaytimeModel.java for its MVC model. * @see DaytimeControllerGUI for its MVC controller. */ import javax.swing.*; // JFrame, JTextField, ... import java.awt.*; // ActionListener, ... import java.awt.event.*; // ActionEvent, ... // DaytimeGUI provides the MVC view... public class DaytimeGUI extends JFrame { private JTextField myHostField; private JTextField myOutputField; private JPanel myHostPanel, myOutputPanel, myMainPanel; public DaytimeGUI(ActionListener controller) { this.setTitle("Daytime Client GUI"); myMainPanel = new JPanel(); myMainPanel.setLayout(new BoxLayout(myMainPanel, BoxLayout.Y_AXIS) ); myMainPanel.add( new JLabel("Enter daytime host/address:", JLabel.LEFT) ); myHostField = new JTextField(); myHostField.addActionListener(controller); myMainPanel.add(myHostField); myMainPanel.add( new JLabel("Host's Response:", JLabel.LEFT) ); myOutputField = new JTextField(32); myOutputField.setEditable(false); myMainPanel.add(myOutputField); this.setContentPane(myMainPanel); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public String getServer() { return myHostField.getText(); } public void display(String str) { myOutputField.setText(str); myHostField.selectAll(); } }