Newer
Older
nonet / src / ch / epfl / lca / sc250 / gui / CnFrameTCP.java
@Andreas Jaggi Andreas Jaggi on 17 May 2006 1 KB Finished TP7, started work on TP8
package ch.epfl.lca.sc250.gui;

import java.awt.BorderLayout;
import java.awt.GridLayout;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

/**
 * This Class dispalys messages received from the Server. E.g. Server Hello etc... <br>
 * Call appendText(String) to update the GUI
 * 
 * @author Christophe Trefois
 */
public class CnFrameTCP extends CnFrame {

	/**
	 * Generated serialID by Eclipse
	 */
	private static final long serialVersionUID = 4899514760671051872L;
	
	/**
	 * The TextArea used to display the messages
	 */
	private JTextArea textArea;
	
	/**
	 * Constructs a CnFrameTCP Instance with title windowTitle
	 * @param windowTitle
	 */
	public CnFrameTCP(String windowTitle) {
		super(windowTitle);
		setSize(500, 250);
		
		JPanel centerPanel = new JPanel();
		
		textArea = new JTextArea();
		textArea.setEditable(false);
		
		JScrollPane scrollPane = new JScrollPane(textArea);
		
		centerPanel.setLayout(new GridLayout(1, 1));
		centerPanel.add(scrollPane);
		
		// put the centerPanel to the Center 
		getContentPane().add(centerPanel, BorderLayout.CENTER);
		
		// Make this frame visible
		setVisible(true);
	}
	
	/**
	 * Append Text to the textArea
	 * @param textToAppend
	 */
	public void appendText(String textToAppend) {
			textArea.append(super.getCurrentTime() + " : " + textToAppend);
			textArea.setCaretPosition(textArea.getText().length());
		}
		
		/**
		 * Clear the TextArea.
		 *
		 */
		public void clearTextArea() {
			textArea.replaceRange("", 0, textArea.getText().length());
		}
}