[ictk-cvs] ictk/samples/simpleICSClient CommandInput.java,NONE,1.1 SimpleICSClient.java,1.2,1.3 Simp
chess library in java, PGN, FEN, ICS
Brought to you by:
jvarsoke
|
From: <jva...@us...> - 2003-08-29 08:42:25
|
Update of /cvsroot/ictk/ictk/samples/simpleICSClient In directory sc8-pr-cvs1:/tmp/cvs-serv27976/samples/simpleICSClient Modified Files: SimpleICSClient.java Added Files: CommandInput.java Removed Files: SimpleICSClient.form Log Message: Seperated out the GUI from SimpleICSClient so it is more apparent how things are set up. Added CommandInput. Client GUI is now AWT -- better response to typing. Also improving the Router --- NEW FILE: CommandInput.java --- /* * ICTK - Internet Chess ToolKit * More information is available at http://ictk.sourceforge.net * Copyright (C) 2002 J. Varsoke <jva...@gh...> * All rights reserved. * * $Id: CommandInput.java,v 1.1 2003/08/29 08:42:21 jvarsoke Exp $ * * This file is part of ICTK. * * ICTK is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * ICTK is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with ICTK; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* CommandInput ***********************************************************/ /** * This is a no frills Command input window. * @author jvarsoke */ import java.awt.*; import java.awt.event.*; import ictk.boardgame.chess.net.ics.ICSProtocolHandler; public class CommandInput extends Frame implements ActionListener { TextField tfCommand; ICSProtocolHandler ics; /** Creates new form JCommandInput */ public CommandInput(String title, ICSProtocolHandler ics) { super(title); this.ics = ics; initComponents(); } /** This method is called from within the constructor to * initialize the form. */ private void initComponents() { tfCommand = new TextField(); tfCommand.addActionListener(this); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { ics.disconnect(); System.exit(0); } }); tfCommand.setFont(new Font("Lucida Sans Typewriter", 0, 12)); tfCommand.addActionListener(this); add(tfCommand, BorderLayout.CENTER); pack(); java.awt.Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setSize(new java.awt.Dimension(500, 18)); //setLocation((screenSize.width-500)/2,(screenSize.height-18)/2); setLocation(27,(screenSize.height-60)); } public void actionPerformed (ActionEvent evt) { ics.sendCommand(tfCommand.getText()); tfCommand.setText(""); } } Index: SimpleICSClient.java =================================================================== RCS file: /cvsroot/ictk/ictk/samples/simpleICSClient/SimpleICSClient.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SimpleICSClient.java 20 Aug 2003 14:10:17 -0000 1.2 --- SimpleICSClient.java 29 Aug 2003 08:42:21 -0000 1.3 *************** *** 24,33 **** */ - /* - * SimpleICSClient.java - * - * Created on March 12, 2002, 10:43 PM - */ - /* SimpleICSClient ***********************************************************/ /** --- 24,27 ---- *************** *** 39,107 **** * @author jvarsoke */ - public class SimpleICSClient extends javax.swing.JFrame implements java.awt.event.ActionListener { ! static java.lang.String handle; ! static java.lang.String passwd; ! ictk.boardgame.chess.net.ics.fics.FICSProtocolHandler fics; ! ictk.boardgame.chess.net.ics.ui.cli.ANSIConsole ansiConsole; /** Creates new form SimpleICSClient */ ! public SimpleICSClient() { ! initComponents(); ! fics = new ictk.boardgame.chess.net.ics.fics.FICSProtocolHandler(); ! ansiConsole = new ictk.boardgame.chess.net.ics.ui.cli.ANSIConsole(); ! fics.getRouter().setDefaultRoute(ansiConsole); ! connect(null); } ! /** This method is called from within the constructor to ! * initialize the form. ! * WARNING: Do NOT modify this code. The content of this method is ! * always regenerated by the Form Editor. ! */ ! private void initComponents() {//GEN-BEGIN:initComponents ! tfCommand = new javax.swing.JTextField(); ! bConnect = new javax.swing.JButton(); ! ! setTitle("ICTK Sample ICS Client"); ! addWindowListener(new java.awt.event.WindowAdapter() { ! public void windowClosing(java.awt.event.WindowEvent evt) { ! exitForm(evt); ! } ! }); ! ! tfCommand.setFont(new java.awt.Font("Lucida Sans Typewriter", 0, 12)); ! tfCommand.addActionListener(new java.awt.event.ActionListener() { ! public void actionPerformed(java.awt.event.ActionEvent evt) { ! commandPerformed(evt); ! } ! }); ! ! getContentPane().add(tfCommand, java.awt.BorderLayout.CENTER); ! ! bConnect.setText("Connect"); ! bConnect.addActionListener(new java.awt.event.ActionListener() { ! public void actionPerformed(java.awt.event.ActionEvent evt) { ! connect(evt); ! } ! }); ! ! getContentPane().add(bConnect, java.awt.BorderLayout.EAST); ! ! pack(); ! java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); ! setSize(new java.awt.Dimension(500, 18)); ! //setLocation((screenSize.width-500)/2,(screenSize.height-18)/2); ! setLocation(27,(screenSize.height-60)); ! }//GEN-END:initComponents ! ! private void connect(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_connect // Add your handling code here: ! if (!fics.isConnected()) try { ! System.out.println("Client: attempting to connect"); fics.setHandle(handle); fics.setPassword(passwd); --- 33,65 ---- * @author jvarsoke */ ! import ictk.boardgame.chess.net.ics.ui.cli.ANSIConsole; ! import ictk.boardgame.chess.net.ics.fics.FICSProtocolHandler; ! public class SimpleICSClient { ! String handle; ! String passwd; ! ! FICSProtocolHandler fics; ! ANSIConsole ansiConsole; ! CommandInput commandLine; /** Creates new form SimpleICSClient */ ! public SimpleICSClient(String handle, String passwd) { ! this.handle = handle; ! this.passwd = passwd; ! fics = new FICSProtocolHandler(); ! ansiConsole = new ANSIConsole(); ! fics.getEventRouter().setDefaultListener(ansiConsole); ! commandLine = new CommandInput("Simple ICS Client", fics); } ! public void connect() { // Add your handling code here: ! if (!fics.isConnected()) { try { ! System.out.println("[Client] attempting to connect"); fics.setHandle(handle); fics.setPassword(passwd); *************** *** 115,137 **** e.printStackTrace(); } ! else ! fics.disconnect(); ! }//GEN-LAST:event_connect ! ! private void conntection(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_conntection ! // Add your handling code here: ! ! }//GEN-LAST:event_conntection ! ! private void commandPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_commandPerformed ! // Add your handling code here: ! fics.sendCommand(tfCommand.getText()); ! tfCommand.setText(""); ! }//GEN-LAST:event_commandPerformed ! /** Exit the Application */ ! private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm ! System.exit(0); ! }//GEN-LAST:event_exitForm /** --- 73,82 ---- e.printStackTrace(); } ! } ! } ! public void setVisible (boolean t) { ! commandLine.setVisible(t); ! } /** *************** *** 139,158 **** */ public static void main(String args[]) { if (args.length < 2) { ! System.err.println("must supply username and password"); System.exit(1); } ! handle = args[0]; ! passwd = args[1]; ! new SimpleICSClient().show(); } - - public void actionPerformed(java.awt.event.ActionEvent actionEvent) { - } - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JTextField tfCommand; - private javax.swing.JButton bConnect; - // End of variables declaration//GEN-END:variables - } --- 84,95 ---- */ public static void main(String args[]) { + SimpleICSClient client = null; if (args.length < 2) { ! System.err.println("You must supply username and password"); System.exit(1); } ! client = new SimpleICSClient(args[0], args[1]); ! client.setVisible(true); ! client.connect(); } } --- SimpleICSClient.form DELETED --- |