Client GUI

The client interface offers actual access to customised information. The client application communicates with the server in order to initiate the push operation where the push is the actual datatransfer operation carried out between the client and the server. The JFC components: JTextArea, JTextField, JLabel, JButtons, JProgressBars are placed in a JFrame.

The actionlistener of the "Connect" button makes an instance of the thread clienttest and starts it.

// filename: cint.java import java.awt.*; import java.awt.event.*; import com.sun.java.swing.*; public class cint extends JPanel { static String surlname; static JLabel label; static JTextField txtf; static int attempts = 0; static JFrame frame; static String connect = new String("connect"); static String stop = new String("stop"); static JButton button; static JButton sbutton; static JTextArea txt; static JProgressBar pb; static JProgressBar pb1; public cint( ) { super(true); label = new JLabel("Server : "); label.setBackground(Color.black); label.setForeground(Color.white); add(label); txtf = new JTextField("127.0.0.1",20); txtf.setEditable(true); TextFieldListener myListener1 = new TextFieldListener( ); txtf.addActionListener(myListener1); add(txtf); txt = new JTextArea(" ",20,50,2); txt.setBackground(Color.white); txt.setEditable(false); Font f = new Font("Dialog",Font.BOLD,12); txt.setFont(f); add(txt); button = new JButton("Connect... "); sbutton = new JButton("Stop"); button.setForeground(Color.blue); sbutton.setForeground(Color.blue); button.setToolTipText("Connects to Server for downloading Sports files"); sbutton.setToolTipText("Disconnects Client "); button.setKeyAccelerator('C'); sbutton.setKeyAccelerator('S'); button.setActionCommand(connect); sbutton.setActionCommand(stop); ButtonListener myListener = new ButtonListener( ); button.addActionListener(myListener); sbutton.addActionListener(myListener); pb = new JProgressBar( ); pb1 = new JProgressBar( ); pb.setMinimum(0); pb1.setMinimum(0); pb.setValue(-1); pb1.setValue(-1); //pb.setMaximum(100); add(pb); add(pb1); add(button); add(sbutton); } public static void main(String s[ ]) { WindowListener l = new WindowAdapter( ) { public void windowClosing(WindowEvent e) {System.exit(0);} }; frame = new JFrame("Intranet Client !!!"); frame.addWindowListener(l); frame.setBackground(Color.black); //=>new Color(0,0,0); 0,255,255 for cyan frame.setLayout(new BorderLayout( )); frame.add("Center", new cint( )); frame.pack( ); //important step otherwise screenful of errors frame.setSize(640, 420); frame.setVisible(true); //or frame.show( ); works fine cint.sbutton.setEnabled(false); cint.button.setEnabled(false); } public static void addlabel( ) { JLabel uu = new JLabel("\n\n\t\t SERVER BUSY !\n\n\t Try out after sometime."); frame.add(uu); uu.setBounds(0,0,50,50); frame.pack( ); } public static void print(String str) { txt.append(str); } }//end class cint class ButtonListener extends Frame implements ActionListener { ClientTest xxx ; public void actionPerformed(ActionEvent e) { String factoryName = null; if(e.getActionCommand( ) == cint.connect) { cint.attempts++; if (cint.attempts <= 4) { cint.pb.setValue(-1); cint.pb1.setValue(-1); cint.button.setEnabled(false); cint.sbutton.setEnabled(true); cint.print("\n\nConnecting to Server ... Attempt "+cint.attempts); xxx = new ClientTest( ); xxx.start( ); //ClientTest.runclient( ); } else { cint.button.setEnabled(false); cint.sbutton.setEnabled(true); cint.print("\n Restart Client "); if(cint.attempts>7) { dispose( ); System.exit(0); } } }// end action command if(e.getActionCommand( ) == cint.stop) { xxx.stop( ); //stop the ClientTest.runclient( ); cint.button.setEnabled(true); cint.sbutton.setEnabled(false); //System.exit(0); dispose( ); } }//end action performed }//end class listener class TextFieldListener implements ActionListener { public void actionPerformed(ActionEvent e) { cint.surlname = cint.txtf.getText( ); cint.surlname = cint.surlname.trim( ); cint.txtf.setEditable(false); cint.button.setEnabled(true); }//end action performed }//end class listener

next >>

Index