package ch.epfl.lca.sc250.gui; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Toolkit; import java.text.DateFormat; import java.text.SimpleDateFormat; import javax.swing.JFrame; /** * This class is the Super Class of CnFrameUDP and CnFrameTCP. * @author Christophe Trefois * */ public class CnFrame extends JFrame { /** * Generated serialID by Eclipse */ private static final long serialVersionUID = -5235044694247669643L; public CnFrame() { } /** * Custom Constructor. <br> * Sets the Window title to windowTitle <br> * @param windowTitle The Title provided as String */ public CnFrame (String windowTitle) { this.setTitle(windowTitle); frameConstructor(); } /** * Construct the main Frame. */ private void frameConstructor() { // Set Behaviour when "x" is clicked. setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); // Get Screen Dimensions Dimension windowSize = Toolkit.getDefaultToolkit().getScreenSize(); setBounds(50, 50, windowSize.width / 2, windowSize.height / 2); getContentPane().setLayout(new BorderLayout()); } /** * Retrieves the current time in the following format: dd/MMM/yyyy HH:mm:ss * @return The String representation of the current Date */ public String getCurrentTime() { DateFormat dateFormat = new SimpleDateFormat("dd / MMMM / yyyy -- HH:mm:ss"); java.util.Date date = new java.util.Date(); return dateFormat.format(date); } }