/** ** Class SportsServer - write a description of the class here ** ** Author: Daryl Moulder ** Date: 19/3/99 **/ import javax.swing.*; import java.io.*; import java.net.ServerSocket; import java.net.Socket; import java.util.Vector; import java.util.Enumeration; import java.util.Date; import java.util.Calendar; import java.text.DateFormat; import java.util.GregorianCalendar; import java.util.Locale; import java.awt.event.*; import java.awt.*; public class SportsServer extends JFrame { // instance variables - private JScrollPane entryScroller; private JScrollPane dispScroller; private static int threadNum = 0; private Socket socket; private Vector threadVect; private JTextArea sportsArea; private JTextArea sportsEntryArea; private JButton acceptBtn; private JButton cancelBtn; private ThreadGroup myGroup; private Date myDate; private Calendar myCal; private DateFormat myFormat; private int portNum; //methods to support form introspection private static String names[] = { "dispScroller","entryScroller","acceptBtn","cancelBtn" }; private String[] getNames() { return names; } private Object[] getWidgets() { Object[] list = new Object[4]; list[0] = dispScroller; list[1] = entryScroller; list[2] = acceptBtn; list[3] = cancelBtn; return list; } public static void main(String[] args) { SportsServer me = new SportsServer("My Frame", 6969); } /** ** Constructor for objects of class SportsServer **/ public SportsServer(String frameName, int aPortNum) { portNum = aPortNum; setTitle(frameName); // initialise instance variables addWindowListener(new WinExit()); myDate = new Date(); myCal = new GregorianCalendar(); myCal.setTime(myDate); GridBagLayout grid = new GridBagLayout(); int rowHeights[] = {0,200,30,30};//0,30,30,30 int columnWidths[] = {0,200,30};//0,30,30 double rowWeights[] = {0.0,0.0,0.0,0.0}; double columnWeights[] = {0.0,0.0,0.0}; grid.rowHeights = rowHeights; grid.columnWidths = columnWidths; grid.rowWeights = rowWeights; grid.columnWeights = columnWeights; sportsArea = new JTextArea(15,20);//15 sportsArea.setEditable(false); dispScroller = new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); dispScroller.getViewport().setView(sportsArea); this.getContentPane().add(dispScroller); sportsEntryArea = new JTextArea(4,20); sportsEntryArea.setEditable(true); entryScroller = new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); entryScroller.getViewport().setView(sportsEntryArea); this.getContentPane().add(entryScroller); acceptBtn = new JButton(); acceptBtn.setText("Accept"); //Uncomment this line acceptBtn.addActionListener(this); this.getContentPane().add(acceptBtn); cancelBtn = new JButton(); cancelBtn.setText("Cancel"); //Uncomment this line cancelBtn.addActionListener(this); this.getContentPane().add(cancelBtn); // Geometry management GridBagConstraints con = new GridBagConstraints(); reset(con); con.gridx = 1; con.gridy = 1; con.gridwidth = 2; con.anchor = GridBagConstraints.CENTER; con.fill = GridBagConstraints.BOTH; grid.setConstraints(dispScroller, con); reset(con); con.gridx = 1; con.gridy = 2; con.gridheight = 2; con.anchor = GridBagConstraints.CENTER; con.fill = GridBagConstraints.NONE; grid.setConstraints(entryScroller, con); reset(con); con.gridx = 2; con.gridy = 2; con.anchor = GridBagConstraints.CENTER; con.fill = GridBagConstraints.NONE; grid.setConstraints(acceptBtn, con); reset(con); con.gridx = 2; con.gridy = 3; con.anchor = GridBagConstraints.CENTER; con.fill = GridBagConstraints.NONE; grid.setConstraints(cancelBtn, con); //pack(); setSize(400,350);//340,350 //repaint(); //setSize(340,360); setVisible(true); // Resize behavior management and parent heirarchy this.getContentPane().setLayout(grid); } private void reset(GridBagConstraints con) { con.gridx = GridBagConstraints.RELATIVE; con.gridy = GridBagConstraints.RELATIVE; con.gridwidth = 1; con.gridheight = 1; con.weightx = 0; con.weighty = 0; con.anchor = GridBagConstraints.CENTER; con.fill = GridBagConstraints.NONE; con.insets = new Insets(0, 0, 0, 0); con.ipadx = 0; con.ipady = 0; } }