Int delta

hi experts,
I cannot find the path to delete the int delta in bi7.0
can any one help me.
give me steps how to delete int delta.
thanks
vijay.

Hi,
take a look:
Multiple Init Requests
Delete delta init in delta channel?
Regards
Andreas

Similar Messages

  • Cube 0PP_C03 consists DS 2LIS_04_P_ARBPL(with int. delta), 0PP_WCCP(full)?

    Hi,
    i have an cube 0pp_c03 having DS 2lis_04_p_arbpl have option full and int. delta update for info package AND 0pp_wccp with full update.
    what type of updation for each data source will be ideal?
    Is it possible to set delta for DS other than LO - ex: 0PP_WCCP?
    Best regards,
    dushyant.

    Thanks Francisco Milan and Shilpa for the links. Itu2019s very useful. But still I didnu2019t able to find the cause of the issue.
    My data source 2LIS_04_P_ARBPL is of ABR type and the update mode for KF is Summation. In the data source level, I am getting the values with before & after image (same entries one with +ve & another with u2013ve) and as I am using the u201CSummation as my update type for KF its getting nullified.
    Because of this reason I could not able to get the values in my report. Could any one pls help me on this as I am reaching the go-live date. I need to address this issue immediately. Thanks for all your inputs.
    Regards,
    Shanthi.

  • Int delta problem

    hi to all
            I am trying  load data into DSO 0crm_proh from the datasource 0crm_srv_process_h.  i cant do it it show up an error i have checked with all the target there are no data request is available.
    Delete init. request REQU_4EHGGTDUIKLI78GA0WUGE4V28 before running init. again with same selection
    help me in sloving this issue
    thank u
    gopu77

    Hi,
        irrespective of the load being Success or fail, a flag is been when schedule Init delta.so, it doesn't allows you to reschedule init delta again.to deselect
                                 Infopackage -
    >Scheduler menu--->Initialization Option for Source system-->Uncheck the falg
    and try to run init again.
    Best way is to run Full load first and then Init with the flag initialize without data transfer   set and then delta
    Thanks
    Sandeep

  • Custom graphics in java.awt.ScrollPane

    Hi all,
    I have to draw a custom created image in a scroll pane. As the image is very large I want to display it in a scroll pane. As parts of the image may change within seconds, and drawing the whole image is very time consuming (several seconds) I want to draw only the part of the image that is currently visible to the user.
    My idea: creating a new class that extends from java.awt.ScrollPane, overwrite the paint(Graphics) method and do the drawings inside. Unfortunately, it does not work. The background of the scoll pane is blue, but it does not show the red box (the current viewport is not shown in red).
    Below please find the source code that I am using:
    package graphics;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.ScrollPane;
    import java.awt.event.AdjustmentEvent;
    public class CMyComponent extends ScrollPane {
         /** <p>Listener to force a component to repaint when a scroll bar changes its
          * position.</p>
         private final class ScrollBarAdjustmentListener implements java.awt.event.AdjustmentListener {
              /** <p>The component to force to repaint.</p> */
              private final Component m_Target;
              /** <p>Default constructor.</p>
               * @param Target The component to force to repaint.
              private ScrollBarAdjustmentListener(Component Target) { m_Target = Target; }
              /** <p>Forces to component to repaint upon adjustment of the scroll bar.</p>
               *  @see java.awt.event.AdjustmentListener#adjustmentValueChanged(java.awt.event.AdjustmentEvent)
              public void adjustmentValueChanged(AdjustmentEvent e) { m_Target.paint(m_Target.getGraphics()); }
         public CMyComponent() {
              // Ensure that the component repaints upon changing of the scroll bars
              ScrollBarAdjustmentListener sbal = new ScrollBarAdjustmentListener(this);
              getHAdjustable().addAdjustmentListener(sbal);
              getVAdjustable().addAdjustmentListener(sbal);
         public void paint(Graphics g) {
              setBackground(Color.BLUE);
              g.setColor(Color.RED);
              g.fillRect(getScrollPosition().x, getScrollPosition().y, getViewportSize().width, getViewportSize().height);
         public final static void main(String[] args) {
              java.awt.Frame f = new java.awt.Frame();
              f.add(new CMyComponent());
              f.pack();
              f.setVisible(true);
    }

    Dear all,
    I used the last days and tried several things. I think now I have a quite good working solution (just one bug remains) and it is very performant. To give others a chance to see what I have done I post the source code of the main class (a canvas drawing and implementing scrolling) here. As soon as the sourceforge project is accepted, I will publish the whole sources at there. Enjoy. And if you have some idea for my last bug in getElementAtPixel(Point), then please tell me.
    package internetrail.graphics.hexgrid;
    import java.awt.Canvas;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Image;
    import java.awt.Point;
    import java.awt.Polygon;
    import java.awt.event.ComponentEvent;
    import java.awt.event.ComponentListener;
    import java.awt.geom.Area;
    import java.awt.image.BufferedImage;
    import java.util.WeakHashMap;
    import java.util.Map;
    /** <p>Hex grid view.</p>
    * <p>Visualizes a {@link IHexGridModel}.</p>
    * @version 0.1, 03.06.2006
    * @author Bjoern Wuest, Germany
    public final class CHexGridView extends Canvas implements ComponentListener, IHexGridElementListener {
         /** <p>Serial version unique identifier.</p> */
         private static final long serialVersionUID = -965902826101261530L;
         /** <p>Instance-constant parameter for the width of a hex grid element.</p> */
         public final int CONST_Width;
         /** <p>Instance-constant parameter for 1/4 of the width of a hex grid element.</p> */
         public final int CONST_Width1fourth;
         /** <p>Instance-constant parameter for 3/4 of the width of a hex grid element.</p> */
         public final int CONST_Width3fourth;
         /** <p>Instance-constant parameter for 1.5 times of the width of a hex grid element.</p> */
         public final int CONST_Width1dot5;
         /** <p>Instance-constant parameter for 4 times of the width of a hex grid element.</p> */
         public final int CONST_Widthquad;
         /** <p>Instance-constant parameter for the height of a hex grid element.</p> */
         public final int CONST_Height;
         /** <p>Instance-constant parameter for 1/2 of the height of a hex grid element.</p> */
         public final int CONST_Heighthalf;
         /** <p>Instance-constant parameter for the double height of a hex grid element.</p> */
         public final int CONST_Heightdouble;
         /** <p>The steepness of a side of the hex grid element (calculated for the upper left arc).</p> */
         public final double CONST_Steepness;
         /** <p>The model of this hex grid </p> */
         private final IHexGridModel m_Model;
         /** <p>A cache for already created images of the hex map.</p> */
         private final Map<Point, Image> m_Cache = new WeakHashMap<Point, Image>();
         /** <p>The graphical area to draw the selection ring around a hex element.</p> */
         private final Area m_SelectionRing;
         /** <p>The image of the selection ring around a hex element.</p> */
         private final BufferedImage m_SelectionRingImage;
         /** <p>The current position of the hex grid in pixels (top left visible corner).</p> */
         private Point m_ScrollPosition = new Point(0, 0);
         /** <p>Flag to define if a grid is shown ({@code true}) or not ({@code false}).</p> */
         private boolean m_ShowGrid = true;
         /** <p>Flag to define if the selected hex grid element should be highlighted ({@code true}) or not ({@code false}).</p> */
         private boolean m_ShowSelected = true;
         /** <p>The offset of hex grid elements shown on the screen, measured in hex grid elements.</p> */
         private Point m_CurrentOffset = new Point(0, 0);
         /** <p>The offset of the image shown on the screen, measured in pixels.</p> */
         private Point m_PixelOffset = new Point(0, 0);
         /** <p>The index of the currently selected hex grid element.</p> */
         private Point m_CurrentSelected = new Point(0, 0);
         /** <p>The width of a buffered pre-calculated image in pixel.</p> */
         private int m_ImageWidth;
         /** <p>The height of a buffered pre-calculated image in pixel.</p> */
         private int m_ImageHeight;
         /** <p>The maximum number of columns of hex grid elements to be shown at once on the screen.</p> */
         private int m_MaxColumn;
         /** <p>The maximum number of rows of hex grid elements to be shown at once on the screen.</p> */
         private int m_MaxRow;
         /** <p>Create a new hex grid view.</p>
          * <p>The hex grid view is bound to a {@link IHexGridModel} and registers at
          * that model to listen for {@link IHexGridElement} updates.</p>
          * @param Model The model backing this view.
         public CHexGridView(IHexGridModel Model) {
              // Set the model
              m_Model = Model;
              CONST_Width = m_Model.getElementsWidth();
              CONST_Height = m_Model.getElementsHeight();
              CONST_Width1fourth = CONST_Width/4;
              CONST_Width3fourth = CONST_Width*3/4;
              CONST_Width1dot5 = CONST_Width*3/2;
              CONST_Heighthalf = CONST_Height/2;
              CONST_Widthquad = CONST_Width*4;
              CONST_Heightdouble = CONST_Height*2;
              CONST_Steepness = (double)CONST_Heighthalf / CONST_Width1fourth;
              m_ImageWidth = getSize().width+CONST_Widthquad;
              m_ImageHeight = getSize().height+CONST_Heightdouble;
              m_MaxColumn = m_ImageWidth / CONST_Width3fourth;
              m_MaxRow = m_ImageHeight / CONST_Height;
              // Register this canvas for various notifications
              m_Model.addElementListener(this);
              addComponentListener(this);
              // Create the selection ring to highlight hex grid elements
              m_SelectionRing = new Area(new Polygon(new int[]{-1, CONST_Width1fourth-1, CONST_Width3fourth+1, CONST_Width+1, CONST_Width3fourth+1, CONST_Width1fourth-1}, new int[]{CONST_Heighthalf, -1, -1, CONST_Heighthalf, CONST_Height+1, CONST_Height+1}, 6));
              m_SelectionRing.subtract(new Area(new Polygon(new int[]{2, CONST_Width1fourth+2, CONST_Width3fourth-2, CONST_Width-2, CONST_Width3fourth-2, CONST_Width1fourth+2}, new int[]{CONST_Heighthalf, 2, 2, CONST_Heighthalf, CONST_Height-2, CONST_Height-2}, 6)));
              m_SelectionRingImage = new BufferedImage(CONST_Width, CONST_Height, BufferedImage.TYPE_INT_ARGB);
              Graphics2D g = m_SelectionRingImage.createGraphics();
              g.setColor(Color.WHITE);
              g.fill(m_SelectionRing);
         @Override public synchronized void paint(Graphics g2) {
              // Caculate the offset of indexes to show
              int offsetX = 2 * (m_ScrollPosition.x / CONST_Width1dot5) - 2;
              int offsetY = (int)(Math.ceil(m_ScrollPosition.y / CONST_Height) - 1);
              m_CurrentOffset = new Point(offsetX, offsetY);
              // Check if the image is in the cache
              Image drawing = m_Cache.get(m_CurrentOffset);
              if (drawing == null) {
                   // The image is not cached, so draw it
                   drawing = new BufferedImage(m_ImageWidth, m_ImageHeight, BufferedImage.TYPE_INT_ARGB);
                   Graphics2D g = ((BufferedImage)drawing).createGraphics();
                   // Draw background
                   g.setColor(Color.BLACK);
                   g.fillRect(0, 0, m_ImageWidth, m_ImageHeight);
                   // Draw the hex grid
                   for (int column = 0; column <= m_MaxColumn; column += 2) {
                        for (int row = 0; row <= m_MaxRow; row++) {
                             // Draw even column
                             IHexGridElement element = m_Model.getElementAt(offsetX + column, offsetY + row);
                             if (element != null) { g.drawImage(element.getImage(m_ShowGrid), (int)(column*(CONST_Width3fourth-0.5)), CONST_Height*row, null); }
                             // Draw odd column
                             element = m_Model.getElementAt(offsetX + column+1, offsetY + row);
                             if (element!= null) { g.drawImage(element.getImage(m_ShowGrid), (int)(column*(CONST_Width3fourth-0.5)+CONST_Width3fourth), CONST_Heighthalf*(row*2+1), null); }
                   // Put the image into the cache
                   m_Cache.put(m_CurrentOffset, drawing);
              // Calculate the position of the image to show
              offsetX = CONST_Width1dot5 + (m_ScrollPosition.x % CONST_Width1dot5);
              offsetY = CONST_Height + (m_ScrollPosition.y % CONST_Height);
              m_PixelOffset = new Point(offsetX, offsetY);
              g2.drawImage(drawing, -offsetX, -offsetY, null);
              // If the selected element should he highlighted, then do so
              if (m_ShowSelected) {
                   // Check if the selected element is on screen
                   if (isElementOnScreen(m_CurrentSelected)) {
                        // Correct vertical offset for odd columns
                        if ((m_CurrentSelected.x % 2 == 1)) { offsetY -= CONST_Heighthalf; }
                        // Draw the selection circle
                        g2.drawImage(m_SelectionRingImage, (m_CurrentSelected.x - m_CurrentOffset.x) * CONST_Width3fourth - offsetX - ((m_CurrentSelected.x + 1) / 2), (m_CurrentSelected.y - m_CurrentOffset.y) * CONST_Height - offsetY, null);
         @Override public synchronized void update(Graphics g) { paint(g); }
         public synchronized void componentResized(ComponentEvent e) {
              // Upon resizing of the component, adjust several pre-calculated values
              m_ImageWidth = getSize().width+CONST_Widthquad;
              m_ImageHeight = getSize().height+CONST_Heightdouble;
              m_MaxColumn = m_ImageWidth / CONST_Width3fourth;
              m_MaxRow = m_ImageHeight / CONST_Height;
              // And flush the cache
              m_Cache.clear();
         public void componentMoved(ComponentEvent e) { /* do nothing */ }
         public void componentShown(ComponentEvent e) { /* do nothing */ }
         public void componentHidden(ComponentEvent e) { /* do nothing */ }
         public synchronized void elementUpdated(IHexGridElement Element) {
              // Clear cache where the element may be contained at
              for (Point p : m_Cache.keySet()) { if (isElementInScope(Element.getIndex(), p, new Point(p.x + m_MaxColumn, p.y + m_MaxRow))) { m_Cache.remove(p); } }
              // Update the currently shown image if the update element is shown, too
              if (isElementOnScreen(Element.getIndex())) { repaint(); }
         /** <p>Returns the model visualized by this grid view.</p>
          * @return The model visualized by this grid view.
         public IHexGridModel getModel() { return m_Model; }
         /** <p>Returns the current selected hex grid element.</p>
          * @return The current selected hex grid element.
         public IHexGridElement getSelected() { return m_Model.getElementAt(m_CurrentSelected.x, m_CurrentSelected.y); }
         /** <p>Sets the current selected hex grid element by its index.</p>
          * <p>If the selected hex grid element should be highlighted and is currently
          * shown on the screen, then this method will {@link #repaint() redraw} this
          * component automatically.</p>
          * @param Index The index of the hex grid element to become the selected one.
          * @throws IllegalArgumentException If the index refers to a non-existing hex
          * grid element.
         public synchronized void setSelected(Point Index) throws IllegalArgumentException {
              // Check that the index is valid
              if ((Index.x < 0) || (Index.y < 0) || (Index.x > m_Model.getXElements()) || (Index.y > m_Model.getYElements())) { throw new IllegalArgumentException("There is no hex grid element with such index."); }
              m_CurrentSelected = Index;
              // If the element is on screen and should be highlighted, then repaint
              if (m_ShowSelected && isElementOnScreen(m_CurrentSelected)) { repaint(); }
         /** <p>Moves the visible elements to the left by the number of pixels.</p>
          * <p>To move the visible elements to the left by one hex grid element, pass
          * {@link #CONST_Width3fourth} as the parameter. The component will
          * automatically {@link #repaint()}.</p>
          * @param Pixels The number of pixels to move to the left.
          * @return The number of pixels moved to the left. This is always between 0
          * and {@code abs(Pixels)}.
         public synchronized int moveLeft(int Pixels) {
              int delta = m_ScrollPosition.x - Math.max(0, m_ScrollPosition.x - Math.max(0, Pixels));
              if (delta != 0) {
                   m_ScrollPosition.x -= delta;
                   repaint();
              return delta;
         /** <p>Moves the visible elements up by the number of pixels.</p>
          * <p>To move the visible elements up by one hex grid element, pass {@link
          * #CONST_Height} as the parameter. The component will automatically {@link
          * #repaint()}.</p>
          * @param Pixels The number of pixels to move up.
          * @return The number of pixels moved up. This is always between 0 and {@code
          * abs(Pixels)}.
         public synchronized int moveUp(int Pixels) {
              int delta = m_ScrollPosition.y - Math.max(0, m_ScrollPosition.y - Math.max(0, Pixels));
              if (delta != 0) {
                   m_ScrollPosition.y -= delta;
                   repaint();
              return delta;
         /** <p>Moves the visible elements to the right by the number of pixels.</p>
          * <p>To move the visible elements to the right by one hex grid element, pass
          * {@link #CONST_Width3fourth} as the parameter. The component will
          * automatically {@link #repaint()}.</p>
          * @param Pixels The number of pixels to move to the right.
          * @return The number of pixels moved to the right. This is always between 0
          * and {@code abs(Pixels)}.
         public synchronized int moveRight(int Pixels) {
              int delta = Math.min(m_Model.getXElements() * CONST_Width3fourth + CONST_Width1fourth - getSize().width, m_ScrollPosition.x + Math.max(0, Pixels)) - m_ScrollPosition.x;
              if (delta != 0) {
                   m_ScrollPosition.x += delta;
                   repaint();
              return delta;
         /** <p>Moves the visible elements down by the number of pixels.</p>
          * <p>To move the visible elements down by one hex grid element, pass {@link
          * #CONST_Height} as the parameter. The component will automatically {@link
          * #repaint()}.</p>
          * @param Pixels The number of pixels to move down.
          * @return The number of pixels moved down. This is always between 0 and
          * {@code abs(Pixels)}.
         public synchronized int moveDown(int Pixels) {
              int delta = Math.min(m_Model.getYElements() * CONST_Height + CONST_Heighthalf - getSize().height, m_ScrollPosition.y + Math.max(0, Pixels)) - m_ScrollPosition.y;
              if (delta != 0) {
                   m_ScrollPosition.y += delta;
                   repaint();
              return delta;
         /** <p>Checks if the hex grid element of the given index is currently
          * displayed on the screen (even just one pixel).</p>
          * <p>The intention of this method is to check if a {@link #repaint()} is
          * necessary or not.</p>
          * @param ElementIndex The index of the element to check.
          * @return {@code true} if the hex grid element of the given index is
          * displayed on the screen, {@code false} if not.
         public synchronized boolean isElementOnScreen(Point ElementIndex) { return isElementInScope(ElementIndex, m_CurrentOffset, new Point(m_CurrentOffset.x + m_MaxColumn, m_CurrentOffset.y + m_MaxRow)); }
         /** <p>Checks if the hex grid element of the given index is within the given
          * indexes.</p>
          * <p>The intention of this method is to check if a {@link #repaint()} is
          * necessary or not.</p>
          * @param ElementIndex The index of the element to check.
          * @param ReferenceIndexLeftTop The left top index of the area to check.
          * @param ReferenceIndexRightBottom The right bottom index of the area to check.
          * @return {@code true} if the hex grid element of the given index is within
          * the given area, {@code false} if not.
         public synchronized boolean isElementInScope(Point ElementIndex, Point ReferenceIndexLeftTop, Point ReferenceIndexRightBottom) { if ((ElementIndex.x >= ReferenceIndexLeftTop.x) && (ElementIndex.x <= ReferenceIndexRightBottom.x) && (ElementIndex.y >= ReferenceIndexLeftTop.y) && (ElementIndex.y <= (ReferenceIndexRightBottom.y))) { return true; } else { return false; } }
         /** <p>Return the {@link IHexGridElement hex grid element} shown at the given
          * pixel on the screen.</p>
          * <p><b>Remark: There seems to be a bug in retrieving the proper element,
          * propably caused by rounding errors and unprecise pixel calculations.</p>
          * @param P The pixel on the screen.
          * @return The {@link IHexGridElement hex grid element} shown at the pixel.
         public synchronized IHexGridElement getElementAtPixel(Point P) {
              // @FIXME Here seems to be some bugs remaining
              int dummy = 0; // Variable for warning to indicate that there is something to do :)
              // Calculate the pixel on the image, not on the screen
              int px = P.x + m_PixelOffset.x;
              int py = P.y + m_PixelOffset.y;
              // Determine the x-index of the column (is maybe decreased by one)
              int x = px / CONST_Width3fourth + m_CurrentOffset.x;
              // If the column is odd, then shift the y-pixel by half element height
              if ((x % 2) == 1) { py -= CONST_Heighthalf; }
              // Determine the y-index of the row (is maybe decreased by one)
              int y = py / CONST_Height + m_CurrentOffset.y;
              // Normative coordinates to a single element
              px -= (x - m_CurrentOffset.x) * CONST_Width3fourth;
              py -= (y - m_CurrentOffset.y) * CONST_Height;
              // Check if the normative pixel is in the first quarter of a column
              if (px < CONST_Width1fourth) {
                   // Adjustments to the index may be necessary
                   if (py < CONST_Heighthalf) {
                        // We are in the upper half of a hex-element
                        double ty = CONST_Heighthalf - CONST_Steepness * px;
                        if (py < ty) { x--; }
                   } else {
                        // We are in the lower half of a hex-element
                        double ty = CONST_Heighthalf + CONST_Steepness * px;
                        if (py > ty) {
                             x--;
                             y++;
              return m_Model.getElementAt(x, y);
    }Ah, just to give you some idea: I use this component to visualize a hex grid map with more than 1 million grid elements. And it works, really fast, and requires less than 10 MByte of memory.

  • Using Calendar.set() method problem

    Hi all,
    First of all sorry to bother with such a trivial(?) matter but I cannot solve it by myself.
    I have a piece of code which I simply want to handle the current date with the GregorianCalendar object so that the date would be set to the Calendar.SUNDAY (of the current week). Simple enough?
    Code as follows:
    import java.util.*;
    import java.text.*;
    public class Foo
    public static void main(String[] args)
         Foo foo = new Foo();
         Date newdate = foo.bar();
    public Date bar()
         GregorianCalendar m_calendar = new GregorianCalendar(new Locale("fi","FI"));
         m_calendar.setFirstDayOfWeek(Calendar.MONDAY);
         Date newDate = null;
         try
              m_calendar.setTime(new Date());
              System.out.println("Calendar='" + m_calendar.toString() + "'");
              m_calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);
              SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
              StringBuffer sb = new StringBuffer();
              sdf.format(m_calendar.getTime(), sb, new FieldPosition(0));
              System.out.println("Date in format (" + sdf.toPattern()          + ") = '" + sb.toString() + "'");
         catch(Exception e)
              e.printStackTrace();
         return m_calendar.getTime();
    This should work at least accoring to my understanding of the SDK documentation as follows with
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
    Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)
    Calendar='java.util.GregorianCalendar[time=1054636838494,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Europe/Helsinki",offset=7200000,dstSavings=3600000,useDaylight=true,transitions=118,lastRule=java.util.SimpleTimeZone[id=Europe/Helsinki,offset=7200000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2]],firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=2003,MONTH=5,WEEK_OF_YEAR=23,WEEK_OF_MONTH=1,DAY_OF_MONTH=3,DAY_OF_YEAR=154,DAY_OF_WEEK=3,DAY_OF_WEEK_IN_MONTH=1,AM_PM=1,HOUR=1,HOUR_OF_DAY=13,MINUTE=40,SECOND=38,MILLISECOND=494,ZONE_OFFSET=7200000,DST_OFFSET=3600000]'
    Date in format (yyyy.MM.dd) = '2003.06.08'
    Which is the sunday of this week. But as I run the same code with:
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1.06-020625-14:20)
    Java HotSpot(TM) Server VM (build 1.3.1 1.3.1.06-JPSE_1.3.1.06_20020625 PA2.0, mixed mode)
    Calendar='java.util.GregorianCalendar[time=1054636630703,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=java.util.SimpleTimeZone[id=Europe/Helsinki,offset=7200000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=2,startMonth=2,startDay=-1,startDayOfWeek=1,startTime=3600000,startTimeMode=2,endMode=2,endMonth=9,endDay=-1,endDayOfWeek=1,endTime=3600000,endTimeMode=2],firstDayOfWeek=2,minimalDaysInFirstWeek=4,ERA=1,YEAR=2003,MONTH=5,WEEK_OF_YEAR=23,WEEK_OF_MONTH=1,DAY_OF_MONTH=3,DAY_OF_YEAR=154,DAY_OF_WEEK=3,DAY_OF_WEEK_IN_MONTH=1,AM_PM=1,HOUR=1,HOUR_OF_DAY=13,MINUTE=37,SECOND=10,MILLISECOND=703,ZONE_OFFSET=7200000,DST_OFFSET=3600000]'
    Date in format (yyyy.MM.dd) = '2003.06.01'
    Which is sunday of the previous week and incorrect in my opinion. The latter result is run on HP-UX B.11.11 U 9000/800 and first on NT.
    Any ideas why this is happening? Thanks in advance!
    Greets, Janne

    Thanks for your answer!
    The problem is that I have to work with this older SDK version. :) But I got it solved by using the roll method with the following syntax:
    int delta = [dayToSet] - m_calendar.get(Calendar.DAY_OF_WEEK);
    in which the delta is of course the difference (negative or positive to the current day of the week)
    and then using the roll call:
    m_calendar.roll(Calendar.DAY_OF_WEEK, delta);
    which doesn't alter the current week. So this works if someone else has a similar problem with the version 1.3.1
    Greets, Janne

  • Getting objects to move between PCs

    After CS 150, I find myself back in the world of Java. I recently learned a neat language called Processing (a.k.a. Proce55ing), and I am one of the coders (and am way rusty to be of much use at this point) for a really cool project.
    I'm wondering if I can nag you with some questions on java.net.*. I need to get some objects passed around between 3 PCs. I need to know about latency issues. Basically, we've got Java doing OpenGL graphics on 6 projectors powered by 3 computers. Imagine each PC having a really wide screen... when a autonomous creature gets to the edge of one PC, it needs to continue its thang on the next PC... move fluidly.
    I've checked out some Java.net.* sample code on sun's site. Specifically their KnockKnock Server. However, its multithread support is for interacting with clients on a one-on-one basis... not like a chat-room style environment. So, I don't even have any sample code for a ultra-basic Java Chat Room.... nor do I know how to pass anything but a string to the server, or to the client.
    There are ways to use my limited knowledge to do what I want to do... just pass a string, and have the server store that into a variable which is accessible by every server thread. Then, create a loop in main that keeps searching through that array of strings to pass them off to the PC... the string would have the coordinate information of the autonomous creature, and create a new one of that object with those Vec3f point. However, latency is a key issue, and it would be easiest if I could just pass an object to the server (in this case: a SimpleVehicle) along with an intended target computer, and then that computer would get that vehicle to add to its array of SimpleVehicles. The important thing is speed, so it might be best to have every computer have a client<->server connection with each other... I get utterly baffled reading the Java Docs. But, I seem to understand code when I see it (I can only reverse engineer). I especially understand the KnockKnock Server and MultiClient code on the Sun's Java Networking Tutorial.
    Any pointers to which methods I need to learn (I already realize I'm going to need to downcast the SimpleVehicle object back into a SimpleVehicle after it gets sent). Thanks a million.

    Ok, try this.
    The simplistic application sends colored balls between instances of itself which can be on any machine on your network.
    As a ball reaches the left side of the window it is in, it gets sent to the machine on it's left (if any), likewise if it reaches the right side of the window it gets sent to the machine on it's right. If there is no machine on the side the ball is trying to go, it rebounds within the window it is in.
    So, a simple test is to run three instances on the same machine, one is regarded as one the left on as on the right and one as in the middle
    To start the one on the left:
    java Ziniman1 8000 -right localhost:8001
    To start the one in the middle:
    java Ziniman1 8001 -left localhost:8000 -right localhost:8002
    To start the one on the right:
    java Ziniman1 8002 -left localhost:8001
    Note: You need to start these pretty quickly one after the other or the socket creation will time out. I'll leave that to you to fix ;)
    Once the apps are running, move them so they are next to each other, left to right (the port numbers used as the server port are in the JFrame title).
    To get create a ball, just click on one of the white panels, use the radio buttons at the bottom to change size/color/direction of the new balls.
    Once you've got the hang of the thing, try moving some instances to other machnes.
    Enjoy!
    import java.io.*;
    import java.net.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    public class Ziniman1
         static final String LEFT= "Left";
         static final String RIGHT= "Right";
         static class Ball
              implements Serializable
              public int x= -1;
              public int y;
              public int size= 10;
              private Color mColor;
              public Ball(Color color) { mColor= color; }
              public Ball(Color color, int y) { mColor= color; this.y= y; }
              public Color getColor() { return mColor; }
              public String toString() { return "(" +x +"," +y +") x " +size; }
         static interface DirectionalListener
              public void left(Ball ball);
              public void right(Ball ball);
         static class Directional
              private DirectionalListener mListener= null;
              public final void setListener(DirectionalListener listener) {
                   mListener= listener;
              protected final void fireLeft(Ball ball)
                   if (mListener != null)
                        mListener.left(ball);
              protected final void fireRight(Ball ball)
                   if (mListener != null)
                        mListener.right(ball);
         static class Server
              extends Directional
              public Server(final int port)
                   new Thread() {
                        public void run() {
                             try {
                                  ServerSocket listenSocket= new ServerSocket(port);
                                  System.err.println("Server listening on port " +port);
                                  while (true)
                                       connect(listenSocket.accept());
                             catch (Exception e) {
                                  e.printStackTrace();
                   }.start();
              private synchronized void connect(final Socket socket)
                   Thread thread= new Thread() {
                        public void run() {
                             try {
                                  ObjectInputStream is=
                                       new ObjectInputStream(socket.getInputStream());
                                  while (true) {
                                       String side= (String) is.readObject();
                                       Ball ball= (Ball) is.readObject();
                                       if (side.equals(RIGHT))
                                            fireLeft(ball);
                                       else
                                            fireRight(ball);
                             catch (Exception e) {
                                  e.printStackTrace();
                   thread.setDaemon(true);
                   thread.start();
         static class Client
              private ObjectOutputStream mOs;
              private String mSide;
              public Client(String host, int port, String side)
                   throws Exception
                   mSide= side;
                   Socket socket= new Socket(host, port);
                   mOs= new ObjectOutputStream(socket.getOutputStream());
                   System.err.println(
                        mSide +" client connected to " +host +":" +port);
              private void send(Ball ball)
                   try {
                        mOs.writeObject(mSide);
                        mOs.writeObject(ball);
                   catch (Exception e) {
                        e.printStackTrace();
         static abstract class BallPanel
              extends JPanel
              public void paint(Graphics g)
                   g.setColor(Color.WHITE);
                   g.fillRect(0, 0, getSize().width, getSize().height);
                   Iterator balls= getBalls();
                   while (balls.hasNext()) {
                        Ball ball= (Ball) balls.next();
                        g.setColor(ball.getColor());
                        g.fillOval(ball.x, ball.y, ball.size, ball.size);
              public Dimension getPreferredSize() {
                   return new Dimension(300, 240);
              public abstract Iterator getBalls();
         static class Gui
              extends Directional
              private Runnable mUpdater= new Runnable() {
                   public void run() { mBallPanel.repaint(); }
              private ArrayList mLeft= new ArrayList();
              private ArrayList mRight= new ArrayList();
              private ArrayList mBalls= new ArrayList();
              private BallPanel mBallPanel= new BallPanel() {
                   public Iterator getBalls() {
                        return mBalls.iterator();
              public Gui(String title)
                   final JRadioButton red= new JRadioButton("Red");
                   final JRadioButton green= new JRadioButton("Green");
                   final JRadioButton blue= new JRadioButton("Blue");
                   ButtonGroup group= new ButtonGroup();
                   group.add(red);
                   group.add(blue);
                   group.add(green);
                   final JRadioButton large= new JRadioButton("Large");
                   final JRadioButton small= new JRadioButton("Small");
                   group= new ButtonGroup();
                   group.add(large);
                   group.add(small);
                   final JRadioButton left= new JRadioButton("Left");
                   final JRadioButton right= new JRadioButton("Right");
                   group= new ButtonGroup();
                   group.add(left);
                   group.add(right);
                   red.setSelected(true);
                   small.setSelected(true);
                   right.setSelected(true);
                   mBallPanel.addMouseListener(new MouseAdapter() {
                        public void mousePressed(MouseEvent e) {
                             Ball ball= new Ball(
                                  red.isSelected() ? Color. RED :
                                  blue.isSelected() ? Color.BLUE : Color.GREEN);
                             ball.x= e.getX();
                             ball.y= e.getY();
                             ball.size= large.isSelected() ? 20 : 10;
                             if (left.isSelected())
                                  left(ball);
                             else
                                  right(ball);
                   JPanel panel= new JPanel(new FlowLayout(FlowLayout.LEFT, 4, 4));
                   panel.add(red);
                   panel.add(blue);
                   panel.add(green);
                   panel.add(large);
                   panel.add(small);
                   panel.add(left);
                   panel.add(right);
                   JFrame frame= new JFrame(title);
                   frame.getContentPane().add(mBallPanel, BorderLayout.CENTER);
                   frame.getContentPane().add(panel, BorderLayout.SOUTH);
                   frame.pack();
                   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                   frame.setVisible(true);
              public synchronized void move(int delta)
                   Iterator left= mLeft.iterator();
                   while (left.hasNext()) {
                        Ball ball= (Ball) left.next();
                        ball.x -= delta;
                        if (ball.x <= 0) {
                             left.remove();
                             mBalls.remove(ball);
                             fireLeft(ball);
                   Iterator right= mRight.iterator();
                   while (right.hasNext()) {
                        Ball ball= (Ball) right.next();
                        ball.x += delta;
                        if (ball.x >= (mBallPanel.getSize().width -ball.size)) {
                             right.remove();
                             mBalls.remove(ball);
                             fireRight(ball);
                   SwingUtilities.invokeLater(mUpdater);
              public synchronized void left(Ball ball)
                   mLeft.add(ball);
                   mBalls.add(ball);
                   if (ball.x < 0)
                        ball.x= mBallPanel.getSize().width -(ball.size/2);
                   SwingUtilities.invokeLater(mUpdater);
              public synchronized void right(Ball ball)
                   mRight.add(ball);
                   mBalls.add(ball);
                   if (ball.x < 0)
                        ball.x= ball.size/2;
                   SwingUtilities.invokeLater(mUpdater);
         static class Controller
              public Controller(
                   final Gui gui, final Server server,
                   final Client left, final Client right)
                   gui.setListener(new DirectionalListener() {
                        // Ball reached the left
                        public void left(Ball ball)
                             ball.x= -1;
                             if (left == null)
                                  gui.right(ball);
                             else
                                  left.send(ball);
                        // Ball reached the right
                        public void right(Ball ball)
                             ball.x= -1;
                             if (right == null)
                                  gui.left(ball);
                             else
                                  right.send(ball);
                   server.setListener(new DirectionalListener() {
                        // Ball came from the left
                        public void left(Ball ball) {
                             gui.right(ball);
                        // Ball came from the right
                        public void right(Ball ball) {
                             gui.left(ball);
                   Thread thread= new Thread() {
                        public void run() {
                             while (true) {
                                  try { sleep(100); }
                                  catch (InterruptedException e) { }
                                  gui.move(10);
                   thread.setDaemon(true);
                   thread.start();
         private static final String USAGE=
              "Usage: java Ziniman1 " +
              "<server port> [-left <host:port>] [-right <host:port>]";
            public static void main(String[] argv)
              throws Exception
              if (argv.length < 1)
                   barf();
              int leftPort= -1;
              int rightPort= -1;
              String leftHost= "localhost";
              String rightHost= "localhost";
              int serverPort= Integer.parseInt(argv[0]);
              for (int i= 1; i< argv.length; i += 2) {
                   if (argv.equals("-left")) {
                        if (argv.length == i+1)
                             barf();
                        String url= argv[i+1];
                        if (url.indexOf(":") < 0)
                             barf();
                        leftHost= url.substring(0, url.indexOf(":"));
                        leftPort= Integer.parseInt(url.substring(url.indexOf(":")+1));
                   else if (argv[i].equals("-right")) {
                        if (argv.length == i+1)
                             barf();
                        String url= argv[i+1];
                        if (url.indexOf(":") < 0)
                             barf();
                        rightHost= url.substring(0, url.indexOf(":"));
                        rightPort= Integer.parseInt(url.substring(url.indexOf(":")+1));
              new Controller(
                   new Gui("Balls @ " +serverPort),
                   new Server(serverPort),
                   leftPort > 0 ? new Client(leftHost, leftPort, LEFT) : null,
                   rightPort > 0 ? new Client(rightHost, rightPort, RIGHT) : null);
         private static void barf()
              System.err.println(USAGE);
              System.exit(-1);

  • Please take a look?

    Hello :) My friend is doing his thesis & he's stuck with this program. Unfortunately I don't have Java installed on this comp (in work) so I'm not much use but I was hoping someone here could point him in the right direction. Here goes...
    Description: Basic paddle ball type game.
    This example midlet demonstrates how to use threads and the Canvas class. It implements
    a simple paddle ball type game. It demonstrates how to use a clipping region to implement
    graphics more effeciently.
    It should animate at a constant speed on all phones, although it may appear
    jerky on devices with very restricted processing resources.
    @created den 21 mars 2002
    COPYRIGHT All rights reserved Sony Ericsson Mobile Communications AB 2003.
    The software is the copyrighted work of Sony Ericsson Mobile Communications AB.
    The use of the software is subject to the terms of the end-user license
    agreement which accompanies or is included with the software. The software is
    provided "as is" and Sony Ericsson specifically disclaim any warranty or
    condition whatsoever regarding merchantability or fitness for a specific
    purpose, title or non-infringement. No warranty of any kind is made in
    relation to the condition, suitability, availability, accuracy, reliability,
    merchantability and/or non-infringement of the software provided herein.
    package midp.demo;
    import java.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    * Basic Ball and Paddle game. Use arrow keys to move paddle.
    * Demonstrates multi-threading, animation, event handling.
    * @see MIDlet
    public class PaddleBall extends MIDlet implements CommandListener {
    * Constant for white color
    private static final int COLOR_WHITE = 0xFFFFFF;
    * Constant for black color
    private static final int COLOR_BLACK = 0x000000;
    * The game speed (in milliseconds)
    private final int GAME_SPEED = 5;
    * The main game screen
    private GameFrame mainFrame;
    * The title screen
    private Form titleScreen;
    * The results screen
    private Form statsScreen;
    * The number of milliseconds the user has been playing this game
    private long elapsedTime;
    * The ball object for this game
    private Ball myBall;
    * The paddle object for this game
    private Paddle myPaddle;
    * True if game has not started or player lost
    private boolean gameOver = true;
    * How many games have been played
    private int numGames;
    * Reference to Display
    private Display myDisplay;
    public PaddleBall() {
    myDisplay = Display.getDisplay(this);
    * Create main game screen
    mainFrame = new GameFrame();
    * Create title screen
    titleScreen = new Form("Paddle Ball");
    titleScreen.append(new StringItem(null,
    "The classic arcade game, now on your mobile device!"));
    titleScreen.setCommandListener(this);
    titleScreen.addCommand(new Command("START", Command.OK, 1));
    * Create results screen
    statsScreen = new Form("Results");
    statsScreen.setCommandListener(PaddleBall.this);
    statsScreen.addCommand(new Command("AGAIN?", Command.OK, 1));
    * Begin the application, show its frame
    protected void startApp() {
    myDisplay.setCurrent(titleScreen);
    * Application is being terminated, kill threads
    protected void pauseApp() {
    gameOver = true;
    myBall = null;
    myPaddle = null;
    * Clean up application
    protected void destroyApp(boolean unconditional) {
    gameOver = true;
    * Start the game
    public void commandAction(Command c, Displayable d) {
    * Create ball and paddle threads
    myBall = new Ball();
    myPaddle = new Paddle();
    * Get the starting time
    elapsedTime = System.currentTimeMillis();
    * Set the initial ball and paddle positions
    myBall.setUp();
    myPaddle.setUp();
    * Set the screen
    myDisplay.setCurrent(mainFrame);
    * Start the thread
    gameOver = false;
    myBall.start();
    myPaddle.start();
    * The main Screen for this game
    class GameFrame extends Canvas {
    * Canvas receives all key events
    public void keyPressed(int keyCode) {
    int gameAction = 0;
    try {
    gameAction = getGameAction(keyCode);
    } catch (Exception e) {
    if (gameAction == LEFT) {
    myPaddle.move(-2 * GAME_SPEED);
    } else if (gameAction == RIGHT) {
    myPaddle.move(2 * GAME_SPEED);
    return;
    * Clear the game screen
    private void clear(Graphics g) {
    g.setColor(0xFFFFFF);
    g.fillRect(0, 0, getWidth(), getHeight());
    * Paint the game screen
    public void paint(Graphics g) {
    synchronized (g) {
    * Clear the screen
    clear(g);
    g.setColor(0x000000);
    * Paint the ball and paddle
    g.fillRect(myPaddle.x, myPaddle.y, myPaddle.WIDTH,
    myPaddle.HEIGHT);
    g.fillArc(myBall.x, myBall.y, myBall.SIZE,
    myBall.SIZE, 0, 360);
    * The ball thread
    class Ball extends Thread {
    * The ball diameter
    public final int SIZE = mainFrame.getHeight() / 15;
    * The sign of the x component of the velocity
    private int xDir = 1;
    * The sign of the y component of the velocity
    private int yDir = 1;
    * X position of ball
    int x;
    * Y position of ball
    int y;
    * Create a ball
    public Ball() {
    setUp();
    * Set starting position
    void setUp() {
    x = mainFrame.getWidth() / 2;
    y = mainFrame.getHeight() / 10;
    * Loop to run thread, loops until game over
    public void run() {
    while (!gameOver) {
    * Sleep for animation delay
    try {
    Thread.sleep(150 - 10 * GAME_SPEED);
    } catch (Exception e) {
    return;
    int oldX = x;
    int oldY = y;
    * Recalculate x position
    int xPos = x + xDir * GAME_SPEED;
    if (((xPos+SIZE) <= mainFrame.getWidth())
    && (xPos >= 0)) {
    x = xPos;
    } else {
    xDir *= -1;
    AlertType.WARNING.playSound(myDisplay);
    * Recalculate y position
    int yPos = y + yDir * GAME_SPEED;
    if ((yPos >= 0) &&
    ((yPos + SIZE) <=
    (mainFrame.getHeight() - myPaddle.HEIGHT))) {
    y = yPos;
    } else if ((yPos + SIZE) >
    (mainFrame.getHeight() - myPaddle.HEIGHT)) {
    * Bounce off paddle
    if ((xPos <= (myPaddle.x + myPaddle.WIDTH))
    && ((xPos + SIZE) >= myPaddle.x)) {
    yDir *= -1;
    AlertType.INFO.playSound(myDisplay);
    * Player loses
    } else {
    gameOver = true;
    * Get statistic information
    elapsedTime = System.currentTimeMillis()
    - elapsedTime;
    numGames++;
    statsScreen.append(new StringItem("Game " +
    numGames + " over", "Time: " +
    (elapsedTime/1000) + " seconds"));
    * Show the statistics screen
    myDisplay.setCurrent(statsScreen);
    return;
    } else if (yPos < 0) {
    yDir *= -1;
    AlertType.WARNING.playSound(myDisplay);
    mainFrame.repaint(Math.min(oldX, x), Math.min(oldY, y),
    Math.abs(x-oldX) + SIZE,
    Math.abs(y-oldY) + SIZE);
    * The game paddle thread
    class Paddle extends Thread {
    * Paddle width
    public final int WIDTH = mainFrame.getWidth() / 6;
    * Paddle height
    public final int HEIGHT = mainFrame.getHeight() / 15;
    * X position
    int x;
    * Y position
    int y;
    * Create a new paddle
    public Paddle() {
    setUp();
    * Initialize starting position
    void setUp() {
    x = mainFrame.getWidth() / 2 - WIDTH / 2;
    y = mainFrame.getHeight() - HEIGHT;
    * Loop to run paddlethread, loops until game over
    public void run() {
    while (!gameOver) {
    try {
    Thread.sleep(10);
    } catch (Exception e) {
    return;
    * Move paddle right/left
    void move(int delta) {
    int oldX = x;
    int xPos = x + delta;
    if (((xPos + WIDTH) <= mainFrame.getWidth())
    && (xPos >= 0)) {
    x = xPos;
    mainFrame.repaint(Math.min(oldX, x), y,
    Math.abs(x-oldX) + WIDTH, HEIGHT);
    }

    Let me do you a favor. With this, even you don't have JDK installed, you can help your friend.
    PaddleBall.java:4: package javax.microedition.lcdui does not exist
    import javax.microedition.lcdui.*;
    ^
    PaddleBall.java:5: package javax.microedition.midlet does not exist
    import javax.microedition.midlet.*;
    ^
    PaddleBall.java:13: cannot resolve symbol
    symbol  : class MIDlet
    location: class midp.demo.PaddleBall
    public class PaddleBall extends MIDlet implements CommandListener {
                                    ^
    PaddleBall.java:13: cannot resolve symbol
    symbol  : class CommandListener
    location: class midp.demo.PaddleBall
    public class PaddleBall extends MIDlet implements CommandListener {
                                                      ^
    PaddleBall.java:165: cannot resolve symbol
    symbol  : class Canvas
    location: class midp.demo.PaddleBall.GameFrame
    class GameFrame extends Canvas {
                            ^
    PaddleBall.java:191: cannot resolve symbol
    symbol  : class Graphics
    location: class midp.demo.PaddleBall.GameFrame
    private void clear(Graphics g) {
                       ^
    PaddleBall.java:200: cannot resolve symbol
    symbol  : class Graphics
    location: class midp.demo.PaddleBall.GameFrame
    public void paint(Graphics g) {
                      ^
    PaddleBall.java:38: cannot resolve symbol
    symbol  : class Form
    location: class midp.demo.PaddleBall
    private Form titleScreen;
            ^
    PaddleBall.java:43: cannot resolve symbol
    symbol  : class Form
    location: class midp.demo.PaddleBall
    private Form statsScreen;
            ^
    PaddleBall.java:73: cannot resolve symbol
    symbol  : class Display
    location: class midp.demo.PaddleBall
    private Display myDisplay;
            ^
    PaddleBall.java:130: cannot resolve symbol
    symbol  : class Command
    location: class midp.demo.PaddleBall
    public void commandAction(Command c, Displayable d) {
                              ^
    PaddleBall.java:130: cannot resolve symbol
    symbol  : class Displayable
    location: class midp.demo.PaddleBall
    public void commandAction(Command c, Displayable d) {
                                         ^
    PaddleBall.java:77: cannot resolve symbol
    symbol  : variable Display
    location: class midp.demo.PaddleBall
    myDisplay = Display.getDisplay(this);
                ^
    PaddleBall.java:87: cannot resolve symbol
    symbol  : class Form
    location: class midp.demo.PaddleBall
    titleScreen = new Form("Paddle Ball");
                      ^
    PaddleBall.java:88: cannot resolve symbol
    symbol  : class StringItem
    location: class midp.demo.PaddleBall
    titleScreen.append(new StringItem(null,
                           ^
    PaddleBall.java:91: cannot resolve symbol
    symbol  : class Command
    location: class midp.demo.PaddleBall
    titleScreen.addCommand(new Command("START", Command.OK, 1));
                               ^
    PaddleBall.java:91: cannot resolve symbol
    symbol  : variable Command
    location: class midp.demo.PaddleBall
    titleScreen.addCommand(new Command("START", Command.OK, 1));
                                                ^
    PaddleBall.java:96: cannot resolve symbol
    symbol  : class Form
    location: class midp.demo.PaddleBall
    statsScreen = new Form("Results");
                      ^
    PaddleBall.java:98: cannot resolve symbol
    symbol  : class Command
    location: class midp.demo.PaddleBall
    statsScreen.addCommand(new Command("AGAIN?", Command.OK, 1));
                               ^
    PaddleBall.java:98: cannot resolve symbol
    symbol  : variable Command
    location: class midp.demo.PaddleBall
    statsScreen.addCommand(new Command("AGAIN?", Command.OK, 1));
                                                 ^
    PaddleBall.java:175: cannot resolve symbol
    symbol  : method getGameAction (int)
    location: class midp.demo.PaddleBall.GameFrame
    gameAction = getGameAction(keyCode);
                 ^
    PaddleBall.java:179: cannot resolve symbol
    symbol  : variable LEFT
    location: class midp.demo.PaddleBall.GameFrame
    if (gameAction == LEFT) {
                      ^
    PaddleBall.java:182: cannot resolve symbol
    symbol  : variable RIGHT
    location: class midp.demo.PaddleBall.GameFrame
    } else if (gameAction == RIGHT) {
                             ^
    PaddleBall.java:194: cannot resolve symbol
    symbol  : method getWidth ()
    location: class midp.demo.PaddleBall.GameFrame
    g.fillRect(0, 0, getWidth(), getHeight());
                     ^
    PaddleBall.java:194: cannot resolve symbol
    symbol  : method getHeight ()
    location: class midp.demo.PaddleBall.GameFrame
    g.fillRect(0, 0, getWidth(), getHeight());
                                 ^
    PaddleBall.java:362: cannot resolve symbol
    symbol  : method getWidth ()
    location: class midp.demo.PaddleBall.GameFrame
    public final int WIDTH = mainFrame.getWidth() / 6;
                                      ^
    PaddleBall.java:367: cannot resolve symbol
    symbol  : method getHeight ()
    location: class midp.demo.PaddleBall.GameFrame
    public final int HEIGHT = mainFrame.getHeight() / 15;
                                       ^
    PaddleBall.java:229: cannot resolve symbol
    symbol  : method getHeight ()
    location: class midp.demo.PaddleBall.GameFrame
    public final int SIZE = mainFrame.getHeight() / 15;
                                     ^
    PaddleBall.java:264: cannot resolve symbol
    symbol  : method getWidth ()
    location: class midp.demo.PaddleBall.GameFrame
    x = mainFrame.getWidth() / 2;
                 ^
    PaddleBall.java:265: cannot resolve symbol
    symbol  : method getHeight ()
    location: class midp.demo.PaddleBall.GameFrame
    y = mainFrame.getHeight() / 10;
                 ^
    PaddleBall.java:291: cannot resolve symbol
    symbol  : method getWidth ()
    location: class midp.demo.PaddleBall.GameFrame
    if (((xPos+SIZE) <= mainFrame.getWidth())
                                 ^
    PaddleBall.java:297: package AlertType does not exist
    AlertType.WARNING.playSound(myDisplay);
             ^
    PaddleBall.java:306: cannot resolve symbol
    symbol  : method getHeight ()
    location: class midp.demo.PaddleBall.GameFrame
    (mainFrame.getHeight() - myPaddle.HEIGHT))) {
              ^
    PaddleBall.java:310: cannot resolve symbol
    symbol  : method getHeight ()
    location: class midp.demo.PaddleBall.GameFrame
    (mainFrame.getHeight() - myPaddle.HEIGHT)) {
              ^
    PaddleBall.java:318: package AlertType does not exist
    AlertType.INFO.playSound(myDisplay);
             ^
    PaddleBall.java:332: cannot resolve symbol
    symbol  : class StringItem
    location: class midp.demo.PaddleBall.Ball
    statsScreen.append(new StringItem("Game " +
                           ^
    PaddleBall.java:345: package AlertType does not exist
    AlertType.WARNING.playSound(myDisplay);
             ^
    PaddleBall.java:347: cannot resolve symbol
    symbol  : method repaint (int,int,int,int)
    location: class midp.demo.PaddleBall.GameFrame
    mainFrame.repaint(Math.min(oldX, x), Math.min(oldY, y),
             ^
    PaddleBall.java:391: cannot resolve symbol
    symbol  : method getWidth ()
    location: class midp.demo.PaddleBall.GameFrame
    x = mainFrame.getWidth() / 2 - WIDTH / 2;
                 ^
    PaddleBall.java:392: cannot resolve symbol
    symbol  : method getHeight ()
    location: class midp.demo.PaddleBall.GameFrame
    y = mainFrame.getHeight() - HEIGHT;
                 ^
    PaddleBall.java:417: cannot resolve symbol
    symbol  : method getWidth ()
    location: class midp.demo.PaddleBall.GameFrame
    if (((xPos + WIDTH) <= mainFrame.getWidth())
                                    ^
    PaddleBall.java:421: cannot resolve symbol
    symbol  : method repaint (int,int,int,int)
    location: class midp.demo.PaddleBall.GameFrame
    mainFrame.repaint(Math.min(oldX, x), y,
             ^
    42 errors

  • Please take a look? (Pong)

    Hello :) My friend is doing his thesis & he's stuck with this program. Apparently it's not compiling. Unfortunately I don't have Java installed on this comp (in work) so I'm not much use but I was hoping someone here could point him in the right direction. Here goes...
    Description: Basic paddle ball type game.
    This example midlet demonstrates how to use threads and the Canvas class. It implements
    a simple paddle ball type game. It demonstrates how to use a clipping region to implement
    graphics more effeciently.
    It should animate at a constant speed on all phones, although it may appear
    jerky on devices with very restricted processing resources.
    @created den 21 mars 2002
    COPYRIGHT All rights reserved Sony Ericsson Mobile Communications AB 2003.
    The software is the copyrighted work of Sony Ericsson Mobile Communications AB.
    The use of the software is subject to the terms of the end-user license
    agreement which accompanies or is included with the software. The software is
    provided "as is" and Sony Ericsson specifically disclaim any warranty or
    condition whatsoever regarding merchantability or fitness for a specific
    purpose, title or non-infringement. No warranty of any kind is made in
    relation to the condition, suitability, availability, accuracy, reliability,
    merchantability and/or non-infringement of the software provided herein.
    package midp.demo;
    import java.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    * Basic Ball and Paddle game. Use arrow keys to move paddle.
    * Demonstrates multi-threading, animation, event handling.
    * @see MIDlet
    public class PaddleBall extends MIDlet implements CommandListener {
    * Constant for white color
    private static final int COLOR_WHITE = 0xFFFFFF;
    * Constant for black color
    private static final int COLOR_BLACK = 0x000000;
    * The game speed (in milliseconds)
    private final int GAME_SPEED = 5;
    * The main game screen
    private GameFrame mainFrame;
    * The title screen
    private Form titleScreen;
    * The results screen
    private Form statsScreen;
    * The number of milliseconds the user has been playing this game
    private long elapsedTime;
    * The ball object for this game
    private Ball myBall;
    * The paddle object for this game
    private Paddle myPaddle;
    * True if game has not started or player lost
    private boolean gameOver = true;
    * How many games have been played
    private int numGames;
    * Reference to Display
    private Display myDisplay;
    public PaddleBall() {
    myDisplay = Display.getDisplay(this);
    * Create main game screen
    mainFrame = new GameFrame();
    * Create title screen
    titleScreen = new Form("Paddle Ball");
    titleScreen.append(new StringItem(null,
    "The classic arcade game, now on your mobile device!"));
    titleScreen.setCommandListener(this);
    titleScreen.addCommand(new Command("START", Command.OK, 1));
    * Create results screen
    statsScreen = new Form("Results");
    statsScreen.setCommandListener(PaddleBall.this);
    statsScreen.addCommand(new Command("AGAIN?", Command.OK, 1));
    * Begin the application, show its frame
    protected void startApp() {
    myDisplay.setCurrent(titleScreen);
    * Application is being terminated, kill threads
    protected void pauseApp() {
    gameOver = true;
    myBall = null;
    myPaddle = null;
    * Clean up application
    protected void destroyApp(boolean unconditional) {
    gameOver = true;
    * Start the game
    public void commandAction(Command c, Displayable d) {
    * Create ball and paddle threads
    myBall = new Ball();
    myPaddle = new Paddle();
    * Get the starting time
    elapsedTime = System.currentTimeMillis();
    * Set the initial ball and paddle positions
    myBall.setUp();
    myPaddle.setUp();
    * Set the screen
    myDisplay.setCurrent(mainFrame);
    * Start the thread
    gameOver = false;
    myBall.start();
    myPaddle.start();
    * The main Screen for this game
    class GameFrame extends Canvas {
    * Canvas receives all key events
    public void keyPressed(int keyCode) {
    int gameAction = 0;
    try {
    gameAction = getGameAction(keyCode);
    } catch (Exception e) {
    if (gameAction == LEFT) {
    myPaddle.move(-2 * GAME_SPEED);
    } else if (gameAction == RIGHT) {
    myPaddle.move(2 * GAME_SPEED);
    return;
    * Clear the game screen
    private void clear(Graphics g) {
    g.setColor(0xFFFFFF);
    g.fillRect(0, 0, getWidth(), getHeight());
    * Paint the game screen
    public void paint(Graphics g) {
    synchronized (g) {
    * Clear the screen
    clear(g);
    g.setColor(0x000000);
    * Paint the ball and paddle
    g.fillRect(myPaddle.x, myPaddle.y, myPaddle.WIDTH,
    myPaddle.HEIGHT);
    g.fillArc(myBall.x, myBall.y, myBall.SIZE,
    myBall.SIZE, 0, 360);
    * The ball thread
    class Ball extends Thread {
    * The ball diameter
    public final int SIZE = mainFrame.getHeight() / 15;
    * The sign of the x component of the velocity
    private int xDir = 1;
    * The sign of the y component of the velocity
    private int yDir = 1;
    * X position of ball
    int x;
    * Y position of ball
    int y;
    * Create a ball
    public Ball() {
    setUp();
    * Set starting position
    void setUp() {
    x = mainFrame.getWidth() / 2;
    y = mainFrame.getHeight() / 10;
    * Loop to run thread, loops until game over
    public void run() {
    while (!gameOver) {
    * Sleep for animation delay
    try {
    Thread.sleep(150 - 10 * GAME_SPEED);
    } catch (Exception e) {
    return;
    int oldX = x;
    int oldY = y;
    * Recalculate x position
    int xPos = x + xDir * GAME_SPEED;
    if (((xPos+SIZE) <= mainFrame.getWidth())
    && (xPos >= 0)) {
    x = xPos;
    } else {
    xDir *= -1;
    AlertType.WARNING.playSound(myDisplay);
    * Recalculate y position
    int yPos = y + yDir * GAME_SPEED;
    if ((yPos >= 0) &&
    ((yPos + SIZE) <=
    (mainFrame.getHeight() - myPaddle.HEIGHT))) {
    y = yPos;
    } else if ((yPos + SIZE) >
    (mainFrame.getHeight() - myPaddle.HEIGHT)) {
    * Bounce off paddle
    if ((xPos <= (myPaddle.x + myPaddle.WIDTH))
    && ((xPos + SIZE) >= myPaddle.x)) {
    yDir *= -1;
    AlertType.INFO.playSound(myDisplay);
    * Player loses
    } else {
    gameOver = true;
    * Get statistic information
    elapsedTime = System.currentTimeMillis()
    - elapsedTime;
    numGames++;
    statsScreen.append(new StringItem("Game " +
    numGames + " over", "Time: " +
    (elapsedTime/1000) + " seconds"));
    * Show the statistics screen
    myDisplay.setCurrent(statsScreen);
    return;
    } else if (yPos < 0) {
    yDir *= -1;
    AlertType.WARNING.playSound(myDisplay);
    mainFrame.repaint(Math.min(oldX, x), Math.min(oldY, y),
    Math.abs(x-oldX) + SIZE,
    Math.abs(y-oldY) + SIZE);
    * The game paddle thread
    class Paddle extends Thread {
    * Paddle width
    public final int WIDTH = mainFrame.getWidth() / 6;
    * Paddle height
    public final int HEIGHT = mainFrame.getHeight() / 15;
    * X position
    int x;
    * Y position
    int y;
    * Create a new paddle
    public Paddle() {
    setUp();
    * Initialize starting position
    void setUp() {
    x = mainFrame.getWidth() / 2 - WIDTH / 2;
    y = mainFrame.getHeight() - HEIGHT;
    * Loop to run paddlethread, loops until game over
    public void run() {
    while (!gameOver) {
    try {
    Thread.sleep(10);
    } catch (Exception e) {
    return;
    * Move paddle right/left
    void move(int delta) {
    int oldX = x;
    int xPos = x + delta;
    if (((xPos + WIDTH) <= mainFrame.getWidth())
    && (xPos >= 0)) {
    x = xPos;
    mainFrame.repaint(Math.min(oldX, x), y,
    Math.abs(x-oldX) + WIDTH, HEIGHT);
    }

    Cross-post
    http://forum.java.sun.com/thread.jspa?threadID=5160243&tstart=0

  • Creating an Image from whats already on screen?

    http://carroll1.cc.edu/~tpatters/Scribble.html
    Above is the link to an applet I've been writing for a few days. I'm fairly new to Java and am using this applet to teach myself concepts as I dig them up. Right now when the page is moved, or the application is resized, or anything is drawn over it I lose the image that has been drawn. I'm trying to correct this by creating an offscreen image duplicating what is on screen in mousePressed. How do I grab what has already been drawn as an image? I've tried making it so it initially draws to an offscreen image and drawing that image in mouseReleased, but that doesn't let me see what is being drawn as it is happening. If I draw offscreen and update every iteration is runs horribly slow. I've also tried drawing offscreen and onscreen at the same time, but that too slows everything down.
    Here is the source code, I've been tinkering around all day so it is kinda messy and some things are commented out...
    import javax.swing.border.*;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.util.StringTokenizer;
    public class TPScribble extends JApplet implements AdjustmentListener, ActionListener
         private JLabel lblRed = new JLabel("Red");
         private JLabel lblGreen = new JLabel("Green");
         private JLabel lblBlue = new JLabel("Blue");
         private JScrollBar red,green,blue,size;
         private JButton whiteBack= new JButton("White");
         private JButton currentBack= new JButton("Current Color");
         private JButton info= new JButton("Info");
         private JButton psychoColors= new JButton("Auto-Rainbow");
         private JButton gradient= new JButton("Set Gradient");
         private JButton drawG=new JButton("Draw Gradient");
         private JButton redraw=new JButton("Redraw");
         private int r,gr,b, intsize=16, undoCounter=0;
         private TitledBorder titleBorder = new TitledBorder("Color Chooser");
         private Color color = new Color(128,128,128);
         boolean cycle = false;
         boolean setGrad = false;
         private int cycleRed, cycleGreen, cycleBlue;
         private int[] gradientStart = new int[3];
         private int[] gradientEnd = new int[3];
         private Graphics offscreen;
         //private Dimension dimension = new Dimension();
         private Image image;
         private Image[] undoImage = new Image[5];
         ScribblePanel scribblePanel = new ScribblePanel();
         Brush brush = new Brush();
    public static void main(String[] args)
    JFrame frame = new JFrame("TP Scribble");
    TPScribble applet = new TPScribble();
    frame.getContentPane().add(applet, BorderLayout.CENTER);
    applet.init();
    applet.start();
    frame.setSize(800, 640);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    public void adjustmentValueChanged(AdjustmentEvent e)
         r=red.getValue();
         cycleRed=r;
         gr=green.getValue();
         cycleGreen=gr;
         b=blue.getValue();
         cycleBlue=b;
         intsize=size.getValue();
         lblRed.setText("Red ("+(r+1)+")");
         lblGreen.setText("Green ("+(gr+1)+")");
         lblBlue.setText("Blue ("+(b+1)+")");
         color = new Color(r,gr,b);
         cycle=false;
         brush.updateBrush(color,intsize);
    public void actionPerformed(ActionEvent e)
         if (e.getSource()==whiteBack)
              scribblePanel.setBackColor(Color.white);
         else if (e.getSource() == currentBack)
              scribblePanel.setBackColor(color);
         else if (e.getSource() == info)
              JOptionPane.showMessageDialog(null, "Created by Thom Patterson\n\nLeft Click - Paint Brush\nRight Click - Draw Line\nShift + Left Click - Draw Line","Information",JOptionPane.INFORMATION_MESSAGE);
         else if (e.getSource() == psychoColors)
              int choice = JOptionPane.showConfirmDialog(null, "This will automatically cycle your\ncolors until a slider is moved\n\nProceed?", "Info",JOptionPane.YES_NO_OPTION);
              if (choice==0)
                   cycle=true;
         else if (e.getSource() == gradient)
         {boolean valid = false;
               boolean inside = true;
               do
               inside=true;
               String startGradient = JOptionPane.showInputDialog("Enter Starting Color as an r,g,b value\n\nColor Values lie between 0 and 255\n\nExample: 120,255,17");
               String endGradient = JOptionPane.showInputDialog("Enter Ending Color as an r,g,b value\n\nColor Values lie between 0 and 255\n\nExample: 120,255,17");
               StringTokenizer startToken = new StringTokenizer(startGradient, ",");
               StringTokenizer endToken = new StringTokenizer(endGradient, ",");
               for (int c=0; c<3 ; c++)
                    gradientStart[c]=Integer.parseInt(startToken.nextToken());
              for (int c=0; c<3 ; c++)
                   gradientEnd[c]=Integer.parseInt(endToken.nextToken());
              for (int c=0; c<3; c++)
                   if (gradientStart[c]>255 || gradientStart[c]<0 || gradientEnd[c]>255 || gradientEnd[c]<0)
                   JOptionPane.showMessageDialog(null, "Your numbers were invalid, try again","Error",JOptionPane.INFORMATION_MESSAGE);
                        inside=false;
              if (inside==true)
                   valid=true;     
                   setGrad=true;
              while (valid==false);
         else if (e.getSource()==drawG)
              if (setGrad == false)
                   JOptionPane.showMessageDialog(null, "Please set a Gradient first","Error",JOptionPane.INFORMATION_MESSAGE);
              else if (setGrad == true)
                   scribblePanel.drawGradient(gradientStart, gradientEnd);
         else if (e.getSource()==redraw)
              //scribblePanel.update();
    public void init()
         red = new JScrollBar(0,128,1,0,255);
         green = new JScrollBar(0,128,1,0,255);
         blue = new JScrollBar(0,128,1,0,255);
         size = new JScrollBar(1,16,1,1,50);
         JPanel p1 = new JPanel();
         p1.setLayout(new GridLayout(1,3));
         p1.setBorder(titleBorder);
         JPanel p2 = new JPanel();
         p2.setLayout(new BorderLayout());
         p2.add(new JLabel("Size"), BorderLayout.NORTH);
         p2.add(size, BorderLayout.CENTER);
         JPanel p3 = new JPanel();
         p3.add(info);
         p3.add(whiteBack);
         p3.add(currentBack);
         p3.add(gradient);
         p3.add(drawG);
         p3.add(redraw);
         JPanel p4 = new JPanel();
         p4.setLayout(new GridLayout(4,1));
         p4.add(lblRed);
         p4.add(lblGreen);     
         p4.add(lblBlue);
         p4.add(new JLabel("Cycling Colors"));
         JPanel p5 = new JPanel();
         p5.setLayout(new GridLayout(4,1));
         p5.add(red);
         p5.add(green);
         p5.add(blue);
         p5.add(psychoColors);
         p1.add(p4);
         p1.add(brush);
         p1.add(p5);
         red.addAdjustmentListener(this);
         green.addAdjustmentListener(this);
         blue.addAdjustmentListener(this);
         size.addAdjustmentListener(this);
         whiteBack.addActionListener(this);
         currentBack.addActionListener(this);
         info.addActionListener(this);
         psychoColors.addActionListener(this);
         gradient.addActionListener(this);
         drawG.addActionListener(this);
         redraw.addActionListener(this);
         getContentPane().add(p1, BorderLayout.SOUTH);
         getContentPane().add(p2, BorderLayout.EAST);
         getContentPane().add(p3, BorderLayout.NORTH);
         getContentPane().add(scribblePanel, BorderLayout.CENTER);
    class ScribblePanel extends JPanel implements MouseListener, MouseMotionListener
    {      private Point lineStart = new Point(0, 0);
         private Graphics z,gg;
         public ScribblePanel()
              addMouseListener(this);
              addMouseMotionListener(this);
         public void setBackColor(Color xcolor)
              z = getGraphics();
              z.setColor(xcolor);
              z.fillRect(0,0,getWidth(),getHeight());
              z.dispose();
         public void drawGradient(int[] starter, int[] ender)
              setBackColor(Color.white);
              int delta = (int)(getWidth()/255);
              z=getGraphics();
              cycleRed=ender[0];
              cycleGreen=ender[1];
              cycleBlue=ender[2];
              r=starter[0];
              gr=starter[1];
              b=starter[2];
              for (int c=0;c<getWidth();c+=delta)
                   color = new Color(r,gr,b);
                   z.setColor(color);
                   z.fillRect(c,0,delta,getHeight());
                   if (r==cycleRed)
                   else if (r<cycleRed)
                   {r++;}
                   else if (r>cycleRed)
                   {r--;}
                   if (gr==cycleGreen)
                   else if (gr<cycleGreen)
                   {gr++;}
                   else if (gr>cycleGreen)
                   {gr--;}
                   if (b==cycleBlue)
                   else if (b<cycleBlue)
                   {b++;}
                   else if (b>cycleBlue)
                   {b--;}
              z.dispose();
         public void mouseClicked(MouseEvent e)
              image = createImage(getWidth(), getHeight());
              z = image.getGraphics();
              gg=getGraphics();
              if (cycle==true)
                   cycleColor();
              if (e.isMetaDown()|| e.isShiftDown())
                   z.setColor(color);
                   z.drawLine(lineStart.x, lineStart.y, e.getX(), e.getY());
              else
                   z.setColor(color);
                   z.fillOval(e.getX() - (intsize/2), e.getY() - (intsize/2), intsize, intsize);
              lineStart.move(e.getX(), e.getY());
              gg.drawImage(image,0,0,this);
              image = createImage(getWidth(), getHeight());
              offscreen[undoCounter]=image.getGraphics();
              offscreen[undoCounter].fillOval(0,0,100,255);
              undoCounter++;
              if (undoCounter == 5)
                   undoCounter=0;*/
              gg.dispose();
              z.dispose();
         public void mouseEntered(MouseEvent e)
         public void mouseExited(MouseEvent e)
         public void mouseReleased(MouseEvent e)
         public void mousePressed(MouseEvent e)//maybe add undo here...
              lineStart.move(e.getX(), e.getY());
         public void mouseDragged(MouseEvent e)
              //image = createImage(getWidth(), getHeight());
              //z = image.getGraphics();
              gg=getGraphics();
              if (cycle==true)
                   cycleColor();
              if (e.isMetaDown() || e.isShiftDown())
                   // z.setColor(color);
                   //z.drawLine(lineStart.x, lineStart.y, e.getX(), e.getY());
                   gg.setColor(color);
                   gg.drawLine(lineStart.x, lineStart.y, e.getX(), e.getY());
              else
                   //z.setColor(color);
                   //z.fillOval(e.getX() - (intsize/2), e.getY() - (intsize/2), intsize, intsize);
                   gg.setColor(color);
                   gg.fillOval(e.getX() - (intsize/2), e.getY() - (intsize/2), intsize, intsize);
              lineStart.move(e.getX(), e.getY());
              //z.drawImage(undoImage[0],0,0,this);
              //gg.drawImage(image,0,0,this);
              gg.dispose();
              //z.dispose();
         public void paintComponent(Graphics g)
              if (image == null)
              else
                   g.drawImage(image,0,0,this);
         public void update(Graphics g)
              repaint();
         public void cycleColor()
              if (r==cycleRed && gr==cycleGreen && b==cycleBlue)
                   cycleRed=(int)(Math.random()*255);
                   cycleGreen=(int)(Math.random()*255);
                   cycleBlue=(int)(Math.random()*255);
              if (r==cycleRed)
              else if (r<cycleRed)
              {r++;}
              else if (r>cycleRed)
              {r--;}
              if (gr==cycleGreen)
              else if (gr<cycleGreen)
              {gr++;}
              else if (gr>cycleGreen)
              {gr--;}
              if (b==cycleBlue)
              else if (b<cycleBlue)
              {b++;}
              else if (b>cycleBlue)
              {b--;}
              color = new Color(r,gr,b);
              brush.updateBrush(color, intsize);
              lblRed.setText("Red ("+(r+1)+")");
              lblGreen.setText("Green ("+(gr+1)+")");
              lblBlue.setText("Blue ("+(b+1)+")");
         public void mouseMoved(MouseEvent e)
    class Brush extends JPanel
    private Graphics l;
         public Brush()
         public void updateBrush(Color bcolor, int bintsize)
              l=getGraphics();
              l.setColor(getBackground());
              l.fillRect(0,0,getWidth(),getHeight());
              l.setColor(bcolor);
              l.fillOval(getWidth()/2 - (bintsize/2),getHeight()/2 - (bintsize/2), bintsize, bintsize);
              l.dispose();

    I made a similar app myself, and here is a snippet from inside the draw method of my custom shape        // draws only last segment if in the process of creating the shape
            if (perm) {
                for (int ndx = 2; ndx < numCoords; ndx += 2) {
                    g2.draw(new Line2D.Float(pointCoords[ndx - 2],
                     pointCoords[ndx - 1], pointCoords[ndx], pointCoords[ndx + 1]));
            else {
                g2.draw(new Line2D.Float(pointCoords[numCoords - 4],
                 pointCoords[numCoords - 3], pointCoords[numCoords - 2],
                 pointCoords[numCoords - 1]));
            }as you can see, I only draw the last little segment while the user is drawing the shape (this keeps it fast), but when it is completed, the draw method will draw the entire thing. By calling the draw method both on mouseDragged and in the paintComponent of the canvas, the desired effect is achieved.

  • Key Bindings using the arrow keys

    Following is some code that allows you to move a component around the screen using the arrow keys. I've noticed a problem and I'm just wondering if its Java or my keyboard.
    Lets start with an example that works:
    Press the down and right keys. Then press either the up or left key. The image moves proving that it supports 3 keys.
    Now for the problem:
    Press the up and left keys. Then press either the down or right key. Three things to notice:
    a) the direction doesn't change when the third key is pressed
    b) no output is displayed, so the ActionListener is not being invoked
    c) after a short time, the program starts beeping
    Now try rerunning the code after removing the comments that assign the key bindings to the "a, s, d, f" keys. Redo the above test and it works even if all four keys are pressed.
    I don't remember this problem when I wrote the code a while ago, but I did recently get a cheap new keyboard so I'm just wondering if the problem is my keyboard or whether its a quirk with Java.
    You can download Duke from here:
    http://java.sun.com/docs/books/tutorial/uiswing/examples/components/LayeredPaneDemoProject/src/components/images/dukeWaveRed.gif
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class KeyboardNavigationProblem implements ActionListener
         private JComponent component;
         private int deltaX;
         private int deltaY;
         private Timer timer;
         private int keysPressed;
         private InputMap inputMap;
         public KeyboardNavigationProblem(JComponent component, int delay)
              this.component = component;
              this.deltaX = deltaX;
              this.deltaY = deltaY;
              timer = new Timer(delay, this);
              timer.setInitialDelay( 0 );
              inputMap = component.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
         public void addAction(int keyCode, String description, int deltaX, int deltaY)
              new NavigationAction(keyCode, description, deltaX, deltaY);
         public void updateDeltaX(int delta)
              deltaX += delta;
         public void updateDeltaY(int delta)
              deltaY += delta;
         public void actionPerformed(ActionEvent e)
              int componentWidth = component.getSize().width;
              int componentHeight = component.getSize().height;
              Dimension parentSize = component.getParent().getSize();
              int parentWidth  = parentSize.width;
              int parentHeight = parentSize.height;
              //  Determine next X position
              int nextX = Math.max(component.getLocation().x + deltaX, 0);
              if ( nextX + componentWidth > parentWidth)
                   nextX = parentWidth - componentWidth;
              //  Determine next Y position
              int nextY = Math.max(component.getLocation().y + deltaY, 0);
              if ( nextY + componentHeight > parentHeight)
                   nextY = parentHeight - componentHeight;
              //  Move the component
              component.setLocation(nextX, nextY);
         class NavigationAction extends AbstractAction implements ActionListener
              private int deltaX;
              private int deltaY;
              private KeyStroke pressedKeyStroke;
              private boolean listeningForKeyPressed;
              public NavigationAction(int keyCode, String description, int deltaX, int deltaY)
                   super(description);
                   this.deltaX = deltaX;
                   this.deltaY = deltaY;
                   pressedKeyStroke = KeyStroke.getKeyStroke(keyCode, 0, false);
                   KeyStroke releasedKeyStroke = KeyStroke.getKeyStroke(keyCode, 0, true);
                   inputMap.put(pressedKeyStroke, getValue(Action.NAME));
                   inputMap.put(releasedKeyStroke, getValue(Action.NAME));
                   component.getActionMap().put(getValue(Action.NAME), this);
                   listeningForKeyPressed = true;
              public void actionPerformed(ActionEvent e)
                   if (listeningForKeyPressed)
                        updateDeltaX( deltaX );
                        updateDeltaY( deltaY );
                        inputMap.remove(pressedKeyStroke);
                        listeningForKeyPressed = false;
                           if (keysPressed == 0)
                                timer.start();
                     keysPressed++;
                   else // listening for key released
                        updateDeltaX( -deltaX );
                        updateDeltaY( -deltaY );
                        inputMap.put(pressedKeyStroke, getValue(Action.NAME));
                        listeningForKeyPressed = true;
                        keysPressed--;
                           if (keysPressed == 0)
                                timer.stop();
                   System.out.println(KeyboardNavigationProblem.this.deltaX + " : "
                   + KeyboardNavigationProblem.this.deltaY);
         public static void main(String[] args)
              JPanel contentPane = new JPanel();
              contentPane.setLayout( null );
              JLabel duke = new JLabel( new ImageIcon("dukewavered.gif") );
              duke.setSize( duke.getPreferredSize() );
              duke.setLocation(100, 100);
              contentPane.add( duke );
              KeyboardNavigationProblem navigation = new KeyboardNavigationProblem(duke, 100);
              navigation.addAction(KeyEvent.VK_LEFT, "zLeft", -5, 0);
              navigation.addAction(KeyEvent.VK_RIGHT, "zRight", 5, 0);
              navigation.addAction(KeyEvent.VK_UP, "zUp", 0, -5);
              navigation.addAction(KeyEvent.VK_DOWN, "zDown", 0, 5);
    //          navigation.addAction(KeyEvent.VK_A, "zLeft", -5, 0);
    //          navigation.addAction(KeyEvent.VK_S, "zRight", 5, 0);
    //          navigation.addAction(KeyEvent.VK_D, "zUp", 0, -5);
    //          navigation.addAction(KeyEvent.VK_F, "zDown", 0, 5);
              JFrame frame = new JFrame();
              frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
              frame.setContentPane( contentPane);
              frame.setSize(800, 600);
              frame.setLocationRelativeTo( null );
              frame.setVisible(true);
    }

    if you hold down left and right (so it doesn't move), down works, but not up.
    hold up/down, right works but not left.Yes, the problem only seems to be when the up and left in combination with the right or down key is pressed.
    num lock off - use the number pad arrow keys and all works OK Thats interesting, I didn't notice that. Although it just confuses the issue as to what the problem is.
    So it appears to me that:
    a) left + up + down, and
    b) left + up + right
    are special key combinations that are intercepted by either the OS or the JVM. Do these key combinations ring a bell to anybody?
    I'm use JDK1.4.2 on XP. I wonder if other OS will have the same problem?
    Again, this isn't a real, problem, just more of a curiosity. Thanks,

  • How do I access objects from the original Thread?

    I have this simple JApplet that just makes a circle bounce around the screen. Here it is:
    import java.awt.Color;
    import javax.swing.JApplet;
    import java.awt.Graphics;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseEvent;
    public class TestApplet3 extends JApplet implements MouseListener {
        private int lastX;          // x coordinate of circle
        private int lastY;          // y coordinate of circle
        private int d = 15;          // diameter of circle
        public void paint(Graphics g) {
        public void init() {
            addMouseListener(this);
        public void mouseClicked(MouseEvent event) {
            Graphics gx = this.getGraphics();
            for (int x = 0, y = 0, count = 0, horiz = 2, vert = 2, k = 2; count < 1000; x = x + horiz, y = y + vert, count++) {
                if ((x + d) >= 350) {
                    horiz = -horiz;
                if ((x <= 0) && (horiz < 0)) {
                    horiz = -horiz;
                if ((y + d) >= 200) {
                    vert = -vert;
                if ((y <= 0) && (vert < 0)) {
                    vert = -vert;
                gx.setColor(Color.WHITE);
                gx.fillOval(lastX, lastY, d, d);
                gx.setColor(Color.RED);
                lastX = x;
                lastY = y;
                gx.fillOval(lastX, lastY, d, d);
                try {
                    Thread.sleep(20);
                } catch (Exception ex) {
                    System.out.println(ex.getMessage());
        public void mouseEntered(MouseEvent event) {
        public void mouseExited(MouseEvent event) {
        public void mousePressed(MouseEvent event) {
        public void mouseReleased(MouseEvent event) {
    }But now I'd like to change it so that when the mouse is clicked a new Thread is spawned to run the code within the mouseClicked method..... this will allow multiple circles to bounce around and will also keep the applet responsive to new mouse clicks... so I've tried changing it below:
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    package runninggraph;
    * @author epuknol
    import java.awt.Color;
    import javax.swing.JApplet;
    import java.awt.Graphics;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseEvent;
    public class TestApplet3 extends JApplet implements MouseListener, Runnable {
        private int lastX;          // x coordinate of circle
        private int lastY;          // y coordinate of circle
        private int d = 15;          // diameter of circle
        public void paint(Graphics g) {
        public void init() {
            addMouseListener(this);
        public void run() {
            Graphics gx = this.getGraphics();
            for (int x = 0, y = 0, count = 0, horiz = 2, vert = 2, k = 2; count < 1000; x = x + horiz, y = y + vert, count++) {
                if ((x + d) >= 350) {
                    horiz = -horiz;
                if ((x <= 0) && (horiz < 0)) {
                    horiz = -horiz;
                if ((y + d) >= 200) {
                    vert = -vert;
                if ((y <= 0) && (vert < 0)) {
                    vert = -vert;
                gx.setColor(Color.WHITE);
                gx.fillOval(lastX, lastY, d, d);
                gx.setColor(Color.RED);
                lastX = x;
                lastY = y;
                gx.fillOval(lastX, lastY, d, d);
                try {
                    Thread.sleep(20);
                } catch (Exception ex) {
                    System.out.println(ex.getMessage());
        public void mouseClicked(MouseEvent event) {
            (new Thread(new TestApplet())).start();       
        public void mouseEntered(MouseEvent event) {
        public void mouseExited(MouseEvent event) {
        public void mousePressed(MouseEvent event) {
        public void mouseReleased(MouseEvent event) {
    }but this doesn't work - I think because the this.getGraphics() doesn't refer back to the same object ..... I've tried some other things too - like defining the Graphics gx as a class variable and initializing it before spawning the new Thread ... but I can't access gx using that technique either.
    Can somebody please help me get where I'm trying to go?
    Thanks.

    Aw heck, got bored. For instance, this draws a bunch of balls without a direct call to Thread anything:
    BouncingCircles.java
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Point;
    import java.awt.RenderingHints;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.util.ArrayList;
    import java.util.List;
    import javax.swing.JPanel;
    import javax.swing.Timer;
    * creates a JPanel that draws bouncing circles within it. 
    * @author Pete
    public class BouncingCircles {
      private static final int DELAY = 15;
      private static final int DIAMETER = 15;
      private static final int DELTA = 5;
      List<Ball> ballList = new ArrayList<Ball>(); // list of all balls
      private JPanel mainPanel = new JPanel() {
        @Override
        protected void paintComponent(Graphics g) {
          super.paintComponent(g);
          myPaint(g);
      // Swing Timer that tells the balls to move and tells the JPanel to then draw them
      private Timer sTimer = new Timer(DELAY, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          timerAction(e);
      public BouncingCircles() {
        mainPanel.setPreferredSize(new Dimension(400, 400));
        mainPanel.addMouseListener(new MouseAdapter() {
          @Override
          // add new ball with each mouse press
          public void mousePressed(MouseEvent e) {
            ballList.add(new Ball(e.getPoint(), new Point(DELTA, DELTA)));
        sTimer.start();
      public JPanel getPanel() {
        return mainPanel;
      private void timerAction(ActionEvent e) {
        Dimension d = mainPanel.getSize();
        for (Ball ball : ballList) {
          if (ball.getPoint().x < 0) {
            ball.setXDirectionRight(true);
          } else if (ball.getPoint().x + DIAMETER > d.width) {
            ball.setXDirectionRight(false);
          if (ball.getPoint().y < 0) {
            ball.setYDirectionDown(true);
          } else if (ball.getPoint().y + DIAMETER > d.height) {
            ball.setYDirectionDown(false);
          ball.increment();
        mainPanel.repaint();
       * paintComponent method draws all balls in List
       * @param g
      private void myPaint(Graphics g) {
        g.setColor(Color.red);
        Graphics2D g2d = (Graphics2D) g;
        RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setRenderingHints(rh);
        for (Ball ball : ballList) {
          g.fillOval(ball.getPoint().x, ball.getPoint().y, DIAMETER, DIAMETER);
      private class Ball {
        private Point point = new Point();
        private Point velocity = new Point();
        public Ball(Point point, Point velocity) {
          this.point = point;
          this.velocity = velocity;
        public Point getPoint() {
          return point;
        public Point getVelocity() {
          return velocity;
        public void increment() {
          point = new Point(point.x + velocity.x, point.y + velocity.y);
        public void setXDirectionRight(boolean right) {
          int newVelocityX = Math.abs(velocity.x);
          if (!right) {
            newVelocityX = -newVelocityX;
          velocity = new Point(newVelocityX, velocity.y);
        public void setYDirectionDown(boolean down) {
          int newVelocityY = Math.abs(velocity.y);
          if (!down) {
            newVelocityY = -newVelocityY;
          velocity = new Point(velocity.x, newVelocityY);
    }And this displays the JPanel produced above in a standard JApplet.
    BouncingCircApplet.java
    import java.lang.reflect.InvocationTargetException;
    import javax.swing.JApplet;
    import javax.swing.SwingUtilities;
    public class BouncingCircApplet extends JApplet {
      @Override
      public void init() {
        try {
          SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
              getContentPane().add(new BouncingCircles().getPanel());
        } catch (InterruptedException e) {
          e.printStackTrace();
        } catch (InvocationTargetException e) {
          e.printStackTrace();
    }

  • Need help with rotation in Java

    Hi, I am trying to write an asteroids remake and I have gotten pretty far, but I'm stuck when I try to rotate my ship object. I have googled various formula's etc. but the code doesn't work as expected. I have posted the relevant ship.class below:
    import java.awt.Polygon;
    import java.awt.Graphics;
    import java.awt.Shape;
    import java.awt.*;
    public class Ship extends MyShape {
         Polygon body;
         //line2D.Double base;
         //line2D.Double lside;
         //line2D.Double rside;
         double dx;
         double dy;
         double angle;
         double dAngle;
         Graphics2D gg;
         public Ship(double a,double b) {
        x=a;
        y=b;
        //base=new line2D.Double(x,y,x+10,y);
        //lside=new line2D.Double(x,y,x+5,y-10);
        //rside=new line2D.Double(x+10,y,x-5,y-10);
        body=new Polygon();
        body.addPoint((int)x,(int)y);
        body.addPoint((int)x+20,(int)y);
        body.addPoint((int)x+10,(int)y-30);
        public void advance(){
        public double getX(){
             return x;
        public double getY(){
             return y;
        public void setY(int y){
             this.y=y;
        public void setX(int x){
             this.x=x;
          public void move(int delta){
          body.translate(0,delta);
           // body.addPoint(x,y);
           // body.addPoint(x+20,y);
           // body.addPoint(x+10,y-30);
        public void rotate(double x, double y, double theta){
             //body=new Polygon();
             theta=theta*(Math.PI/180);
             x=((x-(x+10))*Math.cos(theta)-y*Math.sin(theta)+(x+10));
             y=(y*Math.cos(theta)+(x-(x+10))*Math.sin(theta)+y);
                 //body.translate((int)Math.round(x),(int)Math.round(y));
                 body.addPoint((int)Math.round(x),(int)Math.round(y));
                 body.addPoint((int)Math.round(x+20),(int)Math.round(y));
                 body.addPoint((int)Math.round(x+10),(int)Math.round(y-30));
                 //g.rotate(theta,x,y);
        public void warpAround(int x,int y){
             body.translate(x,y);
        public void draw(Graphics2D g){
             g.draw(body);
    }If you could help me I would appreciate it,
    Sincerely,
    LJ
    P.s. I know its a little rough, I wanted to clean it up soon.
    Message was edited by:
    nipponman21

    Ok, I have officially given up on trying to get it to work via the mathematical definitions of a rotational transform. I decided to use the affine transform and it was MUCH easier than I thought to implement; however, the results are still unexpected, the ship actually turns and moves in a circle which is not what I want, here is the source (its a standalone app so you can compile and run it if you want) import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    public class BouncingBall extends JFrame implements Runnable, KeyListener {
        //Windows
        private JFrame frame;
        private DrawPanel pane; 
        private Thread t;
        //Game Vars.
        public Ball ball;
        public Ship ship;
        public static final int FPS = 30;
        public static final int WIDTH = 800;
        public static final int HEIGHT = 600;
        public static final int MAXSPEED = 30;
        public static double dx,dy;
        public static int theta=0;
        public BouncingBall() {
             frame=new JFrame();
             pane=new DrawPanel();
             frame.getContentPane().add(pane);
             frame.setVisible(true);
             frame.pack();
             frame.addKeyListener(this);
             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             initGame();
             start();
        public void initGame(){
             ship=new Ship();
             ball=new Ball();
        public void start(){
        t=new Thread(this);
             t.start();
            public void run(){
                 while(true){
                      try{
                      Thread.sleep(10);
                      }catch(Exception e){}
                      pane.repaint();
        public static void main(String[] args) {
            new BouncingBall();
        public void keyPressed(KeyEvent e){
            switch(e.getKeyCode()){
                   case KeyEvent.VK_UP:
                   dy--;
                   if(dy<MAXSPEED){
                   ship.move(0,dy);
                   else{
                   dy=MAXSPEED;
                   ship.move(0,dy);
                   break;
                   case KeyEvent.VK_LEFT:
                        theta++;
                        break;
                   case KeyEvent.VK_RIGHT:
                        theta--;
                        break;     
        repaint();
        public void keyReleased(KeyEvent e){
            switch(e.getKeyCode()){
                   case KeyEvent.VK_UP:
                   case KeyEvent.VK_DOWN:
                   dy=0;     
                   break;
        repaint();
        public void keyTyped(KeyEvent e){
        class Ball{
              double x;
              double y;
             private Arc2D.Double body;
             public Ball(){
                  x=600.0;
                  y=500.0;
                  body=new Arc2D.Double(x,y,30.0,30.0,0.0,360.0,Arc2D.OPEN);
             public void move(double dx,double dy){
                  body=new Arc2D.Double();
                  x+=dx;
                  y+=dy;
                  body=new Arc2D.Double(x,y,30.0,30.0,0.0,360.0,Arc2D.OPEN);
             public double getX(){
             return this.x;
             public double getY(){
             return this.y;
        class Ship{
              double x;
              double y;
              double angle;         
             private Polygon body;
             public Ship(){
                  x=400.0;
                  y=300.0;
                  angle=0;
                  body=new Polygon();
                  body.addPoint((int)Math.round(x),(int)Math.round(y));
                  body.addPoint((int)Math.round(x+15),(int)Math.round(y));
                  body.addPoint((int)Math.round(x+7.5),(int)Math.round(y-20));
             public void move(double dx,double dy){
                  body=new Polygon();
                  x+=dx;
                  y+=dy;
                  body.addPoint((int)Math.round(x),(int)Math.round(y));
                  body.addPoint((int)Math.round(x+15),(int)Math.round(y));
                  body.addPoint((int)Math.round(x+7.5),(int)Math.round(y-20));
             public double getX(){
             return this.x;
             public double getY(){
             return this.y;
        class DrawPanel extends JPanel{
                public DrawPanel(){
                  setBackground(Color.black);
                  setPreferredSize(new Dimension(BouncingBall.WIDTH,BouncingBall.HEIGHT));
             public void paintComponent(Graphics g){
                 super.paintComponent(g);
                 Graphics2D g2d=(Graphics2D)g;
                 g2d.setColor(Color.white);
                 g2d.fill(ball.body);
                 g2d.rotate(theta*Math.PI / 180.0);     
                 g2d.fill(ship.body);
    }Can you guys maybe run this and look over the code and tell me what I'm doing wrong? I would definitely appreciate it Thanks.

  • Dynamic class creation

    hi,
    I need to create new classes (not objects) dynamically in my program and then objects of that type.
    For example if the user asks to create a class with int, float & char as its data fields, and such class is not yet defined, I need to create such class and then instantiate it.
    I m creating class.java using and then compiling it using Runtime.getRuntime.exec() to get corresponding class file.
    But I m facing problem in instantiating it.
    code goes like this:
    import java.util.*;
    import java.io.*;
    public class Main {
                public Main() {
        public static void main(String[] args) {
            String key="fi";
            Hashtable hs= new Hashtable();
            if(hs.contains(key))
            else
               // hs.put(key,)
               try{
                   PrintWriter pw = new PrintWriter(new FileOutputStream(key+".java"),true);  
                  pw.println("public class "+key+"{");
                   for(int i=0; i< key.length(); i++)
                       char c = key.charAt(i);
                       switch( c )
                           case 'i' : pw.println("int i;");
                            break;
                           case 'f' : pw.println ("float f;");
                           break;
                   pw.println("public " + key + " next=null; ");
                   pw.println("public static int count=0;");
                   pw.println("public "+ key +" first=null;");
                   pw.println("public "+ key +" last=null;");
                   pw.println("public static int delta=0;");
                   pw.println("}");
                Runtime.getRuntime().exec("javac " +key+ ".java");
               catch(Exception e){e.printStackTrace();}
    //           key1 in =new key1();
               //fi in = new fi;
    }    Now after try catch block I m trying instantiate the class whose name is in key. (here key value is fi and I need create instnce of fi)

    No, The classloader associated with a class is the one that loaded it, which in the case of System.class will be the primordial class loader which "loads" classes which are actually built into the JVM. It probably won't even see the ClassPath, You'd be better putting the class files you generate on the fly into a special folder reserved for that purpose and create a URLClassLoader to load them.
    However, as has been pointed out, the question is; how are you going to use them? In general, dynamically loaded classes are only useful if they are known to implement an interface, or extend a class, available at compile time. It's pointless to create a class as a container object, for example, because if you can only access the fields through reflection it's slower, and more complicated, than using something like a HashMap.

  • Trying to catch on to using 'discover'

    I am upgrading our Solaris C++ compilation system all the way from SolStudio v6 Update 2 on Solaris 8 to SolarisStudio 12.2 on Solaris 10. (About time, huh?) Things seem to be going well enough but am struggling with the included 'discover' tool. The documentation seems a bit short and its reported "errors" seem rather dubious - but, hey, you learn something every day (especially with C++ ... ;) )
    Suggestions would be appreciated.
    Here is a rather abbreviate example of the type of oddity I am getting. I am writing a small application to test a class named CNCTimeStamp. The class has a fair number of features, but it can be boiled down to this
    nctimestamp.h
    class CNCTimeStamp {
    public:
      CNCTimeStamp();
      virtual ~CNCTimeStamp();
    protected:
      time_t m_timestamp;
      mutable struct tm* m_tm;
    }; // class CNCTimeStampnctimestamp.cpp
    CNCTimeStamp::CNCTimeStamp() :
         m_timestamp(0),
         m_tm(0)
         ::time( &m_timestamp );
    } // CNCTimeStampWhen I build it, using dmake, I get
    berlin{devel}528: dmake test1
    dmake: defaulting to parallel mode.
    See the man page dmake(1) for more information on setting up the .dmakerc file.
    nervecenter --> 1 job
    /opt/solstudio12.2/bin/CC -g -xO2 -I.. -c timetoy.cpp
    nervecenter --> 2 jobs
    /opt/solstudio12.2/bin/CC -g -xO2 -I.. -c ../nctimestamp.cpp
    nervecenter --> 1 job
    /opt/solstudio12.2/bin/CC -g -xO2 -o timetoy timetoy.o nctimestamp.o
    /usr/bin/file timetoy
    /usr/bin/ldd timetoy
    nervecenter --> Job output
    /opt/solstudio12.2/bin/CC -g -xO2 -o timetoy timetoy.o nctimestamp.o
    /usr/bin/file timetoy
    timetoy:        ELF 32-bit LSB executable 80386 Version 1 [FPU], dynamically linked, not stripped
    /usr/bin/ldd timetoy
            libCstd.so.1 =>  /usr/lib/libCstd.so.1
            libCrun.so.1 =>  /usr/lib/libCrun.so.1
            libm.so.2 =>     /usr/lib/libm.so.2
            libc.so.1 =>     /usr/lib/libc.so.1
    nervecenter --> 1 job
    /opt/solstudio12.2/bin/discover -b /opt/firefox4/firefox -H timetoy.html -w timetoy.txt -o timetoy.disc timetoy
    berlin{devel}529:All looks good so far. When I run "timetoy.disc", I get a multitude of "errors". The first is this, which shows enough in its source listing that you can see what's going on. My trouble is in grasping what an "SBR" is and how it would apply. Thoughts?
    I tried this, btw, replacing the "CNCTimeStamp* start = new CNCTimeStamp();" with "CNCTimeStamp start;" to no avail. Same SBR errors. I make no claim to being an expert with C++, but all this seems over the top. Fortunately, I am wrong most of time. LOL
    ERROR 1 (SBR): read from 0x8046ea0 (4 bytes) is beyond stack frame bounds at:
            CNCTimeStamp::CNCTimeStamp #Nvariant 1() + 0x36  <nctimestamp.cpp:37>
                    34:    // -------------------------------------------------------------------
                    35:    // Constructors
                    36:
                    37:=>  CNCTimeStamp::CNCTimeStamp() :
                    38:     m_timestamp(0),
                    39:     m_tm(0)
                    40:    {
            void nap(int) + 0xfa  <timetoy.cpp:11>
                     8:
                     9:    void nap( int naptime )
                    10:    {
                    11:=>           CNCTimeStamp* start = new CNCTimeStamp();
                    12:
                    13:     std::cout << *start << ". Start time." << std::endl;
                    14:
            main() + 0x86  <timetoy.cpp:48>
                    45:
                    46:     for ( int i = 0; i<argc; ++i )
                    47:     {
                    48:=>           nap( argc );
                    49:     }
                    50:
                    51:     timeplus( argc );
            _start() + 0x7c
    ERROR 2 (SBR): read from 0x8046ea0 (4 bytes) is beyond stack frame bounds at:
            CNCTimeStamp::CNCTimeStamp #Nvariant 1() + 0x5c  <nctimestamp.cpp:37>
                    34:    // -------------------------------------------------------------------
                    35:    // Constructors
                    36:
                    37:=>  CNCTimeStamp::CNCTimeStamp() :
                    38:     m_timestamp(0),
                    39:     m_tm(0)
                    40:    {
            void nap(int) + 0xfa  <timetoy.cpp:11>
                     8:
                     9:    void nap( int naptime )
                    10:    {
                    11:=>           CNCTimeStamp* start = new CNCTimeStamp();
                    12:
                    13:     std::cout << *start << ". Start time." << std::endl;
                    14:
            main() + 0x86  <timetoy.cpp:48>
                    45:
                    46:     for ( int i = 0; i<argc; ++i )
                    47:     {
                    48:=>           nap( argc );
                    49:     }
                    50:
                    51:     timeplus( argc );
            _start() + 0x7c
    ERROR 3 (SBR): read from 0x8046ea0 (4 bytes) is beyond stack frame bounds at:
            CNCTimeStamp::CNCTimeStamp #Nvariant 1() + 0x84  <nctimestamp.cpp:39>
                    36:
                    37:    CNCTimeStamp::CNCTimeStamp() :
                    38:     m_timestamp(0),
                    39:=>   m_tm(0)
                    40:    {
                    41:     ::time( &m_timestamp );
                    42:    } // CNCTimeStamp
            void nap(int) + 0xfa  <timetoy.cpp:11>
                     8:
                     9:    void nap( int naptime )
                    10:    {
                    11:=>           CNCTimeStamp* start = new CNCTimeStamp();
                    12:
                    13:     std::cout << *start << ". Start time." << std::endl;
                    14:
            main() + 0x86  <timetoy.cpp:48>
                    45:
                    46:     for ( int i = 0; i<argc; ++i )
                    47:     {
                    48:=>           nap( argc );
                    49:     }
                    50:
                    51:     timeplus( argc );
            _start() + 0x7c
    ERROR 4 (SBR): read from 0x8046ea0 (4 bytes) is beyond stack frame bounds at:
            CNCTimeStamp::CNCTimeStamp #Nvariant 1() + 0xac  <nctimestamp.cpp:39>
                    36:
                    37:    CNCTimeStamp::CNCTimeStamp() :
                    38:     m_timestamp(0),
                    39:=>   m_tm(0)
                    40:    {
                    41:     ::time( &m_timestamp );
                    42:    } // CNCTimeStamp
            void nap(int) + 0xfa  <timetoy.cpp:11>
                     8:
                     9:    void nap( int naptime )
                    10:    {
                    11:=>           CNCTimeStamp* start = new CNCTimeStamp();
                    12:
                    13:     std::cout << *start << ". Start time." << std::endl;
                    14:
            main() + 0x86  <timetoy.cpp:48>
                    45:
                    46:     for ( int i = 0; i<argc; ++i )
                    47:     {
                    48:=>           nap( argc );
                    49:     }
                    50:
                    51:     timeplus( argc );
            _start() + 0x7c
    ERROR 5 (SBR): read from 0x8046ea0 (4 bytes) is beyond stack frame bounds at:
            CNCTimeStamp::CNCTimeStamp #Nvariant 1() + 0xe4  <nctimestamp.cpp:41>
                    38:     m_timestamp(0),
                    39:     m_tm(0)
                    40:    {
                    41:=>   ::time( &m_timestamp );
                    42:    } // CNCTimeStamp
                    43:
                    44:    CNCTimeStamp::CNCTimeStamp( time_t timestamp ) :
            void nap(int) + 0xfa  <timetoy.cpp:11>
                     8:
                     9:    void nap( int naptime )
                    10:    {
                    11:=>           CNCTimeStamp* start = new CNCTimeStamp();
                    12:
                    13:     std::cout << *start << ". Start time." << std::endl;
                    14:
            main() + 0x86  <timetoy.cpp:48>
                    45:
                    46:     for ( int i = 0; i<argc; ++i )
                    47:     {
                    48:=>           nap( argc );
                    49:     }
                    50:
                    51:     timeplus( argc );
            _start() + 0x7cThanks.

    In the interest of helping out. I'll copy/paste here the makefile and source code. If it gets to be too long, I'll have to reply to this reply - and so on.
    There are four pieces: makefile, timetoy.cpp, nctimestamp.h and nctimestamp.cpp. The goal of this exercise has been to port the code base -this C++ class, CNCTimeStamp, is merely a first piece - up to the current Solaris Studio 12.2 C++ environment. At this point I am only using the command-line interface (dmake, dbx, CC). I hope to get to solstudio and dbxtool soon -- they look great!
    makefile
    CCC             = /opt/solstudio12.2/bin/CC
    DISCOVER        = /opt/solstudio12.2/bin/discover
    FILE            = /usr/bin/file
    LDD             = /usr/bin/ldd
    WEBBROWSER      = /opt/firefox4/firefox
    CC_OPTIMIZE     = -m32 -g -xO2
    timetoy: timetoy.o nctimestamp.o
            $(CCC) $(CC_OPTIMIZE) -o $@ timetoy.o nctimestamp.o
            $(FILE) $@
            $(LDD) $@
    timetoy.disc: timetoy
            $(DISCOVER) -w timetoy.txt -o $@ timetoy
    timetoy.o: timetoy.cpp
            $(CCC) $(CC_OPTIMIZE) -I.. -c timetoy.cpp
    nctimestamp.o: ../nctimestamp.cpp
            $(CCC) $(CC_OPTIMIZE) -I.. -c ../nctimestamp.cpp
    clean:
            $(RM) timetoy
            $(RM) timetoy.disc
            $(RM) timetoy.o nctimestamp.o
    test1: timetoy.disc
            ./timetoy.disc 1 1 1timetoy.cpp
    #include <iostream>
    #include <unistd.h>             // sleep(3C)
    #include <inttypes.h>           // int32_t
    #include "nctimestamp.h"
    void nap( int naptime )
            CNCTimeStamp* start = new CNCTimeStamp();
            std::cout << *start << ". Start time." << std::endl;
            sleep( naptime );
            CNCTimeStamp* stop = new CNCTimeStamp();
            time_t mynap = *stop - *start;
            std::cout << *stop << ". That nap was " << mynap << " seconds long." << std::endl;
            delete start;
            start = 0;
            delete stop;
            stop = 0;
    } // nap
    void timeplus( time_t offset )
            CNCTimeStamp now;
            time_t zoom = now.plus( offset );
            CNCTimeStamp* future = new CNCTimeStamp( zoom );
            std::cout << now << " plus " << offset << " is " << *future << std::endl;
            delete future;
    int main( int argc, const char* argv[] )
            int result = EXIT_SUCCESS;
            for ( int i = 0; i<argc; ++i )
                    nap( argc );
            timeplus( argc );
            return result;
    } // mainnctimestamp.h
    #ifndef _NCTIMESTAMP_H_
    #define _NCTIMESTAMP_H_
    #include <iostream>             // std:: ostream
    #include <string>               // std:: string
    #include <ctime>                // std:: time_t, struct tm
    #include <inttypes.h>           // int32_t
    // Class CNCTimeStamp represents a single moment in time.
    // Implementation:
    // 1. The class has two attributes, m_timestamp and m_tm.  The first,
    // m_timestamp, must always be maintained from contruction thru
    // to destruction.  The second, m_tm, is brought into use only
    // as needed; it is entirely secondary to m_timestamp.  The function
    // tm() is called to bring it into existance or return m_tm if it
    // is already created.
    // 2. Reliance on system calls is intentionally limited.  time(2)
    // is called only in the default constructor, which is the means
    // for the client to create an instance set to the present moment
    // in time.  localtime(3c) is used at the point when the m_tm
    // needs to be instantiated.
    class CNCTimeStamp {
    public: // Construction
            CNCTimeStamp();
                    // Represents the current time.
                    // (The moment in time when the instance
                    // is created.)
            CNCTimeStamp( time_t timestamp );
                    // Represents the moment set by 'timestamp'.
            CNCTimeStamp( int year,
                          int month,
                          int day,
                          int hour = 0,
                          int minute = 0,
                          int second = 0,
                          bool* isDST = 0 );
                    // Represents the moment set by the params.
            CNCTimeStamp( const struct tm& tm );
                    // Represents the moment set by the tm struct.
            CNCTimeStamp( const CNCTimeStamp& other );
                    // Copy constructor.
            virtual ~CNCTimeStamp();
    public:
            const CNCTimeStamp& operator = ( const CNCTimeStamp& source );
            const CNCTimeStamp& operator = ( time_t time );
            const CNCTimeStamp& operator = ( const struct tm& tm );
    public: // Output
            std::string YYYYMMDD_HHMMSS() const;
            std::ostream& YYYYMMDD_HHMMSS( std::ostream& os ) const;
                    // Print the time as "yyyy-hh-mm hh-mm-ss"
                    // ex: "2010-01-31 13:59:03"
    public: // Conversion routines (public / static )
            static struct tm* tm( time_t time);
            static time_t time( struct tm* Tm );
    public: // Comparison
            bool operator == ( const CNCTimeStamp& other ) const;
            bool operator == ( time_t timestamp ) const;
            bool operator != ( const CNCTimeStamp& other ) const;
            bool operator != ( time_t timestamp ) const;
            bool operator < ( const CNCTimeStamp& other ) const;
            bool operator < ( time_t timestamp ) const;
            bool operator <= ( const CNCTimeStamp& other ) const;
            bool operator <= ( time_t timestamp ) const;
            bool operator > ( const CNCTimeStamp& other ) const;
            bool operator > ( time_t timestamp ) const;
            bool operator >= ( const CNCTimeStamp& other ) const;
            bool operator >= ( time_t timestamp ) const;
    public: // Comparison
            int delta( const CNCTimeStamp& other ) const;
                    // The amount of time, in seconds, between this
                    // instance and the 'other'. The result can be
                    // positive (future) or negative (past) or
                    // zero (present).
                    // Ex: If both this and other are for the same
                    // minute in time, but 'this' is for the 30th
                    // second and 'other' is for the 44th second,
                    // then the delta is -14 seconds. As in, this
                    // instance is 14 seconds behind the 'other'.
            static int delta( const CNCTimeStamp& first, const CNCTimeStamp& second );
                    // The amount of time, in seconds, between the
                    // 'first' and 'second' instances. The result can be
                    // positive (future) or negative (past) or
                    // zero (present).
                    // Ex: If both 'first' and 'second' are for the same
                    // minute in time, but 'first' is for the 3rd
                    // second and 'second' is for the 13th second,
                    // then the delta is -10 seconds. As in, the
                    // 'first' instance is 10 seconds behind the
                    // 'second'.
    public: // Operations (Addition / Subtraction)
            time_t plus( time_t timespan ) const;
            time_t operator + ( time_t timespan ) const;
            time_t subtract( time_t timespan ) const;
            time_t operator - ( time_t timespan ) const;
            time_t subtract( const CNCTimeStamp& other ) const;
            time_t operator - ( const CNCTimeStamp& other ) const;
    public: // Access
            operator time_t() const;
    protected:
            struct tm* tm() const;
    protected:
            time_t m_timestamp;
            mutable struct tm* m_tm;
    }; // class CNCTimeStamp
    std::ostream& operator<<( std::ostream& os, const CNCTimeStamp& timestamp );
    #endif // _NCTIMESTAMP_H_nctimestamp.cpp
    #include "nctimestamp.h"
    #include <iomanip>
    #include <iostream>
    #include <ctime>        // time_t mktime( struct std::tm* timeptr )
    // Constructors
    CNCTimeStamp::CNCTimeStamp() :
            m_timestamp(0),
            m_tm(0)
            ::time( &m_timestamp );
    } // CNCTimeStamp
    CNCTimeStamp::CNCTimeStamp( time_t timestamp ) :
            m_timestamp( timestamp ),
            m_tm(0)
    CNCTimeStamp::CNCTimeStamp( int year,
                                int month,
                                int day,
                                int hour,
                                int minute,
                                int second,
                                bool* isDST ) :
            m_timestamp(0),
            m_tm(0)
            m_tm = new struct tm;
            memset( m_tm, 0, sizeof( struct tm ) );
            m_tm->tm_year = year - 1900;
            m_tm->tm_mon = month - 1;
            m_tm->tm_mday = day;
            m_tm->tm_hour = hour;
            m_tm->tm_min = minute;
            m_tm->tm_sec = second;
            m_tm->tm_wday = 0; // will be filled out by mktime()
            m_tm->tm_yday = 0; // will be filled out by mktime()
            if ( !isDST )
                    m_tm->tm_isdst = -1;
            else
                    m_tm->tm_isdst = ( *isDST ) ? 1 : 0;
            m_timestamp = mktime( m_tm );   // <ctime> function
    CNCTimeStamp::CNCTimeStamp( const CNCTimeStamp& other ) :
            m_timestamp( other.m_timestamp ),
            m_tm(0)
    CNCTimeStamp::~CNCTimeStamp()
            if ( m_tm )
                    delete m_tm;
                    m_tm = 0;
    } // ~CNCTimeStamp
    // operator =
    const CNCTimeStamp& CNCTimeStamp::operator = ( const CNCTimeStamp& source )
            if ( this != &source )
                    m_timestamp = source.m_timestamp;
                    if ( m_tm )
                            delete m_tm;
                            m_tm = 0;
                    if ( source.m_tm )
                            m_tm = new struct tm( *source.m_tm );
            return *this;
    } // operator =
    // operator =
    const CNCTimeStamp& CNCTimeStamp::operator = ( time_t time )
            m_timestamp = time;
            if ( m_tm )
                    delete m_tm;
                    m_tm = 0;
            return *this;
    } // operator =
    // operator =
    const CNCTimeStamp& CNCTimeStamp::operator = ( const struct tm& tm )
            if ( m_tm )
                    delete m_tm;
                    m_tm = 0;
            m_tm = new struct tm( tm );
            m_timestamp = mktime( m_tm );   // <ctime> function
            return *this;
    } // operator =
    // operator !=
    bool CNCTimeStamp::operator != ( const CNCTimeStamp& other ) const
            return ( m_timestamp != other.m_timestamp ) ? true : false;
    // operator ==
    bool CNCTimeStamp::operator == ( const CNCTimeStamp& other ) const
            return ( m_timestamp == other.m_timestamp ) ? true : false;
    // operator =
    bool CNCTimeStamp::operator != ( time_t timestamp ) const
            return ( m_timestamp != timestamp ) ? true : false;
    // operator =
    bool CNCTimeStamp::operator == ( time_t timestamp ) const
            return ( m_timestamp == timestamp ) ? true : false;
    // operator <
    bool CNCTimeStamp::operator < ( const CNCTimeStamp& other ) const
            return ( m_timestamp < other.m_timestamp ) ? true : false;
    // operator <
    bool CNCTimeStamp::operator < ( time_t timestamp ) const
            return ( m_timestamp < timestamp ) ? true : false;
    // operator <=
    bool CNCTimeStamp::operator <= ( const CNCTimeStamp& other ) const
            return ( m_timestamp <= other.m_timestamp ) ? true : false;
    // operator <=
    bool CNCTimeStamp::operator <= ( time_t timestamp ) const
            return ( m_timestamp <= timestamp ) ? true : false;
    // operator >
    bool CNCTimeStamp::operator > ( const CNCTimeStamp& other ) const
            return ( m_timestamp > other.m_timestamp ) ? true : false;
    // operator >
    bool CNCTimeStamp::operator > ( time_t timestamp ) const
            return ( m_timestamp > timestamp ) ? true : false;
    // operator >=
    bool CNCTimeStamp::operator >= ( const CNCTimeStamp& other ) const
            return ( m_timestamp >= other.m_timestamp ) ? true : false;
    // operator >=
    bool CNCTimeStamp::operator >= ( time_t timestamp ) const
            return ( m_timestamp >= m_timestamp ) ? true : false;
    // plus
    time_t CNCTimeStamp::plus( time_t timespan ) const
            return m_timestamp + timespan;
    } // plus
    // operator +
    time_t CNCTimeStamp::operator + ( time_t timespan ) const
            return plus( timespan );
    } // operator +
    // subtract
    time_t CNCTimeStamp::subtract( time_t timespan ) const
            return m_timestamp - timespan;
    } // subtract
    // operator -
    time_t CNCTimeStamp::operator - ( time_t timespan ) const
            return subtract( timespan );
    } // operator -
    // subtract
    time_t CNCTimeStamp::subtract( const CNCTimeStamp& other ) const
            return (m_timestamp - other.m_timestamp);
    } // subtract
    // operator -
    time_t CNCTimeStamp::operator - ( const CNCTimeStamp& other ) const
            return subtract( other );
    } // operator -
    // tm
    struct tm* CNCTimeStamp::tm() const
            if ( !m_tm )
                    m_tm = tm( m_timestamp );
            return m_tm;
    } // tm
    // tm
    struct tm* CNCTimeStamp::tm( time_t time )
            struct tm* result = new struct tm;
            memset( result, 0, sizeof( struct tm ) );
    #if defined(__unix)
            localtime_r( &time, result );
    #else
            result = localtime( &time );
    #endif
            return result;
    } // tm
    // YYYYMMDD_HHMMSS
    std::string CNCTimeStamp::YYYYMMDD_HHMMSS() const
            struct tm* Tm = tm();
    #if 1
            // format: "yyyy-mm-dd hh:mm:ss" which is a constant 19 chars.
            char buffer[24];
            sprintf( buffer, "%04d-%02d-%02d %02d:%02d:%02d",
                     Tm->tm_year + 1900,
                     Tm->tm_mon + 1,
                     Tm->tm_mday,
                     Tm->tm_hour,
                     Tm->tm_min,
                     Tm->tm_sec );
            std::string result( buffer );
            return result;
    #else
            // This is slow at runtime. The problem is that it
            // relies heavily on the heap for building up its
            // value.
            std::ostringstream result;
            result << std::setfill('0')
                   << std::setw(4) << Tm->tm_year + 1900
                   << "-"
                   << std::setw(2) << Tm->tm_mon + 1
                   << "-"
                   << std::setw(2) << Tm->tm_mday
                   << " "
                   << std::setw(2) << Tm->tm_hour
                   << ":"
                   << std::setw(2) << Tm->tm_min
                   << ":"
                   << std::setw(2) << Tm->tm_sec;
            return result.str();
    #endif
    } // YYYYMMDD_HHMMSS
    // YYYYMMDD_HHMMSS
    std::ostream& CNCTimeStamp::YYYYMMDD_HHMMSS( std::ostream& os ) const
            os << YYYYMMDD_HHMMSS();
            return os;
    } // YYYYMMDD_HHMMSS
    // time
    time_t CNCTimeStamp::time( struct tm* tb )
            return mktime( tb );    // <ctime> function
    // operator time_t
    CNCTimeStamp::operator time_t() const
            return m_timestamp;
    } // operator std::time_t
    // operator<<
    //      Note, there is no 'this' pointer within this function.  Also,
    //      ensure the feature 'YYYYMMDD_HHMMSS' is virtual for all descendents
    //      of CNCTimeStamp.
    std::ostream& operator<<( std::ostream& os, const CNCTimeStamp& timestamp )
            return timestamp.YYYYMMDD_HHMMSS( os );
    } // operator <<
    // ###

  • DVI/RTP packet decode

    Hi,
    I need to stream audio and/or video to a PDA device. There is a trick here which is:
    The PDA must receive the stream from a multicast address. For this I have implemented a Bridge application which joins the multicast group on behalf of the PDA and receives the Multicast RTP packets (which are sent from JMStudio) and Unicasts them to the PDA.(HP iPAQ) I had no problem implementing this. The streaming is done using JMStudio player which encodes the streaming audio data into a number of encodings (DVI/RTP in my case). I choose DVI/RTP and stream a .wav audio file.
    Now I have to accept the packets and play the stream on the PDA.
    The j2me application receives all the RTP packets successfully and I can extract usefull information from the packets such as: Timestamp, sequence number, payload type. The payload type is 5 which means it is a DVI4 encoding.
    I use the following method to decode the samples:
    public int decode(Object state, byte[] input, int inp, int len, short[] output, int outp) {
    int sign;
    int delta;
    int vpdiff;
    //int valprev = audio.Convert.byte2short(input, inp);
    //int index = input[inp + 2];
    int valprev=0,index=0;
    int inputbuffer = 0;
    int bufferstep = 0;
    valprev = input[0] <<8;
    valprev |= input[1] &0xff;
    index = input[2] &0xff;
    if ( index < 0 ) index = 0;
    else if ( index > 88 ) index = 88;
    int step = stepsizeTable[index];
    inp += 4;
    len = (len - 4) * 2;
    int count = len;
    while(count-- > 0) {
    if ( 0 == bufferstep ) {
    inputbuffer = input[inp++];
    delta = (inputbuffer >> 4) & 0xf;
    bufferstep = 1;
    } else {
    delta = inputbuffer & 0xf;
    bufferstep = 0;
    index += indexTable[delta];
    if ( index < 0 ) index = 0;
    else if ( index > 88 ) index = 88;
    sign = delta & 8;
    delta = delta & 7;
    vpdiff = step >> 1;
    if ( (delta & 4) == 4 ) vpdiff += (step << 2);
    if ( (delta & 2) == 2 ) vpdiff += (step << 1);
    if ( (delta & 1) == 1 ) vpdiff += step;
    vpdiff >>= 2;
    if ( 0 != sign )
    valprev -= vpdiff;
    else
    valprev += vpdiff;
    if ( valprev > 32767 )
    valprev = 32767;
    else if ( valprev < -32768 )
    valprev = -32768;
    step = stepsizeTable[index];
    output[outp++] = (short) valprev;
    ((AdpcmState)state).valprev = valprev;
    ((AdpcmState)state).index = index;
    return len;
    which stores the result into a short[] array.
    I then convert this short[] array into a byte[] array with the following way:
    s is the short[] array
    adp is the byte array
    for(int g=0,k=0;g<s.length;g++,k=k+2){
    audio.Convert.short2byte(s[g],adp,k);
    public static void short2byte(short ival, byte b[], int offset) {
    int i;
    int bits = 16;
    for(i = 0; i >< 2; i++) {
    bits -= 8;
    b[offset + i] = (byte) ((ival >> bits) & 0xff);
    The final result is loaded to the player as follows:
    ByteArrayInputStream input1 = new ByteArrayInputStream(adp);
    player = Manager.createPlayer(input1, "audio/x-wav");//create new player
    player.addPlayerListener(this);
    player.prefetch();
    player.realize();
    player.start();
    The player begins to play but I only get horrible sounds instead of the original wave file
    The player now initializes ok without any problem but I can only hear a meesed up sound rather than the original. So now I strongly believe that the problem is in the decoding of the samples of the DVI/RTP codec.

    thesti wrote:
    how JMF deal with RTP packet loss? since my application doesn't handle anything due to RTP packet loss, i believe that JMF has a mechanism to deal with it.It "deals" with it by having a blank spot in the rendering where that packet would have gone...

Maybe you are looking for

  • New bt vision box

    I have just been sent a btvision box and told to replace my 'old' one with it .... however it looks exactly the same. My existing one is silver and so is the replacement, however on the web the new one is shown as being black. If I swap them over, i

  • I can't play my movies from iTunes when i connect to my HDTV.

    I'm having trouble viewing my video from iTunes on my hdtv. I have a 2013 MBP 13" retina display runing OS X Mavericks. i recently bought an hdmi cable so i can hook up my MBP to my HDTV and watch my videos from iTunes.But when i open my itunes and t

  • Photo booth .qtz's in iMovie

    Hi, I am trying to do a green screen effiect in iMovie without a green screen. This is possible in photo booth with the background effects. I have been suprised to find that these effects are not available in iMovie. This question has been asked befo

  • Ora - 12170 - Connection Timeout

    Hi, Problem - I am using TOAD on my machine to connect to my database, but giving the error "Ora-12170, Connection Timeout". Explanation - I have installed Oracle InstantClient 10.2 on local machine and using that home as default home to connect to t

  • Last Purchase Price History

    Dear All, Is there any way we can have the Last Purchase Price History in SAP system? Our customer has 2 stock transfer. In those 2 documents, she has 2 difference last purchase price on the document. But actually, she didn't issue any GRPO of that i