Simple TicTacToe Program

Hi,
I'm taking an introductory Java class, and I'm just trying to complete an assignment in my textbook. Here is a copy of the code that I'm having a problem with:
import java.util.Scanner;
public class TicTacToeClient
     public static void main( String [] args )
          Scanner scan = new Scanner( System.in );
          TicTacToe ttt1 = new TicTacToe( );
          String garbage;
          int player = 1;
          boolean gameOver = false;
          int position;
          while ( ! gameOver )
               System.out.print( "Please enter a position, player " + player + " > " );
               while( ! scan.hasNextInt( ) )
                    garbage = scan.nextLine( );
                    System.out.print( "Please enter a valid position, player " + player + " > " );
               position = scan.nextInt( );
               if ( ! ttt1.isLegal( position ) )
                    System.out.println( "This position is already used!" );
               else
                    ttt1.makeMove( player, position );
                    if ( ttt1.gameWon( player ) || ttt1.isTie( ) )
                         gameOver = true;
                    else
                         if ( player == 1 )
                              player = 2;
                         else
                              player = 1;
          ttt1.printWinner( player );
I'm very sorry if the format of this code is hard to read, as the message textbox is pretty small.
Anyhow, when I enter 0 for player 1, and then an invalid character for player 2 ( such as 'j' ), I get the "Please enter a valid value ..." message twice in a row. I thought that the scan.hasNextInt( ) condition in the while loop would wait for the user to press Enter before repeating the loop. Why does this happen and how can I correct it?
Thanks in advance for your help.
Message was edited by:
invinciBill

Thanks for the link.
This should be easier to read:
import java.util.Scanner;
public class TicTacToeClient
     public static void main( String [] args )
          Scanner scan = new Scanner( System.in );
          TicTacToe ttt1 = new TicTacToe( );
          String garbage;
          int player = 1;
          boolean gameOver = false;
          int position;
          while ( ! gameOver )
               System.out.print( "Please enter a position, player " + player + " > " );
               while( ! scan.hasNextInt( ) )
                    garbage = scan.nextLine( );
                    System.out.print( "Please enter a valid position, player " + player + " > " );
               position = scan.nextInt( );
               if ( ! ttt1.isLegal( position ) )
                    System.out.println( "This position is already used!" );
               else
                    ttt1.makeMove( player, position );
                    if ( ttt1.gameWon( player ) || ttt1.isTie( ) )
                         gameOver = true;
                    else
                         if ( player == 1 )
                              player = 2;
                         else
                              player = 1;
          ttt1.printWinner( player );
}

Similar Messages

  • "Assertion failed" error when executing a simple UCI program

    I am using a simple UCI program (tt1.c) with Xmath version 7.0.1 on Sloaris 2.8 that performs the followings:
    - Start Xmath701
    - Sleep 10 Seconds
    - Load a sysbuild model
    - Stop Xmath
    I am calling the uci executable using the following command:
    > /usr/local/apps/matrixx-7.0.1/bin/xmath -call tt1 &
    In this way everything works fine and the following printouts from the program are produced.
    --------- uci printout ----------
    ## Starting Xmath 701
    ## sleep 10 seconds
    ## load "case_h_cs_ds.xmd";
    ## Stopping Xmath 701
    All the processes (tt1, XMATH, xmath_mon, and sysbld) terminate correctly.
    The problem occurs if the 10 second wait after starting xmath is omitted:
    - Start Xmath701
    - Load a sysbuild model
    - Stop Xmath
    This results to the following printouts:
    --------- uci printout ----------
    ## Starting Xmath 701
    ## load "case_h_cs_ds.xmd";
    Assertion failed: file "/vob1/xm/ipc/ipc.cxx", line 420 errno 0.
    Note that the last line is not produced by the uci program and the tt1 did not
    finish (the printout before stopping xmath "## Stopping Xmath 701" was
    not produced).
    A call to the unix "ps -ef" utility shows that none of the related process has been terminated:
    fs085312 27631 20243 0 10:45:29 pts/27 0:00 tt1
    fs085312 27643 1 0 10:45:30 ? 0:00 /usr/local/apps/matrixx-7.0.1/solaris_mx_70.1/xmath/bin/xmath_mon /usr/local/app
    fs085312 27641 27631 0 10:45:30 ? 0:01 /usr/local/apps/matrixx-7.0.1/solaris_mx_70.1/xmath/bin/XMATH 142606339, 0x8800
    fs085312 25473 25446 0 10:45:33 ? 0:01 sysbld ++ 19 4 7 6 5 8 9 0 25446 ++
    The questions are as follows:
    1- What is "Assertion failed: file "/vob1/xm/ipc/ipc.cxx", line 420 errno 0" and why is that produced?
    2- Should the UCI program waits for end of sysbld initialization before issuing commands?
    3- If the answer to the above question is yes, is there a way to check the termination of sysbld initialization?
    Thanks in advance for you help.
    Attachments:
    tt1.c ‏1 KB

    I tracked down the problem and it is a race condition between the many processes being started up. A smaller delay should also solve the problem. Or, maybe do something else before the first 'load'. The 'load' command tries to launch systembuild and causes the race condition.

  • Weblogic error while deplying a simple servlet program

    Hi This is a very simple servlet program.
    I am trying to deploy it on the weblogic server but i get this error as follow
    Unable to access the selected application.
    *javax.enterprise.deploy.spi.exceptions.InvalidModuleException: [J2EE Deployment SPI:260105]Failed to create*
    DDBeanRoot for application, 'E:\AqanTech\WebApp1\myApp.war'.
    I have checked everything, right from my code to my web.xml file. I have used a build.bat file to build my war file.
    PLEASE HELP ME TO SOLVE THIS HUGE PROBLEM OF MINE ?
    Thanks,
    Shoeb

    Hi,
    The J2EE Error code siply suggest that there is something wrong in your Deployment Descriptors...
    Can u please post the XML files available inside your "WEB-INF" directory?
    Thanks
    Jay SenSharma
    http://jaysensharma.wordpress.com (WebLogic Wonders Are Here)

  • I'm not able to run a simple Hello Program in java

    I have just now installed jdk 1.3.1_2.
    I have set the path and class path.
    I'm able to compile the class without any errors but am not able to run the program.
    when i say java Hello(after compiling Hello.java), i'm seeing the following error:
    Exception in thread "main" java.lang.NoclassDefFoundError:Hello
    Thanks in advance in this regard

    Hmm..
    Okay.. set aside any import or package stuffs.. lets say about a simple HelloWorld program which is called Hello.class. It resides in c:\, which means the full path is c:\Hello.class.
    Make sure you got one of your path as c:\jdk1.3\bin(assuming you are using jdk 1.3).
    If you are in the same directory as Hello.class, which is c:\>, you can execute the class file by typing:
    C:\>java Hello
    If you are not in the same directory and you wishes to run the class file, example you are in directory temp now:
    C:\Temp>java -cp C:\ Hello
    So the cp set will be just c:\. Hope that answers your question somehow.. well... if I never intepret it wrongly.

  • Problem while executing simple java program

    Hi
    while trying to execute a simple java program,i am getting the following exception...
    please help me in this
    java program :import java.util.*;
    import java.util.logging.*;
    public class Jump implements Runnable{
        Hashtable activeQueues = new Hashtable();
        String dbURL, dbuser, dbpasswd, loggerDir;   
        int idleSleep;
        static Logger logger = Logger.getAnonymousLogger();      
        Thread myThread = null;
        JumpQueueManager manager = null;
        private final static String VERSION = "2.92";
          public Jump(String jdbcURL, String user, String pwd, int idleSleep, String logDir) {
            dbURL = jdbcURL;
            dbuser = user;
            dbpasswd = pwd;
            this.idleSleep = idleSleep;
            manager = new JumpQueueManager(dbURL, dbuser, dbpasswd);
            loggerDir = logDir;
            //preparing logger
            prepareLogger();
          private void prepareLogger(){      
            Handler hndl = new pl.com.sony.utils.SimpleLoggerHandler();
            try{
                String logFilePattern = loggerDir + java.io.File.separator + "jumplog%g.log";
                Handler filehndl = new java.util.logging.FileHandler(logFilePattern, JumpConstants.MAX_LOG_SIZE, JumpConstants.MAX_LOG_FILE_NUM);
                filehndl.setEncoding("UTF-8");
                filehndl.setLevel(Level.INFO);
                logger.addHandler(filehndl);
            catch(Exception e){
            logger.setLevel(Level.ALL);
            logger.setUseParentHandlers(false);
            logger.addHandler(hndl);
            logger.setLevel(Level.FINE);
            logger.info("LOGGING FACILITY IS READY !");
          private void processTask(QueueTask task){
            JumpProcessor proc = JumpProcessorGenerator.getProcessor(task);       
            if(proc==null){
                logger.severe("Unknown task type: " + task.getType());           
                return;
            proc.setJumpThread(myThread);
            proc.setLogger(logger);       
            proc.setJumpRef(this);
            task.setProcStart(new java.util.Date());
            setExecution(task, true);       
            new Thread(proc).start();       
         private void processQueue(){       
            //Endles loop for processing tasks from queue       
            QueueTask task = null;
            while(true){
                    try{
                        //null argument means: take first free, no matters which queue
                        do{
                            task = manager.getTask(activeQueues);
                            if(task!=null)
                                processTask(task);               
                        while(task!=null);
                    catch(Exception e){
                        logger.severe(e.getMessage());
                logger.fine("-------->Sleeping for " + idleSleep + " minutes...hzzzzzz (Active queues:"+ activeQueues.size()+")");
                try{
                    if(!myThread.interrupted())
                        myThread.sleep(60*1000*idleSleep);
                catch(InterruptedException e){
                    logger.fine("-------->Wakeing up !!!");
            }//while       
        public void setMyThread(Thread t){
            myThread = t;
        /** This method is only used to start Jump as a separate thread this is
         *usefull to allow jump to access its own thread to sleep wait and synchronize
         *If you just start ProcessQueue from main method it is not possible to
         *use methods like Thread.sleep becouse object is not owner of current thread.
        public void run() {
            processQueue();
        /** This is just another facade to hide database access from another classes*/
        public void updateOraTaskStatus(QueueTask task, boolean success){
            try{         
                manager.updateOraTaskStatus(task, success);
            catch(Exception e){
                logger.severe("Cannot update status of task table for task:" + task.getID() +  "\nReason: " + e.getMessage());       
        /** This is facade to JumpQueueManager method with same name to hide
         *existance of database and SQLExceptions from processor classes
         *Processor class calls this method to execute stored proc and it doesn't
         *take care about any SQL related issues including exceptions
        public void executeStoredProc(String proc) throws Exception{
            try{
                manager.executeStoredProc(proc);
            catch(Exception e){
                //logger.severe("Cannot execute stored procedure:"+ proc + "\nReason: " + e.getMessage());       
                throw e;
         *This method is only to hide QueueManager object from access from JumpProcessors
         *It handles exceptions and datbase connecting/disconnecting and is called from
         *JumpProceesor thread.
        public  void updateTaskStatus(int taskID, int status){       
            try{
                manager.updateTaskStatus(taskID, status);
            catch(Exception e){
                logger.severe("Cannot update status of task: " + taskID + " to " + status + "\nReason: " + e.getMessage());
        public java.sql.Connection getDBConnection(){
            try{
                return manager.getNewConnection();
            catch(Exception e){
                logger.severe("Cannot acquire new database connection: " + e.getMessage());
                return null;
        protected synchronized void setExecution(QueueTask task, boolean active){
            if(active){
                activeQueues.put(new Integer(task.getQueueNum()), JumpConstants.TH_STAT_BUSY);
            else{
                activeQueues.remove(new Integer(task.getQueueNum()));
        public static void main(String[] args){
                 try{
             System.out.println("The length-->"+args.length);
            System.out.println("It's " + new java.util.Date() + " now, have a good time.");
            if(args.length<5){
                System.out.println("More parameters needed:");
                System.out.println("1 - JDBC strign, 2 - DB User, 3 - DB Password, 4 - sleeping time (minutes), 5 - log file dir");
                return;
            Jump jump = new Jump(args[0], args[1], args[2], Integer.parseInt(args[3]), args[4]);
            Thread t1= new Thread(jump);
            jump.setMyThread(t1);      
            t1.start();}
                 catch(Exception e){
                      e.printStackTrace();
    } The exception i am getting is
    java.lang.NoClassDefFoundError: jdbc:oracle:thin:@localhost:1521:xe
    Exception in thread "main" ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2
    JDWP exit error AGENT_ERROR_NO_JNI_ENV(183):  [../../../src/share/back/util.c:820] Please help me.....
    Thanks in advance.....sathya

    I am not willing to wade through the code, but this portion makes me conjecture your using an Oracle connect string instead of a class name.
    java.lang.NoClassDefFoundError: jdbc:oracle:thin:@localhost:1521:xe

  • Error in simple oops program

    Hi experts,
    When executing a simple oops program ..i got the following error. Please correct the code.
    "VAR" is not type-compatible with formal parameter "I_DATA".          
          CLASS main DEFINITION
    CLASS main DEFINITION.
      PUBLIC SECTION.
        "// Instance Methods ( Note we use the statement 'METHODS'
        "// to define an instance method )
        METHODS set_data IMPORTING i_data TYPE string.
        METHODS get_data RETURNING value(r_data) TYPE string.
        METHODS print_attribute IMPORTING i_data TYPE string.
        "// Instance Methods ( Note we use the statement 'CLASS-METHODS'
        "// to define a static method )
        CLASS-METHODS set_classdata IMPORTING i_data TYPE string.
        CLASS-METHODS get_classdata RETURNING value(r_data) TYPE string.
        CLASS-METHODS print_classattribute IMPORTING i_data TYPE string.
      PROTECTED SECTION.
        "// Instance Attribute ( Note we use the statement 'DATA'
        "// to define an instance attribute )
        DATA attribute TYPE string.
        "// Static Attribute ( Note we use the statement 'CLASS-DATA'
        "// to define a static attribute )
        CLASS-DATA classattribute TYPE string.
      PRIVATE SECTION.
        "// Instace event ( Note we use the statement 'EVENTS'
        "// to define aN instance event )
        EVENTS event EXPORTING value(e_data) TYPE string.
        "// Instace event ( Note we use the statement 'CLASS-EVENTS'
        "// to define a static event )
        CLASS-EVENTS classevent EXPORTING value(e_data) TYPE string.
        "// For more informations about events see the following example:
        "// ABAP Objects - Creating your First Local Class - Using Events
    ENDCLASS.                    "main DEFINITION
          CLASS main IMPLEMENTATION
    CLASS main IMPLEMENTATION.
      METHOD set_data.
        CONCATENATE 'Instance Attribute value' i_data
                                   INTO attribute SEPARATED BY space.
      ENDMETHOD.                    "set_data
      METHOD get_data.
        MOVE attribute TO r_data.
      ENDMETHOD.                    "get_data
      METHOD set_classdata.
        CONCATENATE 'Static Attribute value' i_data
                                   INTO classattribute SEPARATED BY space.
      ENDMETHOD.                    "set_classdata
      METHOD get_classdata.
        MOVE main=>classattribute TO r_data.
      ENDMETHOD.                    "get_classdata
      METHOD print_attribute.
        WRITE: i_data, /.
      ENDMETHOD.                    "print_attribute
      METHOD print_classattribute.
        WRITE: i_data, /.
      ENDMETHOD.                    "print_classattribute
    ENDCLASS.                    "main IMPLEMENTATION
    DATA: var type char20.
    START-OF-SELECTION.
      "// Calling a Static method (note we don't have a object )
      "// instead we use the <class name>=><method name>.
      main=>set_classdata( 'SDN' ).
      var = main=>get_classdata( ).
      "// Print the var value
      main=>print_classattribute( var ).
      DATA: object_reference TYPE REF TO main.
      CREATE OBJECT object_reference.
      "// - Calling a Instance Method( Note we have to use a object to
      "// access the insntace components of class main )
      "// - Note we're using the statment "CALL METHOD", see looking for
      "// functional & General methods for more informations
      CALL METHOD object_reference->set_data( 'BPX' ).
      var = object_reference->get_data(  ).
      object_reference->print_attribute( var ).
    Thanks in Advance.
    Regards
    Nani

    Hi Nani,
    try changing your data definition for var from CHAR20 to STRING.
    regards,
    Peter

  • I need ready code for a simple paint program today

    hi all I need ready code for a simple paint program today for me ics projct
    plz give me a halp on this give me what you have with you and it is so good if it look like this :
    Design a GUI based drawing Java application that works like a simple paint program
    1-There should be a number of buttons for choosing different shapes to draw. For example, there should be a button for rectangle. If user presses the rectangle button, then he can draw a rectangle using mouse. Similarly, there should be a button for each shape(rectangle, circle, ellipse, and line etc.
    2-The shapes can be filled with different colors.
    3-There should be option of moving .
    4- There should also be three menus including File, Shape, and Color menu.
    i. File menu can have menu items New and Exit. If user selects New, the drawing area will be cleared and all shapes will be erased.
    ii. Shape menu will serve the same purpose as of feature 2 described above. It will have menu items for drawing all the different shapes. For example, there will be menu item for rectangle; so user can draw a rectangle by selecting the menu item for rectangle.
    iii. Color menu will serve the same purpose as of feature 3 described above. It will have menu items for all the colors which are shown in color buttons. The user can select a color from this menu and then click inside a shape to fill it with the selected color.

    Read the Swing tutorial. There are sections on how to use menus and painting and all other kinds of stuff you need to do this homework assignment. Nobody here is going to write the code for you:
    http://java.sun.com/docs/books/tutorial/uiswing/TOC.html

  • PARSE_APPLICATION_DATA Error during XML = ABAP conversion: Response Message; CX_ST_DESERIALIZATION_ERROR in /1SAI/SAS0446CC11CC6EC1AD4789 Line 24 An error occurred when deserializing in the simple transformation program /1SAI/SAS0446CC11CC6EC1AD4789

    Hi Experts ,
    i have a scenario proxy to soap  where i am getting error while getting the response .
    we are sending the request successfully and getting response .some times we are getting in proxy level error below
    PARSE_APPLICATION_DATA Error during XML => ABAP conversion: Response Message; CX_ST_DESERIALIZATION_ERROR in /1SAI/SAS0446CC11CC6EC1AD4789 Line 24 An error occurred when deserializing in the simple transformation program /1SAI/SAS0446CC11CC6EC1AD4789 (Cha
    Please help us to fix this bug in proxy response.
    Regards
    Ravi

    Hello Ravinder,
    Can you please post the complete stack trace, it seems to be some fields are getting truncated i,e data sent from the program to the proxy object might be violating some length restrictions.
    Please check your message interface field lengths and what is being passed to the proxy.
    Regards,
    Ravi.

  • How to use simple abap program O/P using bsp.

    Hi All,
    I want to know simple BSP program which will call normal abap program. It has to display simple output not in table format.
    Thanks,

    Check the tutorials mentioned in the Wiki. Read the documentation. It is all simple.
    Cheers
    Graham Robbo

  • Need help on with simple email program

    i have been set a task to create a simple email program that has the variables of the sender the recipient the subject the content and a date object representing when the email was sent (this is just to be set to the current system date)
    It also needs to include a constructor with four String arguments, i.e the sender, receiver, subject and content. The constructor has to initialise the date of the email then transfer the values of the input parameters to the relevant attributes. If any values of the strings aren'nt given, the string �Unknown� should be set as the value.
    I was given a java file to test the one i am to create, but some of the values are not given, if anyone could be of anyhelp or just point me in the right direction then i would be very greatfull, ive posted the code for the test file i have been given below, thanks.
    public class SimpleEmailTest {
         public static void main( String[] args ) {
              SimpleEmail email;     // email object to test.
              String whoFrom;          // sender
              String whoTo;          // recipient
              String subject;          // subject matter
              String content;          // text content of email
              static final String notKnown = "Unknown";
              email = new SimpleEmail
    (notKnown, notKnown, notKnown, notKnown);
              System.out.println( "SimpleEmail: " +
    "\n    From: " + email.getSender() +
    "\n      To: " + email.getRecipient() +
    "\n Subject: " + email.getSubject() +
    "\n    Date: " + 
    email.getDate().toString() +
    "\n Message: \n" + email.getContent() + "\n";
              email.setSender( "Jimmy Testsender");
              email.setRecipient( "Sheena Receiver");
              email.setSubject( "How are you today?");
              email.setContent( "I just wrote an email class!");
              System.out.println( "SimpleEmail: " +
    "\n    From: " + email.getSender() +
    "\n      To: " + email.getRecipient() +
    "\n Subject: " + email.getSubject() +
    "\n    Date: " + 
    email.getDate().toString() +
    "\n Message: \n" + email.getContent() + "\n";
         }

    Start by writing a class named SimpleEmail, implement a constructor with four arguments in it, and the methods that the test code calls, such as the get...() and set...() methods. The class probably needs four member variables too.
    public class SimpleEmail {
        // ... add member variables here
        // constructor
        public SimpleEmail(String whoFrom, String whoTo, String subject, String content) {
            // ... add code to the constructor here
        // ... add get...() and set...() methods here
    }

  • Simple Tracking program

    Hi
    I am still learning the techniques of java and would like some help if possible. I am trying to create a simple tracking program which tracks what letter has been typed. For example if an A was pressed then the A label would turn blue. Then if another key was pressed then it would return to its default state white. I have created all the various labels for each letter and now have to do the programming of the tracking.I want it in the end to work out that when each letter key is typed on the keyboard then their various label would turn blue. If any of you have any hints or tutorials that would help me with it, I would be thankful.
    Nico

    I am still learning the techniques of java and would like some help if possible.Still learning how to ask a question as well I see. Much information is missing. For example:
    a) is this Swing or AWT (there are separate forums for each, instead of using the general programming forum)
    b) what kind of component has focus. A text field a panel?
    In general, you would probably use a KeyListener or a DocumentListener. Read the [Swing Tutorial|http://java.sun.com/docs/books/tutorial/uiswing/TOC.html] for examples of both.

  • How to create desktop application for simple server program using netbeans?

    Hi,can anyone help me on this one??
    I'm am very new to java,and I already trying different example program to create desktop applications
    for simple server program but it's not working.
    This is the main program for the simple server.
    import java.io.*;
    import java.net.*;
    public class Server {
    * @param args the command line arguments
    public static void main(String[] args) {
    try{
    ServerSocket serverSocket = new ServerSocket(4488);
    System.out.println("Server is waiting for an incoming connection on port 4488");
    Socket socket = serverSocket.accept();
    System.out.println(socket.getInetAddress() + "connected");
    PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
    BufferedReader in = new BufferedReader( new InputStreamReader(socket.getInputStream()));
    String inputLine;
    while ((inputLine = in.readLine()) != null){
    out.println(inputLine);
    System.out.println("Connection will be cut");
    out.close();
    in.close();
    socket.close();
    serverSocket.close();
    }catch(IOException e){
    e.printStackTrace();
    // TODO code application logic here
    }

    and this is the Main Processing :
    import java.awt.*;
    import java.awt.event.*;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.*;
    import java.text.*;
    import java.util.*;
    import java.net.*;
    import java.io.*;
    public class MainProcessing {
    private static final long serialVersionUID = 1L;
    static private boolean isApplet_ = true;
    static private InetAddress argIp_ = null;
    static private int argPort_ = 0;
    public TCPIP TCPIP_ = null;
    private InetAddress ip_ = null;
    private int port_ = 10001;
    static private boolean conectFlag = false;
    private BufferedWriter bw;
    FileOutputStream fos;
    OutputStreamWriter osw;
    public int[] current = new int[400];
    public int[] volt = new int[400];
    public int[] revolution = new int[400];
    public void init() {
    public void start() {
    if (isApplet_) {
    try {
    ip_ = InetAddress.getByName(getCodeBase().getHost());
    } catch (UnknownHostException e) {
    } else {
    ip_ = argIp_;
    if (argPort_ != 0) {
    port_ = argPort_;
    // IP&#12450;&#12489;&#12524;&#12473;&#12364;&#19981;&#26126;&#12394;&#12425;&#20309;&#12418;&#12375;&#12394;&#12356;
    if (ip_ != null) {
    // &#12467;&#12493;&#12463;&#12471;&#12519;&#12531;&#12364;&#25104;&#31435;&#12375;&#12390;&#12356;&#12394;&#12356;&#12394;&#12425;&#12289;&#25509;&#32154;
    if (TCPIP_ == null) {
    TCPIP_ = new TCPIP(ip_, port_);
    if (TCPIP_.getSocket_() == null) {
    System.out.println("&#12511;&#12473;&#65297;");
    // &#12456;&#12521;&#12540;&#12513;&#12483;&#12475;&#12540;&#12472;&#12434;&#34920;&#31034;
    return;
    if (TCPIP_ == null) {
    System.out.println("&#12511;&#12473;&#65298;");
    return;
    System.out.println("&#25104;&#21151;");
    conectFlag = true;
    try {
    TCPIP_.sendF();
    } catch (IOException ex) {
    Logger.getLogger(MainProcessing.class.getName()).log(Level.SEVERE, null, ex);
    System.out.println("" + conectFlag);
    return;
    public void receive() {
    try {
    // Calendar cal1 = Calendar.getInstance(); //(1)&#12458;&#12502;&#12472;&#12455;&#12463;&#12488;&#12398;&#29983;&#25104;
    // int year = cal1.get(Calendar.YEAR); //(2)&#29694;&#22312;&#12398;&#24180;&#12434;&#21462;&#24471;
    // int month = cal1.get(Calendar.MONTH) + 1; //(3)&#29694;&#22312;&#12398;&#26376;&#12434;&#21462;&#24471;
    // int day = cal1.get(Calendar.DATE); //(4)&#29694;&#22312;&#12398;&#26085;&#12434;&#21462;&#24471;
    // int hour = cal1.get(Calendar.HOUR_OF_DAY); //(5)&#29694;&#22312;&#12398;&#26178;&#12434;&#21462;&#24471;
    // int min = cal1.get(Calendar.MINUTE); //(6)&#29694;&#22312;&#12398;&#20998;&#12434;&#21462;&#24471;
    // int sec = cal1.get(Calendar.SECOND); //(7)&#29694;&#22312;&#12398;&#31186;&#12434;&#21462;&#24471;
    byte[] rev = TCPIP_.receive();
    // System.out.println("&#21463;&#20449;");
    if (rev != null) {
    byte[] Change = new byte[1];
    int j = 0;
    for (int i = 0; i < 1200; i++) {
    Change[0] = rev;
    current[j] = decimalChange(Change);
    i++;
    Change[0] = rev[i];
    volt[j] = decimalChange(Change);
    i++;
    Change[0] = rev[i];
    revolution[j] = decimalChange(Change);
    } catch (NullPointerException e) {
    public int decimalChange(byte[] byteData) {
    int bit0, bit1, bit2, bit3, bit4, bit5, bit6, bit7;
    int bit = 0;
    for (int i = 0; i < 8; i++) {
    int a = (byteData[0] >> i) & 1;
    System.out.print(a);
    System.out.println();
    return 1;
    public void destroy() {
    // &#20999;&#26029;
    if (TCPIP_ != null) {
    TCPIP_.disconnect();
    if (TCPIP_.getSocket_() != null) {
    try {
    System.out.println("\ndisconnect:" + TCPIP_.getSocket_().getInetAddress().getHostAddress() + " " + TCPIP_.getSocket_().getPort());
    } catch (Exception e) {
    TCPIP_ = null;
    public boolean conect(int IP) {
    conectFlag = false;
    String address = "192.168.1." + IP;
    System.out.println(address);
    try {
    argIp_ = InetAddress.getByName(address);
    } catch (UnknownHostException e) {
    // xp.init();
    isApplet_ = false;
    start();
    return (conectFlag);
    public void send(String command, int value, int sendData[][], int i) {
    int j = 0;
    Integer value_ = new Integer(value);
    byte values = value_.byteValue();
    Integer progNum = new Integer(i);
    byte progNums = progNum.byteValue();
    try {
    TCPIP_.send(command, values, progNums);
    for (j = 1; j <= i; j++) {
    Integer time = new Integer(sendData[j][0]);
    byte times = time.byteValue();
    Integer power = new Integer(sendData[j][1]);
    byte powers = power.byteValue();
    TCPIP_.send(times, powers);
    TCPIP_.flush();
    } catch (IOException ex) {
    Logger.getLogger(MainProcessing.class.getName()).log(Level.SEVERE, null, ex);
    public void file(String name) {
    ublic void fileclose(String name, String command, int value, int sendData[][], int i) {
    try {
    fos = new FileOutputStream("" + name + ".csv");
    osw = new OutputStreamWriter(fos, "MS932");
    bw = new BufferedWriter(osw);
    String msg = "" + command + "," + value + "";
    bw.write(msg);
    bw.newLine();
    for (int j = 1; j <= i; j++) {
    msg = "" + j + "," + sendData[i][0] + "," + sendData[i][1];
    bw.write(msg);
    bw.newLine();
    bw.close();
    } catch (IOException ex) {
    Logger.getLogger(MainProcessing.class.getName()).log(Level.SEVERE, null, ex);

  • A simple slideshow program for 68k OS7 Macs suggestions pls

    I'm looking for a simple slideshow program for my old 68k OS7 Macs. I just want to have some PICTs display on a set time period or key press. Nothing fancy.
    I can get Claris to this but wonder if HyperCard can. I'm no expert on HC but it seems to be designed for this exact job. Do I need to find a "stack" or some already made item to open in HC then attach my piks? Any suggestions?

    It would be possible to use HyperCard, although you may need to do a little programming if you go with it. If you use a blank HyperCard stack, you can assign one picture per card and link them. Clickable buttons would be the easiest way to do this. Which version of HyperCard are you using?
    An old version of PowerPoint would work fine too. Anything older than PowerPoint 98 runs on a 68K unless you are using a 68000 processor, in which case you'll need one of the pre-1994 versions.
    Believe it or not, Kid Pix is a possible answer to this as well. Any version from Kid Pix 2 onward (as well as the Kid Pix Companion addon for the original Broderbund version) contains an application called Slide Show, which is used with files in the PICT format. You can display an image for up to 30 seconds and add transitions between slides.

  • Simple transformation program debugging

    hi ,
       can any boby guide me how can we debug a simple transformation program which is used for xml to abap conversion .

    Hi,
    have a look on this.
    REPORT  YMS_XMLTOSAP.
    TYPE-POOLS: IXML.
    TYPES: BEGIN OF T_XML_LINE,
            DATA(256) TYPE X,
          END OF T_XML_LINE.
    DATA: L_IXML            TYPE REF TO IF_IXML,
          L_STREAMFACTORY   TYPE REF TO IF_IXML_STREAM_FACTORY,
          L_PARSER          TYPE REF TO IF_IXML_PARSER,
          L_ISTREAM         TYPE REF TO IF_IXML_ISTREAM,
          L_DOCUMENT        TYPE REF TO IF_IXML_DOCUMENT,
          L_NODE            TYPE REF TO IF_IXML_NODE,
          L_XMLDATA         TYPE STRING.
    DATA: L_ELEM            TYPE REF TO IF_IXML_ELEMENT,
          L_ROOT_NODE       TYPE REF TO IF_IXML_NODE,
          L_NEXT_NODE       TYPE REF TO IF_IXML_NODE,
          L_NAME            TYPE STRING,
          L_ITERATOR        TYPE REF TO IF_IXML_NODE_ITERATOR.
    DATA: L_XML_TABLE       TYPE TABLE OF T_XML_LINE,
          L_XML_LINE        TYPE T_XML_LINE,
          L_XML_TABLE_SIZE  TYPE I.
    DATA: L_FILENAME        TYPE STRING.
    PARAMETERS: PA_FILE TYPE CHAR1024 DEFAULT 'c:\temp\orders_dtd.xml'.
    * Validation of XML file: Only DTD included in xml document is supported
    PARAMETERS: PA_VAL  TYPE CHAR1 AS CHECKBOX.
    START-OF-SELECTION.
    *   Creating the main iXML factory
      L_IXML = CL_IXML=>CREATE( ).
    *   Creating a stream factory
      L_STREAMFACTORY = L_IXML->CREATE_STREAM_FACTORY( ).
      PERFORM GET_XML_TABLE CHANGING L_XML_TABLE_SIZE L_XML_TABLE.
    *   wrap the table containing the file into a stream
      L_ISTREAM = L_STREAMFACTORY->CREATE_ISTREAM_ITABLE( TABLE = L_XML_TABLE
                                                      SIZE  = L_XML_TABLE_SIZE ).
    *   Creating a document
      L_DOCUMENT = L_IXML->CREATE_DOCUMENT( ).
    *   Create a Parser
      L_PARSER = L_IXML->CREATE_PARSER( STREAM_FACTORY = L_STREAMFACTORY
                                        ISTREAM        = L_ISTREAM
                                        DOCUMENT       = L_DOCUMENT ).
    *   Validate a document
      IF PA_VAL EQ 'X'.
        L_PARSER->SET_VALIDATING( MODE = IF_IXML_PARSER=>CO_VALIDATE ).
      ENDIF.
    *   Parse the stream
      IF L_PARSER->PARSE( ) NE 0.
        IF L_PARSER->NUM_ERRORS( ) NE 0.
          DATA: PARSEERROR TYPE REF TO IF_IXML_PARSE_ERROR,
                STR        TYPE STRING,
                I          TYPE I,
                COUNT      TYPE I,
                INDEX      TYPE I.
          COUNT = L_PARSER->NUM_ERRORS( ).
          WRITE: COUNT, ' parse errors have occured:'.
          INDEX = 0.
          WHILE INDEX < COUNT.
            PARSEERROR = L_PARSER->GET_ERROR( INDEX = INDEX ).
            I = PARSEERROR->GET_LINE( ).
            WRITE: 'line: ', I.
            I = PARSEERROR->GET_COLUMN( ).
            WRITE: 'column: ', I.
            STR = PARSEERROR->GET_REASON( ).
            WRITE: STR.
            INDEX = INDEX + 1.
          ENDWHILE.
        ENDIF.
      ENDIF.
    *   Process the document
      IF L_PARSER->IS_DOM_GENERATING( ) EQ 'X'.
        PERFORM PROCESS_DOM USING L_DOCUMENT.
      ENDIF.
    *&      Form  get_xml_table
    FORM GET_XML_TABLE CHANGING L_XML_TABLE_SIZE TYPE I
                                L_XML_TABLE      TYPE STANDARD TABLE.
    *   Local variable declaration
      DATA: L_LEN      TYPE I,
            L_LEN2     TYPE I,
            L_TAB      TYPE TSFIXML,
            L_CONTENT  TYPE STRING,
            L_STR1     TYPE STRING,
            C_CONV     TYPE REF TO CL_ABAP_CONV_IN_CE,
            L_ITAB     TYPE TABLE OF STRING.
      L_FILENAME = PA_FILE.
    *   upload a file from the client's workstation
      CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_UPLOAD
        EXPORTING
          FILENAME   = L_FILENAME
          FILETYPE   = 'BIN'
        IMPORTING
          FILELENGTH = L_XML_TABLE_SIZE
        CHANGING
          DATA_TAB   = L_XML_TABLE
        EXCEPTIONS
          OTHERS     = 19.
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                   WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    *   Writing the XML document to the screen
      CLEAR L_STR1.
      LOOP AT L_XML_TABLE INTO L_XML_LINE.
        C_CONV = CL_ABAP_CONV_IN_CE=>CREATE( INPUT = L_XML_LINE-DATA REPLACEMENT = SPACE  ).
        C_CONV->READ( IMPORTING DATA = L_CONTENT LEN = L_LEN ).
        CONCATENATE L_STR1 L_CONTENT INTO L_STR1.
      ENDLOOP.
      L_STR1 = L_STR1+0(L_XML_TABLE_SIZE).
      SPLIT L_STR1 AT CL_ABAP_CHAR_UTILITIES=>CR_LF INTO TABLE L_ITAB.
      WRITE: /.
      WRITE: /' XML File'.
      WRITE: /.
      LOOP AT L_ITAB INTO L_STR1.
        REPLACE ALL OCCURRENCES OF CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB IN
          L_STR1 WITH SPACE.
        WRITE: / L_STR1.
      ENDLOOP.
      WRITE: /.
    ENDFORM.                    "get_xml_table
    *&      Form  process_dom
    FORM PROCESS_DOM USING DOCUMENT TYPE REF TO IF_IXML_DOCUMENT.
      DATA: NODE      TYPE REF TO IF_IXML_NODE,
            ITERATOR  TYPE REF TO IF_IXML_NODE_ITERATOR,
            NODEMAP   TYPE REF TO IF_IXML_NAMED_NODE_MAP,
            ATTR      TYPE REF TO IF_IXML_NODE,
            NAME      TYPE STRING,
            PREFIX    TYPE STRING,
            VALUE     TYPE STRING,
            INDENT    TYPE I,
            COUNT     TYPE I,
            INDEX     TYPE I.
      NODE ?= DOCUMENT.
      CHECK NOT NODE IS INITIAL.
      ULINE.
      WRITE: /.
      WRITE: /' DOM-TREE'.
      WRITE: /.
      IF NODE IS INITIAL. EXIT. ENDIF.
    *   create a node iterator
      ITERATOR  = NODE->CREATE_ITERATOR( ).
    *   get current node
      NODE = ITERATOR->GET_NEXT( ).
    *   loop over all nodes
      WHILE NOT NODE IS INITIAL.
        INDENT = NODE->GET_HEIGHT( ) * 2.
        INDENT = INDENT + 20.
        CASE NODE->GET_TYPE( ).
          WHEN IF_IXML_NODE=>CO_NODE_ELEMENT.
    *         element node
            NAME    = NODE->GET_NAME( ).
            NODEMAP = NODE->GET_ATTRIBUTES( ).
            WRITE: / 'ELEMENT  :'.
            WRITE: AT INDENT NAME COLOR COL_POSITIVE INVERSE.
            IF NOT NODEMAP IS INITIAL.
    *           attributes
              COUNT = NODEMAP->GET_LENGTH( ).
              DO COUNT TIMES.
                INDEX  = SY-INDEX - 1.
                ATTR   = NODEMAP->GET_ITEM( INDEX ).
                NAME   = ATTR->GET_NAME( ).
                PREFIX = ATTR->GET_NAMESPACE_PREFIX( ).
                VALUE  = ATTR->GET_VALUE( ).
                WRITE: / 'ATTRIBUTE:'.
                WRITE: AT INDENT NAME  COLOR COL_HEADING INVERSE, '=',
                                 VALUE COLOR COL_TOTAL   INVERSE.
              ENDDO.
            ENDIF.
          WHEN IF_IXML_NODE=>CO_NODE_TEXT OR
               IF_IXML_NODE=>CO_NODE_CDATA_SECTION.
    *         text node
            VALUE  = NODE->GET_VALUE( ).
            WRITE: / 'VALUE     :'.
            WRITE: AT INDENT VALUE COLOR COL_GROUP INVERSE.
        ENDCASE.
    *     advance to next node
        NODE = ITERATOR->GET_NEXT( ).
      ENDWHILE.
    ENDFORM.                    "process_dom
    Thanks,
    Sankar M

  • Can anyone clarify my doubt in a simple JSP Program ?

    when we write a simple jsp program such as helloworld.jsp does a
    class file or servlet be created when we run the jsp program using a
    web browser and Tomcat ? if so please tell the folder(path) in tomcat
    where this class file will be located or stored .Thankq

    JSPs will (usually) be compiled into class files representing Servlets, yes. But that's something that happens internally inside the application server and shouldn't concern you.
    Why would you need to know where it resides? It seems like a code smell if you need that information.
    If you're just curious, then look into the work directory of your tomcat.

Maybe you are looking for