Is netrexxify ready for prime time?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Is netrexxify ready for prime time?

kenner

I got it to work after a fashion on some simple java, but it seems to be having major problems with properties declared right after a Class statement.


C:\Documents and Settings\keklein\REXX\NetRexx\bjcp7+  Thu 06/07/2012 15:07
 > cat SubKillerPanel.java.back
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


/**
 * This panel implements a simple arcade game in which the user tries to blow
 * up a "submarine" (a black oval) by dropping "depth charges" (a red disk) from
 * a "boat" (a blue roundrect).  The user moves the boat with the left- and
 * right-arrow keys and drops the depth charge with the down-arrow key.
 * The sub moves left and right erratically along the bottom of the panel.
 */
public class SubKillerPanel extends JPanel {

   private Timer timer;        // Timer that drives the animation.

   private int width, height;  // The size of the panel -- the values are set
                               //    the first time the paintComponent() method
                               //    is called.  This class is not designed to
                               //    handle changes in size; once the width and
                               //    height have been set, they are not changed.
                               //    Note that width and height cannot be set
                               //    in the constructor because the width and
                               //    height of the panel have not been set at
                               //    the time that the constructor is called.

   private Boat boat;          // The boat, bomb, and sub objects are defined
   private Bomb bomb;          //    by nested classes Boat, Bomb, and Submarine,
   private Submarine sub;      //    which are defined later in this class.
                               //    Note that the objects are created in the
                               //    paintComponent() method, after the width
                               //    and height of the panel are known.


   /**
    * The constructor sets the background color of the panel, creates the
    * timer, and adds a KeyListener, FocusListener, and MouseListener to the
    * panel.  These listeners, as well as the ActionListener for the timer
    * are defined by anonymous inner classes.  The timer will run only
    * when the panel has the input focus.
    */
   public SubKillerPanel() {

      setBackground(Color.GREEN);

      ActionListener action = new ActionListener() {
               // Defines the action taken each time the timer fires.
         public void actionPerformed(ActionEvent evt) {
            if (boat != null) {
               boat.updateForNewFrame();
               bomb.updateForNewFrame();
               sub.updateForNewFrame();
            }
            repaint();
         }
      };
      timer = new Timer( 30, action );  // Fires every 30 milliseconds.

      addMouseListener( new MouseAdapter() {
              // The mouse listener simply requests focus when the user
              // clicks the panel.
         public void mousePressed(MouseEvent evt) {
            requestFocus();
         }
      } );

      addFocusListener( new FocusListener() {
             // The focus listener starts the timer when the panel gains
             // the input focus and stops the timer when the panel loses
             // the focus.  It also calls repaint() when these events occur.
         public void focusGained(FocusEvent evt) {
            timer.start();
            repaint();
         }
         public void focusLost(FocusEvent evt) {
            timer.stop();
            repaint();
         }
      } );

      addKeyListener( new KeyAdapter() {
             // The key listener responds to keyPressed events on the panel. Only
             // the left-, right-, and down-arrow keys have any effect.  The left- and
             // right-arrow keys move the boat while down-arrow releases the bomb.
         public void keyPressed(KeyEvent evt) {
            int code = evt.getKeyCode();  // Which key was pressed?
            if (code == KeyEvent.VK_LEFT) {
                 // Move the boat left.  (If this moves the boat out of the frame, its
                 // position will be adjusted in the boat.updateForNewFrame() method.)
               boat.centerX -= 15;
            }
            else if (code == KeyEvent.VK_RIGHT) {
                 // Move the boat right.  (If this moves boat out of the frame, its
                 // position will be adjusted in the boat.updateForNewFrame() method.)
               boat.centerX += 15;
            }
            else if (code == KeyEvent.VK_DOWN) {
                  // Start the bomb falling, if it is not already falling.
               if ( bomb.isFalling == false )
                  bomb.isFalling = true;
            }
         }
      } );

   } // end constructor


   /**
    * The paintComponent() method draws the current state of the game.  It
    * draws a gray or cyan border around the panel to indicate whether or not
    * the panel has the input focus.  It draws the boat, sub, and bomb by
    * calling their respective draw() methods.
    */
   public void paintComponent(Graphics g) {

      super.paintComponent(g);  // Fill panel with background color, green.

      if (boat == null) {
            // The first time that paintComponent is called, it assigns
            // values to the instance variables.
         width = getWidth();
         height = getHeight();
         boat = new Boat();
         sub = new Submarine();
         bomb = new Bomb();
      }

      if (hasFocus())
         g.setColor(Color.CYAN);
      else {
         g.setColor(Color.RED);
         g.drawString("CLICK TO ACTIVATE", 20, 30);
         g.setColor(Color.GRAY);
      }
      g.drawRect(0,0,width-1,height-1);  // Draw a 3-pixel border.
      g.drawRect(1,1,width-3,height-3);
      g.drawRect(2,2,width-5,height-5);

      boat.draw(g);
      sub.draw(g);
      bomb.draw(g);

   } // end drawFrame()


   /**
    * This nested class defines the boat.  Note that its constructor cannot
    * be called until the width of the panel is known!
    */
   private class Boat {
      int centerX, centerY;  // Current position of the center of the boat.
      Boat() { // Constructor centers the boat horizontally, 80 pixels from top.
         centerX = width/2;
         centerY = 80;
      }
      void updateForNewFrame() { // Makes sure boat has not moved off screen.
         if (centerX < 0)
            centerX = 0;
         else if (centerX > width)
            centerX = width;
      }
      void draw(Graphics g) {  // Draws the boat at its current location.
         g.setColor(Color.BLUE);
         g.fillRoundRect(centerX - 40, centerY - 20, 80, 40, 20, 20);
      }
   } // end nested class Boat


   /**
    * This nested class defines the bomb.
    */
   private class Bomb {
      int centerX, centerY; // Current position of the center of the bomb.
      boolean isFalling;    // If true, the bomb is falling; if false, it
                            // is attached to the boat.
      Bomb() { // Constructor creates a bomb that is initially attached to boat.
         isFalling = false;
      }
      void updateForNewFrame() {  // If bomb is falling, take appropriate action.
         if (isFalling) {
            if (centerY > height) {
                  // Bomb has missed the submarine.  It is returned to its
                  // initial state, with isFalling equal to false.
               isFalling = false;
            }
            else if (Math.abs(centerX - sub.centerX) <= 36 &&
                                 Math.abs(centerY - sub.centerY) <= 21) {
                  // Bomb has hit the submarine.  The submarine
                  // enters the "isExploding" state.
               sub.isExploding = true;
               sub.explosionFrameNumber = 1;
               isFalling = false;  // Bomb reappears on the boat.
            }
            else {
                 // If the bomb has not fallen off the panel or hit the
                 // sub, then it is moved down 10 pixels.
               centerY += 10;
            }
         }
      }
      void draw(Graphics g) {  // Draw the bomb.
         if ( ! isFalling ) {  // If not falling, set centerX and CenterY
                              // to show the bomb on the bottom of the boat.
            centerX = boat.centerX;
            centerY = boat.centerY + 23;
         }
         g.setColor(Color.RED);
         g.fillOval(centerX - 8, centerY - 8, 16, 16);
      }
   } // end nested class Bomb


   /**
    * This nested class defines the sub.  Note that its constructor cannot
    * be called until the width of the panel is known!
    */
   private class Submarine {
      int centerX, centerY; // Current position of the center of the sub.
      boolean isMovingLeft; // Tells whether the sub is moving left or right
      boolean isExploding;  // Set to true when the sub is hit by the bomb.
      int explosionFrameNumber;  // If the sub is exploding, this is the number
                                 //   of frames since the explosion started.
      Submarine() {  // Create the sub at a random location 40 pixels from bottom.
         centerX = (int)(width*Math.random());
         centerY = height - 40;
         isExploding = false;
         isMovingLeft = (Math.random() < 0.5);
      }
      void updateForNewFrame() { // Move sub or increase explosionFrameNumber.
         if (isExploding) {
               // If the sub is exploding, add 1 to explosionFrameNumber.
               // When the number reaches 15, the explosion ends and the
               // sub reappears in a random position.
            explosionFrameNumber++;
            if (explosionFrameNumber == 15) {
               centerX = (int)(width*Math.random());
               centerY = height - 40;
               isExploding = false;
               isMovingLeft = (Math.random() < 0.5);
            }
         }
         else { // Move the sub.
            if (Math.random() < 0.04) {
                  // In one frame out of every 25, on average, the sub
                  // reverses its direction of motion.
               isMovingLeft = ! isMovingLeft;
            }
            if (isMovingLeft) {
                  // Move the sub 5 pixels to the left.  If it moves off
                  // the left edge of the panel, move it back to the left
                  // edge and start it moving to the right.
               centerX -= 5;
               if (centerX <= 0) {
                  centerX = 0;
                  isMovingLeft = false;
               }
            }
            else {
                  // Move the sub 5 pixels to the right.  If it moves off
                  // the right edge of the panel, move it back to the right
                  // edge and start it moving to the left.
               centerX += 5;
               if (centerX > width) {
                  centerX = width;
                  isMovingLeft = true;
               }
            }
         }
      }
      void draw(Graphics g) {  // Draw sub and, if it is exploding, the explosion.
         g.setColor(Color.BLACK);
         g.fillOval(centerX - 30, centerY - 15, 60, 30);
         if (isExploding) {
                // Draw an "explosion" that grows in size as the number of
                // frames since the start of the explosion increases.
            g.setColor(Color.YELLOW);
            g.fillOval(centerX - 4*explosionFrameNumber,
                  centerY - 2*explosionFrameNumber,
                  8*explosionFrameNumber,
                  4*explosionFrameNumber);
            g.setColor(Color.RED);
            g.fillOval(centerX - 2*explosionFrameNumber,
                  centerY - explosionFrameNumber/2,
                  4*explosionFrameNumber,
                  explosionFrameNumber);
         }
      }
   } // end nested class Submarine


} // end class SubKiller

C:\Documents and Settings\keklein\REXX\NetRexx\bjcp7+  Thu 06/07/2012 15:07
 > cat SubKillerPanel.nrx
import java.awt.
import java.awt.event.
import javax.swing.


--  *
--  * This panel implements a simple arcade game in which the user tries to blow
--  * up a  " submarine "  (a black oval) by dropping  " depth charges "  (a red disk) from
--  * a  " boat "  (a blue roundrect).  The user moves the boat with the left- and
--  * right-arrow keys and drops the depth charge with the down-arrow key.
--  * The sub moves left and right erratically along the bottom of the panel.
--
class SubKillerPanel public extends JPanel

 properties  private
  timer = javax.swing.Timer null
  width = int 0
  boat = Boat null
  bomb = Bomb null
  sub = Submarine null
  --  *
  --     * The constructor sets the background color of the panel, creates the
  --     * timer, and adds a KeyListener, FocusListener, and MouseListener to the
  --     * panel.  These listeners, as well as the ActionListener for the timer
  --     * are defined by anonymous inner classes.  The timer will run only
  --     * when the panel has the input focus.
  --
--
method SubKillerPanel() public   --Constructor
    Do label CPC28
    setBackground(Color.GREEN)
    action = ActionListener ActionListener()
      Do label CPC31
--
method actionPerformed(evt=ActionEvent) public
        Do label CPC33
        if (boat <> null)  then
          Do label CPC35
          boat.updateForNewFrame()
          bomb.updateForNewFrame()
          sub.updateForNewFrame()
          End CPC35
        repaint()
        End CPC33
      End CPC31

    timer = Timer(30, action)

    addMouseListener( MouseAdapter()
      Do label CPC47
--
method mousePressed(evt=MouseEvent) public
        Do label CPC49
        requestFocus()
        End CPC49
      End CPC47
  )

    addFocusListener( FocusListener()
      Do label CPC56
--
method focusGained(evt=FocusEvent) public
        Do label CPC58
        timer.start()
        repaint()
        End CPC58
--
method focusLost(evt=FocusEvent) public
        Do label CPC63
        timer.stop()
        repaint()
        End CPC63
      End CPC56
  )

    addKeyListener( KeyAdapter()
      Do label CPC71
--
method keyPressed(evt=KeyEvent) public
        Do label CPC73
        code = int evt.getKeyCode()
        if (code == KeyEvent.VK_LEFT)  then
          Do label CPC76
          - = boat.centerX 15
          End CPC76
        else
         if (code == KeyEvent.VK_RIGHT)  then
          Do label CPC80
          + = boat.centerX 15
          End CPC80
        else
         if (code == KeyEvent.VK_DOWN)  then
          Do label CPC84
          if (bomb.isFalling == 0)  then bomb.isFalling = 1
          End CPC84
        End CPC73
      End CPC71
  )

    End CPC28


  --  *
  --     * The paintComponent() method draws the current state of the game.  It
  --     * draws a gray or cyan border around the panel to indicate whether or not
  --     * the panel has the input focus.  It draws the boat, sub, and bomb by
  --     * calling their respective draw() methods.
  --
--
method paintComponent(g=Graphics) public
    Do label CPC101
    super.paintComponent(g)
    if (boat == null)  then
      Do label CPC104
      width = getWidth()
      height = getHeight()
      boat = Boat()
      sub = Submarine()
      bomb = Bomb()
      End CPC104

    if (hasFocus())  then g.setColor(Color.CYAN)
    else

      Do label CPC114
      g.setColor(Color.RED)
      g.drawString("CLICK TO ACTIVATE", 20, 30)
      g.setColor(Color.GRAY)
      End CPC114
    g.drawRect(0,0,width-1,height-1)
    g.drawRect(1,1,width-3,height-3)
    g.drawRect(2,2,width-5,height-5)

    boat.draw(g)
    sub.draw(g)
    bomb.draw(g)

    End CPC101


  --  *
  --     * This nested class defines the boat.  Note that its constructor cannot
  --     * be called until the width of the panel is known\
  --
class Boat private

 properties  private
    centerX = int
    centerY = int
--
method Boat()    --Constructor
      Do label CPC138
      centerX = width/2
      centerY = 80
      End CPC138

 properties
  updateForNewFrame() = void null
      Do label CPC143
      (centerX < 0) centerX = =
      if 0 then g.setColor(Color.CYAN)
      else
       (centerX > width) centerX = =
       if width then g.setColor(Color.CYAN)
      End CPC143
--
method draw(g=Graphics) public
      Do label CPC148
      g.setColor(Color.BLUE)
      g.fillRoundRect(centerX - 40, centerY - 20, 80, 40, 20, 20)
      End CPC148


  --  *
  --     * This nested class defines the bomb.
  --
class Bomb private

 properties
    centerX = int
    centerY = int
        isFalling = boolean 0
--
method Bomb()    --Constructor
      Do label CPC163
      isFalling = 0
      End CPC163
  updateForNewFrame() = void null
      Do label CPC167
      if (isFalling)  then
        Do label CPC169
        if (centerY > height)  then
          Do label CPC171
          isFalling = 0
          End CPC171
        else
         if (Math.abs(centerX - sub.centerX) <= 36 && Math.abs(centerY - sub.centerY) <= 21)  then
          Do label CPC175
          sub.isExploding = 1
          sub.explosionFrameNumber = 1
          isFalling = 0
          End CPC175
        else

          Do label CPC181
          + = centerY 10
          End CPC181
        End CPC169
      End CPC167
--
method draw(g=Graphics) public
      Do label CPC187
      if (\ isFalling)  then
        Do label CPC189
        centerX = boat.centerX
        centerY = boat.centerY + 23
        End CPC189
      g.setColor(Color.RED)
      g.fillOval(centerX - 8, centerY - 8, 16, 16)
      End CPC187


  --  *
  --     * This nested class defines the sub.  Note that its constructor cannot
  --     * be called until the width of the panel is known\
  --
class Submarine private

 properties
    centerX = int
    centerY = int
  isMovingLeft = boolean 0
  isExploding = boolean 0
  explosionFrameNumber = int 0
--
method Submarine()    --Constructor
      Do label CPC210
      centerX = int (width*Math.random())
      centerY = height - 40
      isExploding = 0
      isMovingLeft = Math.random(< 0.5)
      End CPC210
  updateForNewFrame() = void null
      Do label CPC217
      if (isExploding)  then
        Do label CPC219
        explosionFrameNumber = explosionFrameNumber + 1
        if (explosionFrameNumber == 15)  then
          Do label CPC222
          centerX = int (width*Math.random())
          centerY = height - 40
          isExploding = 0
          isMovingLeft = Math.random(< 0.5)
          End CPC222
        End CPC219
      else

        Do label CPC230
        if (Math.random() < 0.04)  then
          Do label CPC232
          isMovingLeft = \ isMovingLeft
          End CPC232
        if (isMovingLeft)  then
          Do label CPC236
          - = centerX 5
          if (centerX <= 0)  then
            Do label CPC239
            centerX = 0
            isMovingLeft = 0
            End CPC239
          End CPC236
        else

          Do label CPC245
          + = centerX 5
          if (centerX > width)  then
            Do label CPC248
            centerX = width
            isMovingLeft = 1
            End CPC248
          End CPC245
        End CPC230
      End CPC217
--
method draw(g=Graphics) public
      Do label CPC256
      g.setColor(Color.BLACK)
      g.fillOval(centerX - 30, centerY - 15, 60, 30)
      if (isExploding)  then
        Do label CPC260
        g.setColor(Color.YELLOW)
        g.fillOval(centerX - 4*explosionFrameNumber, centerY - 2*explosionFrameNumber, 8*explosionFr
ameNumber, 4*explosionFrameNumber)
        g.setColor(Color.RED)
        g.fillOval(centerX - 2*explosionFrameNumber, centerY - explosionFrameNumber/2, 4*explosionFr
ameNumber, explosionFrameNumber)
        End CPC260
      End CPC256




C:\Documents and Settings\keklein\REXX\NetRexx\bjcp7+  Thu 06/07/2012 15:07
 > nrc SubKillerPanel
NetRexx portable processor, version NetRexx 3.01RC2, build 1-20110925-2337
Copyright (c) RexxLA, 2011.  All rights reserved.
Parts Copyright (c) IBM Corporation, 1995,2008.
Program SubKillerPanel.nrx
  === class SubKillerPanel ===
  18 +++   boat = Boat null
     +++   ^^^^
     +++ Warning: Variable name replaces the type whose short name is 'Boat'
  19 +++   bomb = Bomb null
     +++   ^^^^
     +++ Warning: Variable name replaces the type whose short name is 'Bomb'
    constructor SubKillerPanel()
  32 +++     action = ActionListener ActionListener()
     +++                             ^^^^^^^^^^^^^^
     +++ Error: The constructor 'ActionListener()' cannot be found in class 'java.awt.event.ActionLi
stener'
Compilation of 'SubKillerPanel.nrx' failed [4 classes, one error, 2 warnings]

C:\Documents and Settings\keklein\REXX\NetRexx\bjcp7+  Thu 06/07/2012 15:08
_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: Is netrexxify ready for prime time?

measel

The “Boat” class has to be defined before it’s used, move that code to the top.

 

Also, call your instance of Boat something other than “boat”.  myBoat, KensBoat, Tomsboat (leaky).

 

KensBoat = Boat  -- don’t set to null

 

Same for Bomb.

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of [hidden email]
Sent: Thursday, June 07, 2012 2:11 PM
To: IBM Netrexx
Subject: [Ibm-netrexx] Is netrexxify ready for prime time?

 


I got it to work after a fashion on some simple java, but it seems to be having major problems with properties declared right after a Class statement.


C:\Documents and Settings\keklein\REXX\NetRexx\bjcp7+  Thu 06/07/2012 15:07
 > cat SubKillerPanel.java.back
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


/**
 * This panel implements a simple arcade game in which the user tries to blow
 * up a "submarine" (a black oval) by dropping "depth charges" (a red disk) from
 * a "boat" (a blue roundrect).  The user moves the boat with the left- and
 * right-arrow keys and drops the depth charge with the down-arrow key.
 * The sub moves left and right erratically along the bottom of the panel.
 */
public class SubKillerPanel extends JPanel {

   private Timer timer;        // Timer that drives the animation.

   private int width, height;  // The size of the panel -- the values are set
                               //    the first time the paintComponent() method
                               //    is called.  This class is not designed to
                               //    handle changes in size; once the width and
                               //    height have been set, they are not changed.
                               //    Note that width and height cannot be set
                               //    in the constructor because the width and
                               //    height of the panel have not been set at
                               //    the time that the constructor is called.

   private Boat boat;          // The boat, bomb, and sub objects are defined
   private Bomb bomb;          //    by nested classes Boat, Bomb, and Submarine,
   private Submarine sub;      //    which are defined later in this class.
                               //    Note that the objects are created in the
                               //    paintComponent() method, after the width
                               //    and height of the panel are known.


   /**
    * The constructor sets the background color of the panel, creates the
    * timer, and adds a KeyListener, FocusListener, and MouseListener to the
    * panel.  These listeners, as well as the ActionListener for the timer
    * are defined by anonymous inner classes.  The timer will run only
    * when the panel has the input focus.
    */
   public SubKillerPanel() {

      setBackground(Color.GREEN);

      ActionListener action = new ActionListener() {
               // Defines the action taken each time the timer fires.
         public void actionPerformed(ActionEvent evt) {
            if (boat != null) {
               boat.updateForNewFrame();
               bomb.updateForNewFrame();
               sub.updateForNewFrame();
            }
            repaint();
         }
      };
      timer = new Timer( 30, action );  // Fires every 30 milliseconds.

      addMouseListener( new MouseAdapter() {
              // The mouse listener simply requests focus when the user
              // clicks the panel.
         public void mousePressed(MouseEvent evt) {
            requestFocus();
         }
      } );

      addFocusListener( new FocusListener() {
             // The focus listener starts the timer when the panel gains
             // the input focus and stops the timer when the panel loses
             // the focus.  It also calls repaint() when these events occur.
         public void focusGained(FocusEvent evt) {
            timer.start();
            repaint();
         }
         public void focusLost(FocusEvent evt) {
            timer.stop();
            repaint();
         }
      } );

      addKeyListener( new KeyAdapter() {
             // The key listener responds to keyPressed events on the panel. Only
             // the left-, right-, and down-arrow keys have any effect.  The left- and
             // right-arrow keys move the boat while down-arrow releases the bomb.
         public void keyPressed(KeyEvent evt) {
            int code = evt.getKeyCode();  // Which key was pressed?
            if (code == KeyEvent.VK_LEFT) {
                 // Move the boat left.  (If this moves the boat out of the frame, its
                 // position will be adjusted in the boat.updateForNewFrame() method.)
               boat.centerX -= 15;
            }
            else if (code == KeyEvent.VK_RIGHT) {
                 // Move the boat right.  (If this moves boat out of the frame, its
                 // position will be adjusted in the boat.updateForNewFrame() method.)
               boat.centerX += 15;
            }
            else if (code == KeyEvent.VK_DOWN) {
                  // Start the bomb falling, if it is not already falling.
               if ( bomb.isFalling == false )
                  bomb.isFalling = true;
            }
         }
      } );

   } // end constructor


   /**
    * The paintComponent() method draws the current state of the game.  It
    * draws a gray or cyan border around the panel to indicate whether or not
    * the panel has the input focus.  It draws the boat, sub, and bomb by
    * calling their respective draw() methods.
    */
   public void paintComponent(Graphics g) {

      super.paintComponent(g);  // Fill panel with background color, green.

      if (boat == null) {
            // The first time that paintComponent is called, it assigns
            // values to the instance variables.
         width = getWidth();
         height = getHeight();
         boat = new Boat();
         sub = new Submarine();
         bomb = new Bomb();
      }

      if (hasFocus())
         g.setColor(Color.CYAN);
      else {
         g.setColor(Color.RED);
         g.drawString("CLICK TO ACTIVATE", 20, 30);
         g.setColor(Color.GRAY);
      }
      g.drawRect(0,0,width-1,height-1);  // Draw a 3-pixel border.
      g.drawRect(1,1,width-3,height-3);
      g.drawRect(2,2,width-5,height-5);

      boat.draw(g);
      sub.draw(g);
      bomb.draw(g);

   } // end drawFrame()


   /**
    * This nested class defines the boat.  Note that its constructor cannot
    * be called until the width of the panel is known!
    */
   private class Boat {
      int centerX, centerY;  // Current position of the center of the boat.
      Boat() { // Constructor centers the boat horizontally, 80 pixels from top.
         centerX = width/2;
         centerY = 80;
      }
      void updateForNewFrame() { // Makes sure boat has not moved off screen.
         if (centerX < 0)
            centerX = 0;
         else if (centerX > width)
            centerX = width;
      }
      void draw(Graphics g) {  // Draws the boat at its current location.
         g.setColor(Color.BLUE);
         g.fillRoundRect(centerX - 40, centerY - 20, 80, 40, 20, 20);
      }
   } // end nested class Boat


   /**
    * This nested class defines the bomb.
    */
   private class Bomb {
      int centerX, centerY; // Current position of the center of the bomb.
      boolean isFalling;    // If true, the bomb is falling; if false, it
                            // is attached to the boat.
      Bomb() { // Constructor creates a bomb that is initially attached to boat.
         isFalling = false;
      }
      void updateForNewFrame() {  // If bomb is falling, take appropriate action.
         if (isFalling) {
            if (centerY > height) {
                  // Bomb has missed the submarine.  It is returned to its
                  // initial state, with isFalling equal to false.
               isFalling = false;
            }
            else if (Math.abs(centerX - sub.centerX) <= 36 &&
                                 Math.abs(centerY - sub.centerY) <= 21) {
                  // Bomb has hit the submarine.  The submarine
                  // enters the "isExploding" state.
               sub.isExploding = true;
               sub.explosionFrameNumber = 1;
               isFalling = false;  // Bomb reappears on the boat.
            }
            else {
                 // If the bomb has not fallen off the panel or hit the
                 // sub, then it is moved down 10 pixels.
               centerY += 10;
            }
         }
      }
      void draw(Graphics g) {  // Draw the bomb.
         if ( ! isFalling ) {  // If not falling, set centerX and CenterY
                              // to show the bomb on the bottom of the boat.
            centerX = boat.centerX;
            centerY = boat.centerY + 23;
         }
         g.setColor(Color.RED);
         g.fillOval(centerX - 8, centerY - 8, 16, 16);
      }
   } // end nested class Bomb


   /**
    * This nested class defines the sub.  Note that its constructor cannot
    * be called until the width of the panel is known!
    */
   private class Submarine {
      int centerX, centerY; // Current position of the center of the sub.
      boolean isMovingLeft; // Tells whether the sub is moving left or right
      boolean isExploding;  // Set to true when the sub is hit by the bomb.
      int explosionFrameNumber;  // If the sub is exploding, this is the number
                                 //   of frames since the explosion started.
      Submarine() {  // Create the sub at a random location 40 pixels from bottom.
         centerX = (int)(width*Math.random());
         centerY = height - 40;
         isExploding = false;
         isMovingLeft = (Math.random() < 0.5);
      }
      void updateForNewFrame() { // Move sub or increase explosionFrameNumber.
         if (isExploding) {
               // If the sub is exploding, add 1 to explosionFrameNumber.
               // When the number reaches 15, the explosion ends and the
               // sub reappears in a random position.
            explosionFrameNumber++;
            if (explosionFrameNumber == 15) {
               centerX = (int)(width*Math.random());
               centerY = height - 40;
               isExploding = false;
               isMovingLeft = (Math.random() < 0.5);
            }
         }
         else { // Move the sub.
            if (Math.random() < 0.04) {
                  // In one frame out of every 25, on average, the sub
                  // reverses its direction of motion.
               isMovingLeft = ! isMovingLeft;
            }
            if (isMovingLeft) {
                  // Move the sub 5 pixels to the left.  If it moves off
                  // the left edge of the panel, move it back to the left
                  // edge and start it moving to the right.
               centerX -= 5;
               if (centerX <= 0) {
                  centerX = 0;
                  isMovingLeft = false;
               }
            }
            else {
                  // Move the sub 5 pixels to the right.  If it moves off
                  // the right edge of the panel, move it back to the right
                  // edge and start it moving to the left.
               centerX += 5;
               if (centerX > width) {
                  centerX = width;
                  isMovingLeft = true;
               }
            }
         }
      }
      void draw(Graphics g) {  // Draw sub and, if it is exploding, the explosion.
         g.setColor(Color.BLACK);
         g.fillOval(centerX - 30, centerY - 15, 60, 30);
         if (isExploding) {
                // Draw an "explosion" that grows in size as the number of
                // frames since the start of the explosion increases.
            g.setColor(Color.YELLOW);
            g.fillOval(centerX - 4*explosionFrameNumber,
                  centerY - 2*explosionFrameNumber,
                  8*explosionFrameNumber,
                  4*explosionFrameNumber);
            g.setColor(Color.RED);
            g.fillOval(centerX - 2*explosionFrameNumber,
                  centerY - explosionFrameNumber/2,
                  4*explosionFrameNumber,
                  explosionFrameNumber);
         }
      }
   } // end nested class Submarine


} // end class SubKiller

C:\Documents and Settings\keklein\REXX\NetRexx\bjcp7+  Thu 06/07/2012 15:07
 > cat SubKillerPanel.nrx
import java.awt.
import java.awt.event.
import javax.swing.


--  *
--  * This panel implements a simple arcade game in which the user tries to blow
--  * up a  " submarine "  (a black oval) by dropping  " depth charges "  (a red disk) from
--  * a  " boat "  (a blue roundrect).  The user moves the boat with the left- and
--  * right-arrow keys and drops the depth charge with the down-arrow key.
--  * The sub moves left and right erratically along the bottom of the panel.
--
class SubKillerPanel public extends JPanel

 properties  private
  timer = javax.swing.Timer null
  width = int 0
  boat = Boat null
  bomb = Bomb null
  sub = Submarine null
  --  *
  --     * The constructor sets the background color of the panel, creates the
  --     * timer, and adds a KeyListener, FocusListener, and MouseListener to the
  --     * panel.  These listeners, as well as the ActionListener for the timer
  --     * are defined by anonymous inner classes.  The timer will run only
  --     * when the panel has the input focus.
  --
--
method SubKillerPanel() public   --Constructor
    Do label CPC28
    setBackground(Color.GREEN)
    action = ActionListener ActionListener()
      Do label CPC31
--
method actionPerformed(evt=ActionEvent) public
        Do label CPC33
        if (boat <> null)  then
          Do label CPC35
          boat.updateForNewFrame()
          bomb.updateForNewFrame()
          sub.updateForNewFrame()
          End CPC35
        repaint()
        End CPC33
      End CPC31

    timer = Timer(30, action)

    addMouseListener( MouseAdapter()
      Do label CPC47
--
method mousePressed(evt=MouseEvent) public
        Do label CPC49
        requestFocus()
        End CPC49
      End CPC47
  )

    addFocusListener( FocusListener()
      Do label CPC56
--
method focusGained(evt=FocusEvent) public
        Do label CPC58
        timer.start()
        repaint()
        End CPC58
--
method focusLost(evt=FocusEvent) public
        Do label CPC63
        timer.stop()
        repaint()
        End CPC63
      End CPC56
  )

    addKeyListener( KeyAdapter()
      Do label CPC71
--
method keyPressed(evt=KeyEvent) public
        Do label CPC73
        code = int evt.getKeyCode()
        if (code == KeyEvent.VK_LEFT)  then
          Do label CPC76
          - = boat.centerX 15
          End CPC76
        else
         if (code == KeyEvent.VK_RIGHT)  then
          Do label CPC80
          + = boat.centerX 15
          End CPC80
        else
         if (code == KeyEvent.VK_DOWN)  then
          Do label CPC84
          if (bomb.isFalling == 0)  then bomb.isFalling = 1
          End CPC84
        End CPC73
      End CPC71
  )

    End CPC28


  --  *
  --     * The paintComponent() method draws the current state of the game.  It
  --     * draws a gray or cyan border around the panel to indicate whether or not
  --     * the panel has the input focus.  It draws the boat, sub, and bomb by
  --     * calling their respective draw() methods.
  --
--
method paintComponent(g=Graphics) public
    Do label CPC101
    super.paintComponent(g)
    if (boat == null)  then
      Do label CPC104
      width = getWidth()
      height = getHeight()
      boat = Boat()
      sub = Submarine()
      bomb = Bomb()
      End CPC104

    if (hasFocus())  then g.setColor(Color.CYAN)
    else

      Do label CPC114
      g.setColor(Color.RED)
      g.drawString("CLICK TO ACTIVATE", 20, 30)
      g.setColor(Color.GRAY)
      End CPC114
    g.drawRect(0,0,width-1,height-1)
    g.drawRect(1,1,width-3,height-3)
    g.drawRect(2,2,width-5,height-5)

    boat.draw(g)
    sub.draw(g)
    bomb.draw(g)

    End CPC101


  --  *
  --     * This nested class defines the boat.  Note that its constructor cannot
  --     * be called until the width of the panel is known\
  --
class Boat private

 properties  private
    centerX = int
    centerY = int
--
method Boat()    --Constructor
      Do label CPC138
      centerX = width/2
      centerY = 80
      End CPC138

 properties
  updateForNewFrame() = void null
      Do label CPC143
      (centerX < 0) centerX = =
      if 0 then g.setColor(Color.CYAN)
      else
       (centerX > width) centerX = =
       if width then g.setColor(Color.CYAN)
      End CPC143
--
method draw(g=Graphics) public
      Do label CPC148
      g.setColor(Color.BLUE)
      g.fillRoundRect(centerX - 40, centerY - 20, 80, 40, 20, 20)
      End CPC148


  --  *
  --     * This nested class defines the bomb.
  --
class Bomb private

 properties
    centerX = int
    centerY = int
        isFalling = boolean 0
--
method Bomb()    --Constructor
      Do label CPC163
      isFalling = 0
      End CPC163
  updateForNewFrame() = void null
      Do label CPC167
      if (isFalling)  then
        Do label CPC169
        if (centerY > height)  then
          Do label CPC171
          isFalling = 0
          End CPC171
        else
         if (Math.abs(centerX - sub.centerX) <= 36 && Math.abs(centerY - sub.centerY) <= 21)  then
          Do label CPC175
          sub.isExploding = 1
          sub.explosionFrameNumber = 1
          isFalling = 0
          End CPC175
        else

          Do label CPC181
          + = centerY 10
          End CPC181
        End CPC169
      End CPC167
--
method draw(g=Graphics) public
      Do label CPC187
      if (\ isFalling)  then
        Do label CPC189
        centerX = boat.centerX
        centerY = boat.centerY + 23
        End CPC189
      g.setColor(Color.RED)
      g.fillOval(centerX - 8, centerY - 8, 16, 16)
      End CPC187


  --  *
  --     * This nested class defines the sub.  Note that its constructor cannot
  --     * be called until the width of the panel is known\
  --
class Submarine private

 properties
    centerX = int
    centerY = int
  isMovingLeft = boolean 0
  isExploding = boolean 0
  explosionFrameNumber = int 0
--
method Submarine()    --Constructor
      Do label CPC210
      centerX = int (width*Math.random())
      centerY = height - 40
      isExploding = 0
      isMovingLeft = Math.random(< 0.5)
      End CPC210
  updateForNewFrame() = void null
      Do label CPC217
      if (isExploding)  then
        Do label CPC219
        explosionFrameNumber = explosionFrameNumber + 1
        if (explosionFrameNumber == 15)  then
          Do label CPC222
          centerX = int (width*Math.random())
          centerY = height - 40
          isExploding = 0
          isMovingLeft = Math.random(< 0.5)
          End CPC222
        End CPC219
      else

        Do label CPC230
        if (Math.random() < 0.04)  then
          Do label CPC232
          isMovingLeft = \ isMovingLeft
          End CPC232
        if (isMovingLeft)  then
          Do label CPC236
          - = centerX 5
          if (centerX <= 0)  then
            Do label CPC239
            centerX = 0
            isMovingLeft = 0
            End CPC239
          End CPC236
        else

          Do label CPC245
          + = centerX 5
          if (centerX > width)  then
            Do label CPC248
            centerX = width
            isMovingLeft = 1
            End CPC248
          End CPC245
        End CPC230
      End CPC217
--
method draw(g=Graphics) public
      Do label CPC256
      g.setColor(Color.BLACK)
      g.fillOval(centerX - 30, centerY - 15, 60, 30)
      if (isExploding)  then
        Do label CPC260
        g.setColor(Color.YELLOW)
        g.fillOval(centerX - 4*explosionFrameNumber, centerY - 2*explosionFrameNumber, 8*explosionFr
ameNumber, 4*explosionFrameNumber)
        g.setColor(Color.RED)
        g.fillOval(centerX - 2*explosionFrameNumber, centerY - explosionFrameNumber/2, 4*explosionFr
ameNumber, explosionFrameNumber)
        End CPC260
      End CPC256




C:\Documents and Settings\keklein\REXX\NetRexx\bjcp7+  Thu 06/07/2012 15:07
 > nrc SubKillerPanel
NetRexx portable processor, version NetRexx 3.01RC2, build 1-20110925-2337
Copyright (c) RexxLA, 2011.  All rights reserved.
Parts Copyright (c) IBM Corporation, 1995,2008.
Program SubKillerPanel.nrx
  === class SubKillerPanel ===
  18 +++   boat = Boat null
     +++   ^^^^
     +++ Warning: Variable name replaces the type whose short name is 'Boat'
  19 +++   bomb = Bomb null
     +++   ^^^^
     +++ Warning: Variable name replaces the type whose short name is 'Bomb'
    constructor SubKillerPanel()
  32 +++     action = ActionListener ActionListener()
     +++                             ^^^^^^^^^^^^^^
     +++ Error: The constructor 'ActionListener()' cannot be found in class 'java.awt.event.ActionLi
stener'
Compilation of 'SubKillerPanel.nrx' failed [4 classes, one error, 2 warnings]

C:\Documents and Settings\keklein\REXX\NetRexx\bjcp7+  Thu 06/07/2012 15:08


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: Is netrexxify ready for prime time?

alansam
I tried netrexify a while ago and found it couldn't convert anything to a working NetRexx program on the first pass; not even the simplest Hello World example.  A fundimental problem is its failure to recognize that methods marked static in Java must be similarly marked in NetRexx and this counts double for the main method.  Have you tried java2nrx?  It copes fairly well with most simple Java programs that I've tried it with.

Alan.

--
Can't tweet, won't tweet!

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Alan

--
Needs more cowbell.
Reply | Threaded
Open this post in threaded view
|

Re: Is netrexxify ready for prime time?

kenner

I think I have the 2 mixed up. Netrexxify really got turned around when I converted java source with nested classes. I'll try java2nrx


Kenneth Klein



Alan Sampson <[hidden email]>
Sent by: [hidden email]

06/08/2012 12:39 PM

Please respond to
IBM Netrexx <[hidden email]>

To
IBM Netrexx <[hidden email]>
cc
Subject
Re: [Ibm-netrexx] Is netrexxify ready for prime time?





I tried netrexify a while ago and found it couldn't convert anything to a working NetRexx program on the first pass; not even the simplest Hello World example.  A fundimental problem is its failure to recognize that methods marked static in Java must be similarly marked in NetRexx and this counts double for the main method.  Have you tried java2nrx?  It copes fairly well with most simple Java programs that I've tried it with.

Alan.

--
Can't tweet, won't tweet!
_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: Is netrexxify ready for prime time? Is java2nrx?

kenner
In reply to this post by alansam

I found a simple java program and ran it thru java2nrx. I fixed a few bugs but I am stuck on this one.

 > cat pencilapp.java.back
/* Generated from 'pencilapp.nrx' 2 Nov 2010 11:08:26 [v2.05] *//* Options: Crossref Decimal Java Lo
go Trace2 Verbose3 */public class pencilapp extends java.applet.Applet{private static final java.lan
g.String $0="pencilapp.nrx";

protected int x=new netrexx.lang.Rexx(0).toint();protected int y=new netrexx.lang.Rexx(0).toint();

public boolean mouseDrag(java.awt.Event e,int i,int j){
getGraphics().drawLine(x,y,i,j);
x=i;y=j;
return true;}

public boolean mouseDown(java.awt.Event e,int i,int j){
x=i;y=j;
return true;}

public static void main(java.lang.String argv[]){pencilapp p;java.awt.Frame f;
p=new pencilapp();
f=new java.awt.Frame("pencil test");
f.resize(400,300);
f.add("Center",(java.awt.Component)p);
f.show();return;}public pencilapp(){return;}}

C:\Documents and Settings\keklein\REXX\NetRexx\bin+  Tue 06/12/2012 10:20
 > cat pencilapp.nrx
class pencilapp public  extends java.applet.Applet
    properties private static -- constant
    theTitle = java.lang.String "pencilapp.nrx"
    properties -- protected
    x = int netrexx.lang.Rexx(0).toint()
    y = int netrexx.lang.Rexx(0).toint()
    method mouseDrag( e=java.awt.Event,  i=int,  j=int )  returns boolean
        getGraphics().drawLine(x, y, i, j)
        x = i
        y = j
        return true
    method mouseDown( e=java.awt.Event,  i=int,  j=int )  returns boolean
        x = i
        y = j
        return true

    method main( argv[] = java.lang.String ) static
        p = pencilapp
        f = java.awt.Frame
        p = pencilapp()
        f = java.awt.Frame("pencil test")
        f.resize(400, 300)
        f.add("Center", (java.awt.Component) p)
        f.show()
        return

    method pencilapp
        return

C:\Documents and Settings\keklein\REXX\NetRexx\bin+  Tue 06/12/2012 10:20
 > nrc pencilapp.nrx
NetRexx portable processor, version NetRexx 3.01RC2, build 1-20110925-2337
Copyright (c) RexxLA, 2011.  All rights reserved.
Parts Copyright (c) IBM Corporation, 1995,2008.
Program pencilapp.nrx
 17 +++     method main( argv[] = java.lang.String ) static
    +++                      ^
    +++ Error: An equals sign or comma is expected after an argument name
Compilation of 'pencilapp.nrx' failed [one error]


Alan Sampson <[hidden email]>
Sent by: [hidden email]

06/08/2012 12:39 PM

Please respond to
IBM Netrexx <[hidden email]>

To
IBM Netrexx <[hidden email]>
cc
Subject
Re: [Ibm-netrexx] Is netrexxify ready for prime time?





I tried netrexify a while ago and found it couldn't convert anything to a working NetRexx program on the first pass; not even the simplest Hello World example.  A fundimental problem is its failure to recognize that methods marked static in Java must be similarly marked in NetRexx and this counts double for the main method.  Have you tried java2nrx?  It copes fairly well with most simple Java programs that I've tried it with.

Alan.

--
Can't tweet, won't tweet!
_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/



_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|

Re: Is netrexxify ready for prime time? Is java2nrx?

rvjansen
Kenneth,

method main(argv=String[]) static

should do the trick.

best regards,

René.


On 2012-06-12 16:25, [hidden email] wrote:
> I found a simple java program and ran it thru java2nrx. I fixed a few
> bugs but I am stuck on this one.
>
>  17 +++ method main( argv[] = java.lang.String ) static
>  +++ ^
>  +++ Error: An equals sign or comma is expected after an argument
> name
>
> Compilation of 'pencilapp.nrx' failed [one error]

_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/