SERVER GUI

Class sint provides the user interface at the server side. Swingset 0.2 has been used for coding purposes. JFC is employed to give the required interface. JFrame is used to have a basic window. JFrame is initialized with appropriate title, background colours and the layout manager. AWT helps our application to place the components and the preffered sizes by means of the layout manager. The JFC components: JTextArea, JTextField, JLabels, JButton are added to this frame. A WindowListener is also added to the frame(window). It uses the WindowAdapter to implement the window interface. The window closing event is handled by this interface. Multiple threads concurrently write on the text area. At any given instance it may reflect the files being pulled, the number of clients attached, the files undergoing the formatting operations, insertion of the advertisements, the file database or the files being pushed on to the clients. The first textfield is initialized to show the URL or the location where to connect. The second one holds the reference string "spor". The button "OK" when clicked starts the InetClient thread.

// filename : sint.java import java.io.*; import java.awt.*; import java.awt.event.*; import com.sun.java.swing.*; public class sint extends JPanel { static String urlname; static String refstr; static JFrame frame; static JTextArea txt; static JTextField txtf; static JLabel label; static JTextField txtf1; static JLabel label1; static JButton butt; public sint() { super(true); label = new JLabel("Enter URL: "); label.setBackground(Color.black); label.setForeground(Color.white); add(label); txtf = new JTextField("www.timesofindia.com:80/today/pagespor.htm",30); txtf.setEditable(true); TextFieldListener myListener = new TextFieldListener(); txtf.addActionListener(myListener); add(txtf); label1 = new JLabel("Enter Ref String : "); label1.setBackground(Color.black); label1.setForeground(Color.white); add(label1); txtf1 = new JTextField("spor",7); txtf1.setEditable(true); TextFieldListener1 myListener1 = new TextFieldListener1(); txtf1.addActionListener(myListener1); add(txtf1); butt = new JButton("Ok"); ButtonListener mybuttListener = new ButtonListener(); butt.addActionListener(mybuttListener); add(butt); txt = new JTextArea(" ",25,55,2);//don't modify txt.setBackground(Color.white); txt.setEditable(false); Font f = new Font("Dialog",Font.BOLD,12); txt.setFont(f); add(txt); } public static void main(String s[]) { WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) {System.exit(0);} }; frame = new JFrame("Intranet Server"); frame.addWindowListener(l); frame.setBackground(Color.black); //=>new Color(0,0,0); frame.setLayout(new BorderLayout()); frame.add("Center", new sint()); frame.pack(); //important step otherwise screenful of errors frame.setSize(640, 450); frame.setVisible(true); //or frame.show(); works fine sint.txtf.setEditable(true); sint.txtf1.setEditable(false); sint.butt.setEnabled(true); } public static void print(String str) { txt.append(str); } }//end class sint class TextFieldListener implements ActionListener { public void actionPerformed(ActionEvent e) { sint.urlname = sint.txtf.getText(); sint.urlname = sint.urlname.trim(); sint.txtf.setEditable(false); sint.txtf1.setEditable(true); }//end action performed }//end class listener class TextFieldListener1 implements ActionListener { public void actionPerformed(ActionEvent e) { sint.refstr = sint.txtf1.getText(); sint.refstr = sint.refstr.trim(); sint.txtf1.setEditable(false); }//end action performed }//end class listener class ButtonListener implements ActionListener { public void actionPerformed(ActionEvent e) { sint.refstr = sint.txtf1.getText(); sint.refstr = sint.refstr.trim(); sint.butt.setEnabled(false); InetClient inet = new InetClient(); try { inet.start(); } catch(Exception t){ } sint.txtf.setEditable(false); sint.txtf1.setEditable(false); }//end action performed }//end class listener

next >>

Index