Position of Canvas in Applet

Hello, I am creating a simple shoot 'em up game where the player has to blast the meteors.
The meteors are instances of Canvas's and the location of each is set by using the setLocation() method. When I press the refresh button on IE, the meteors sometimes dont appear in the correct place (i.e. overlap each other).
The problem usually happens 1 in 200 refreshes of the browser. I know people might think an error as small as this is not worth bothering about, but the game needs to be completly error free.
I have used setLayout(NULL) so that I can nullify the layout and use the setLocation() method.
I hope somone can help me out here. I am using JDK 1.3.1_16 (so that it will work with MSJVM) and MSJVM Version 5 Release 5.0.0.3805
Thanks
Andrew

Are you using absolute layout on your entier GUI? or just the container that you have your asteroids in? The reason I as is that if you have the Fit to Screen option on in IE, then it may be becoming confused and shrinking the rest of your interface and causing your asteroids to overlap from time to time.

Similar Messages

  • How do I put a hyperlink button on the Canvas in Applet

    I am tried to put a hyperlink button on the Canvas in Applet.
    But Canvas is a componet that can't contain any component.
    I hope best way that is like hyperlink of HTML , I just clicked this hyperlink in Canvas,it's automation link to directed homepage.
    Can I have any way to do that?

    You can setup Restrictions...
    Tap Settings > General > Restrictions
    AFAIK, it's not possible to attach a password for access to the Settings.

  • "Viewport X/Y Position on Canvas" ??????

    Viewport X Position on Canvas Viewport Y Position on Canvas These Properties determine where the viewport will be positioned on the stacked canvas itself.
    Fine I understand this or at least i thought i did until i played around wiht it and it dosen't seem to be working the way i understood it should from the online docs.
    Problem:
    On the stacked canvas itself i can see the viewport is represented by a box designated with a thin black line. If i resize the box the viewport property settings adjust as they do if i reposition the the box somewhere else on the stacked canvas. BUT when i run the form the viewport does not reflect some of the settings i.e. the viewport size changes but what isn't happening is the viewport position which seems to be fixed no matter what i input in the Viewport X/Y Position on Canvas property.
    So am i changing the right settings so that the viewport shows me different parts of the stacked canvas at runtime?
    Cheers
    Gus

    I just tested it for myself (Forms10g) and everything worked fine. Is your canvas 'large enough'? During testing I recognized that you can't set the viewport in a way that there would be 'free space' left with nothing displaed in it.
    What I mean is:
    Lets say your stacked canvas has the with of 600 points, 500 points are visible then you can't set the viewport at x=200 because there would be 100 points left with nothing to display into it. In this case Forms sets the viewport x=100 so everything fits.
    (In fact I first thought of a bug myself before I recognized this)
    Frank

  • Re: adding canvas to applet

    Hi
    I am trying to add a canvas to an applet. I am successful in doing so. There is a JMenuBar added to the applet. when I click on the file menu The contents are being displayed behind the canvas and as a result I am neither able to see the buttons nor select them. Could some one help me with this.
    Note: Once you compile the code you wouldn't be able to see the contents right away. Click on left top,immidiately below the applet menu. This will repaint the contentpane. This is some thing I am working on.
    applet class
    package aple;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Shape;
    import java.awt.geom.AffineTransform;
    import java.util.ArrayList;
    import javax.swing.JApplet;
    public class NewJApplet extends JApplet{
        public Graphics2D g2;
        AffineTransform atf = new AffineTransform();
        sketch sk = new sketch();   
            @Override
        public void init() {      
            getContentPane().add(sk);
           Gui gui = new Gui();
            // menubar
            this.setJMenuBar(gui.Gui());     
        @Override
    gui class
    package aple;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    public class Gui {
        JMenuBar menuBar;
        JMenu file,edit,insert,view,draw,circle;
        JMenuItem nu,close,saveAs,open,centreandradius,line,rectangle,point,arc;
        public JMenuBar Gui(){
            //Menubar
            menuBar = new JMenuBar();
            //Menus
            file = new JMenu("File");
            menuBar.add(file);
            edit = new JMenu("Edit");
            menuBar.add(edit);
            view = new JMenu("View");
            menuBar.add(view);
            insert = new JMenu("Insert");       
            draw = new JMenu("Draw");
            circle = new JMenu("Circle");
            draw.add(circle);
            insert.add(draw);       
            menuBar.add(insert);
            //MenuItems
            nu = new JMenuItem("New");
            file.add(nu);
            open = new JMenuItem("Open");
            file.add(open);
            saveAs = new JMenuItem("SaveAs");
            file.add(saveAs);
            close = new JMenuItem("Close");
            file.add(close);
            line = new JMenuItem("Line");
            draw.add(line);
            centreandradius = new JMenuItem("Centre and Radius");
            circle.add(centreandradius);
            rectangle = new JMenuItem("Rectangle");
            draw.add(rectangle);
            point = new JMenuItem("Point");
            draw.add(point);
            arc = new JMenuItem("arc");
            draw.add("Arc");
            return(menuBar);
    sketch class
    package aple;
    import java.awt.Canvas;
    import java.awt.Color;
    import java.awt.Graphics;
    public class sketch extends Canvas{
        public void sketch(){
            this.setBackground(Color.green);
        @Override
        public void paint(Graphics g){
         // g.fillRect(50,50, 50, 50); 
    }

    When you were using JPanel, your "setBackground" didn't work because you were overriding its paint(Graphics) method without calling "super.paint(g);". If you don't do this, the panel won't paint its background.
    You should also override "protected void paintComponent(Graphics g)" in any JComponent, such as JPanel, instead of just "paint(Graphics)". (And don't forget to call super.paintComponent(g) FIRST in your subclass's overridden method, if you want the background painted):
    class MyJPanelSubclass extends JPanel {
       protected void paintComponent(Graphics g) {
          super.paintComponent(g); // Paints background and any other stuff normally painted.
          // Do your custom painting here.
    }

  • Painting on Canvas or Applet?

    1) I have been writing an RPG for some time using j2sdk1.4.1_01 in windowsxp, The main component I'm drawing on is now a Canvas but was originally an Applet, Which is a better choice to use? I am using a double buffering system with VolatileImage and Fullscreen Exclusive mode with a Frame at 640x480 screen size. I have set the framerate to repaint at 25 fps. 2) Any performance boosting suggestions?

    the bare minimum to render to a fullscreen frame in the fastest way possible...
    Frame f = new Frame();
    f.getGraphicsConfiguration().getDefaultDevice().setFullScreenWindow(f);
    f.createBufferStrategy(2);
    BufferStrategy bs = f.getBufferStrategy();
    Random r = new Random();
    while(true)
       Graphics g = bs.getDrawGraphics();
       g.setColor(new Color(r.nextInt));
       g.fillRect(0,0,getWidth(),getHeight());
       g.dispose();
       bs.show();
    }

  • Adding a goemetry object in an already started applet, behvior ?

    Hello there,
    I would like to add a geometric form (cube, box, cone etc..) in an already
    started applet. I think creating a specific behavior would be the most
    appropriate.
    Has anybody done this kind of thing before ?
    Many thanks.
    Gwena�l

    Great thread! I am having difficulty with removing objects from a scene graph. See source code below:
    addTarget creates a grpahicsObject (class consisting of some data, mainly a 3d object which is attached to a transformGroup).
    //function to add an aircrafat to display
         //attemps to create the aircraft in the specified location
         //returns false if the spot is not null
         public boolean addTarget(int location, float x, float y, float z)
              if(targets[location]!=null)
                   return false;
              //create transform vector
              Vector3f targetTransform = new Vector3f(x,y,z);
              //create the object
              targets[location]= new GraphicsObject(targetTransform, TARGET_COLOR);
              //add it to the scene graph
              sadist.addObject(targets[location].getTransformGroup());
              return true;
    //sadist is an object that contains my universe and pretty much controls my display
    //the add object code adds the created to the scene graph by adding the transform group to a newly created branchgroup and than adding that to the mother branchgroup. The mother branchgroup was attached to the simple universe object (see code snipit)
    private Applet CreateWorld()
              setLayout(new BorderLayout());
         //create a new canvas
         Canvas3D canvas3D = new Canvas3D(null); // NEED TO PASS IN SOMETHING
         //add canvas to applet
         add("Center", canvas3D);
         BranchGroup scene = createSceneGraph();
         mother = new BranchGroup();
              mother.setCapability(BranchGroup.ALLOW_DETACH);
              mother.setCapability(Group.ALLOW_CHILDREN_READ);
         mother.setCapability(Group.ALLOW_CHILDREN_WRITE);
         mother.setCapability(Group.ALLOW_CHILDREN_EXTEND);
         mother.addChild(scene);
         // SimpleUniverse is a Convenience Utility class
         // code reuse saves time
         simpleU = new SimpleUniverse(canvas3D);
              ViewingPlatform vp = simpleU.getViewingPlatform();
              TransformGroup steerTG = vp.getViewPlatformTransform();
              //create my transform
              Transform3D t3d = new Transform3D();
              steerTG.getTransform(t3d);
              //lookAt( from here, look here, vector up)
              t3d.lookAt( new Point3d (2,2,2),
                             new Point3d (0,0,0),
                             new Vector3d(0,1,0) );
              t3d.invert(); //inverted since the position is relative to the viewer
              //set the transform for the transform group
              steerTG.setTransform(t3d);
              simpleU.addBranchGraph(mother);
         return(this);
         //function to add transofrm group to scene graph
         public void addObject(TransformGroup object)
              //should I create a new branch graph, add the transform group, and then
              //add that to the simple u
              //I don't think this is right as I have no real way of identifying this
              //I need to look into a removeChild or something
              //could result in 1000's of null nodes on scene graph
              //yuck...
              System.out.println("going to add the transformg group to the branchgroup");
              BranchGroup t = new BranchGroup();
              t.setCapability(BranchGroup.ALLOW_DETACH);
              t.setCapability(Group.ALLOW_CHILDREN_READ);
              t.setCapability(Group.ALLOW_CHILDREN_WRITE);
         t.setCapability(Group.ALLOW_CHILDREN_EXTEND);
              t.addChild(object);
              t.compile();
              //simpleU.addBranchGraph(t);
              mother.addChild(t);
    When I run the code with a tester function I can add the objects just fine but when I try to remove them (see code below) it doesn�t work.
    //removal of targets will take place
         public void removeObject(int location) throws CapabilityNotSetException
              try
                   //I tried detaching the branchgroup via the detach() function
                   //howeve that wasn't successful either.
                   mother.removeChild(location);
              catch(CapabilityNotSetException e)
                   throw e;
    Any advice you could give would be great.
    Thanks,
    Mike

  • Errors running converted application (from applet)

    I've converted some codes (applet) into an application. When I run the application, I can see the GUI, but the application reports error as follows:
    Exception occurred during event dispatching:
    java.lang.NullPointerException
         at swarmCanvas.paint(Swarm.java:192)
         at sun.awt.RepaintArea.paint(RepaintArea.java:298)
         at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:196)
         at java.awt.Component.dispatchEventImpl(Component.java:2663)
         at java.awt.Component.dispatchEvent(Component.java:2497)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:339)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:131)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:98)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:85)
    What I see is only the GUI less the animation that occurs when it was an applet. Could anyone offer me any suggestions or help? Thanks a lot.

    Here's my codes, many thanks:
    * Swarm.class
    * This is the major class of the swarm animation. The Swarm class is
    * responsible for initialising and coordinating the Flock, swarmCanvas,
    * and swarmPanel classes.
    * @see Flock.class
    * @see Bird.class
    * @see Barrier.class
    * @author Duncan Crombie
    * @version 2.02, 20 September 1997
    import java.awt.*;
    public class Swarm extends java.applet.Applet implements Runnable {
    Thread animator; // animation thread
    swarmCanvas arena; // display canvas
    swarmPanel controls; // control panel
    static int NUMBLUE = 15, NUMRED = 5, MAXPOP = 20;
    static double SPEED = 5.0;
    static int TURN = 15, MINDIST = 30, MAXDIST = 60;
    boolean paused = false;
    public void init() { // initialise applet components
    arena = new swarmCanvas();
    controls = new swarmPanel(NUMBLUE, NUMRED, MAXPOP);
    setLayout(new BorderLayout());
    add("Center", arena); // add canvas to applet at 'Center'
    add("South", controls); // add panel to applet at 'South'
    arena.requestFocus();
    public void start() { // start thread when applet starts
    if (animator == null) {
    animator = new Thread(this);
    animator.start();
    public void stop() { // stop thread when applet stops
    if (animator != null) {
    animator.stop();
    animator = null;
    public void run() {
    boolean flocking = false;
    while (true) {
    if (!flocking && arena.unpacked) { // once canvas component is unpacked
    Bird.setBoundaries(arena.w, arena.h); // set swarm boundaries
    arena.flock = new Flock(NUMBLUE, NUMRED, SPEED, TURN, MINDIST, MAXDIST);
    flocking = true;
    } else if (flocking) {
    Bird.setBoundaries(arena.w, arena.h);
    if (!paused)
    arena.flock.move(); // animate the flock
    arena.repaint(); // update display
    try {
    Thread.sleep(20); // interval between steps
    } catch (InterruptedException e) {}
    public boolean handleEvent(Event ev) { // check for control panel actions
    if (ev.id == Event.ACTION_EVENT && ev.target == controls.reset) {
    resetApplet(); // reset button pressed in controls
    return true;
    if (ev.id == Event.ACTION_EVENT && ev.target == controls.pause) {
    paused = !paused; // toggle paused status
    controls.pause.setLabel((paused) ? "Continue" : "Pause");
    return true;
    if (ev.target == controls.sbRed) {
    if (ev.id == Event.SCROLL_LINE_UP)
    arena.flock.removeBird(Color.red); // remove a red Bird from flock
    else if (ev.id == Event.SCROLL_LINE_DOWN)
    arena.flock.addBird(new Bird(Color.red)); // add a red Bird
    return true;
    if (ev.target == controls.sbBlue) {
    if (ev.id == Event.SCROLL_LINE_UP)
    arena.flock.removeBird(Color.blue); // remove a blue Bird from flock
    else if (ev.id == Event.SCROLL_LINE_DOWN)
    arena.flock.addBird(new Bird(Color.blue)); // add a blue Bird
    return true;
    return super.handleEvent(ev); // pass on unprocessed events
    public boolean keyDown(Event e, int x) { // check for key press
    boolean shiftKeyDown = ((e.modifiers & Event.SHIFT_MASK) != 0);
    if (shiftKeyDown) {
    if (x == Event.DOWN) Flock.minDISTANCE -= 5; // less separation
    if (x == Event.UP) Flock.minDISTANCE += 5; // more separation
    if (x == Event.LEFT) Flock.maxDISTANCE -= 5; // lower detection
    if (x == Event.RIGHT) Flock.maxDISTANCE += 5; // higher detection
    Barrier.minRANGE = Flock.minDISTANCE;
    Barrier.maxRANGE = Flock.maxDISTANCE;
    } else {
    if (x == Event.DOWN) Bird.maxSPEED -= 1.0; // slower
    if (x == Event.UP) Bird.maxSPEED += 1.0; // faster
    if (x == Event.LEFT) Bird.maxTURN -= 5; // less turning
    if (x == Event.RIGHT) Bird.maxTURN += 5; // more turning
    return true; // all key events handled
    public void resetApplet() {
    arena.flock = new Flock(NUMBLUE, NUMRED, SPEED, TURN, MINDIST, MAXDIST);
    controls.sbBlue.setValue(NUMBLUE); // initialise scrollbars
    controls.sbRed.setValue(NUMRED);
    * swarmPanel.class
    * A Panel holding two scrollbars and two buttons for controlling the
    * Swarm applet.
    * @see Swarm.class
    * @author Duncan Crombie
    * @version 2.01, 20 September 1997
    class swarmPanel extends Panel { // class defines applet control panel
    Button reset, pause;
    Scrollbar sbBlue = new Scrollbar(Scrollbar.HORIZONTAL);
    Scrollbar sbRed = new Scrollbar(Scrollbar.HORIZONTAL);
    Label label1, label2;
    * The construction method creates and adds control panel components
    swarmPanel(int numRed, int numBlue, int maxBoid) {
    setLayout(new GridLayout(2, 3)); // define 2 x 3 grid layout for controls
    label1 = new Label("Blue #");
    label1.setFont(new Font("Dialog", Font.PLAIN, 12)); add(label1);
    label2 = new Label("Red #");
    label2.setFont(new Font("Dialog", Font.PLAIN, 12)); add(label2);
    reset = new Button("Reset"); add(reset);
    sbBlue.setValues(numRed, 1, 0, maxBoid);
    add(sbBlue);
    sbRed.setValues(numBlue, 1, 0, maxBoid);
    add(sbRed);
    pause = new Button("Pause");
    add(pause);
    * swarmCanvas.class
    * A Canvas for displaying the Flock and Swarm parameters.
    * @see Swarm.class
    * @author Duncan Crombie
    * @version 2.01, 20 September 1997
    class swarmCanvas extends Canvas {
    Flock flock;
    Image offScrImg;
    boolean unpacked = false;
    int w, h;
    /* Double buffered graphics */
    public void update(Graphics g) {
    if (offScrImg == null || offScrImg.getWidth(this) != w || offScrImg.getHeight(this) != h)
    offScrImg = createImage(w, h);
    Graphics og = offScrImg.getGraphics();
    paint(og);
    g.drawImage(offScrImg, 0, 0, this);
    og.dispose();
    public void paint(Graphics g) {
    Dimension d = this.preferredSize();
    if (!unpacked) {
    this.w = d.width;
    this.h = d.height;
    unpacked = true;
    g.setColor(Color.white);
    g.fillRect(0, 0, w, h); // draw white background
    g.setColor(Color.black); // set font and write applet parameters
    g.setFont(new Font("Dialog", Font.PLAIN, 10));
    g.drawString("Bird Speed: " + Bird.maxSPEED, 10, 15);
    g.drawString("Bird Turning: " + Bird.maxTURN, 10, 30);
    g.drawString("Minimum Distance: " + Flock.minDISTANCE, 10, 45);
    g.drawString("Maximum Distance: " + Flock.maxDISTANCE, 10, 60);
    flock.display(g); // draw Flock members
    if (this.w != d.width || this.h != d.height)
    unpacked = false;
    public boolean mouseDown(Event ev, int x, int y) {
    int radius = Barrier.maxRANGE;
    boolean top, bottom;
    flock.addBird(new Barrier(x, y)); // place Barrier at click coordinates
    top = (y < radius);
    bottom = (y > h-radius);
    if (x < radius) { // if left
    flock.addBird(new Barrier(w + x, y));
    if (top) flock.addBird(new Barrier(w + x, h + y));
    else if (bottom) flock.addBird(new Barrier(w + x, y - h));
    } else if (x > w-radius) { // if right
    flock.addBird(new Barrier(x - w, y));
    if (top) flock.addBird(new Barrier(x - w, h + y));
    else if (bottom) flock.addBird(new Barrier(x - w, y - h));
    if (top) flock.addBird(new Barrier(x, h + y));
    else if (bottom) flock.addBird(new Barrier(x, y - h));
    return true;
    ===================================================================
    * Bird.class
    * This class defines the appearance and behaviour of a Bird object.
    * @see Swarm.class
    * @see Flock.class
    * @see Barrier.class
    * @author Duncan Crombie
    * @version 2.02, 21 September 1997
    import java.awt.*;
    class Bird {
    int iX, iY, iTheta;
    Color cFeathers;
    static int arenaWIDTH, arenaHEIGHT; // canvas dimensions
    static double maxSPEED; // speed of Bird
    static int maxTURN; // maximum turn in degrees
    Bird(int x, int y, int theta, Color feath) {
    iX = x;
    iY = y;
    iTheta = theta;
    cFeathers = feath;
    Bird(Color feath) {
    this((int)(Math.random() * arenaWIDTH),
    (int)(Math.random() * arenaHEIGHT),
    (int)(Math.random() * 360),
    feath);
    public void move(int iHeading) {
    int iChange = 0;
    int left = (iHeading - iTheta + 360) % 360;
    int right = (iTheta - iHeading + 360) % 360;
    if (left < right)
    iChange = Math.min(maxTURN, left);
    else
    iChange = -Math.min(maxTURN, right);
    iTheta = (iTheta + iChange + 360) % 360;
    iX += (int)(maxSPEED * Math.cos(iTheta * Math.PI/180)) + arenaWIDTH;
    iX %= arenaWIDTH;
    iY -= (int)(maxSPEED * Math.sin(iTheta * Math.PI/180)) - arenaHEIGHT;
    iY %= arenaHEIGHT;
    public void display(Graphics g) { // draw Bird as a filled arc
    g.setColor(this.cFeathers);
    g.fillArc(iX - 12, iY - 12, 24, 24, iTheta + 180 - 15, 30);
    public int getDistance(Bird bOther) {
    int dX = bOther.getPosition().x-iX;
    int dY = bOther.getPosition().y-iY;
    return (int)Math.sqrt(Math.pow(dX, 2) + Math.pow(dY, 2));
    static void setBoundaries(int w, int h) {
    arenaWIDTH = w;
    arenaHEIGHT = h;
    public int getTheta() {
    return iTheta;
    public Point getPosition() {
    return new Point(iX, iY);
    public Color getFeathers() {
    return cFeathers;
    =================================================================
    * Flock.class
    * This class creates and coordinates the movement of a flock of Birds.
    * @see Swarm.class
    * @see Bird.class
    * @see Barrier.class
    * @author Duncan Crombie
    * @version 2.02, 21 September 1997
    import java.util.Vector;
    import java.awt.*;
    class Flock { // implement swarming algorithm on flock of birds
    private Vector vBirds;
    static int minDISTANCE, maxDISTANCE;
    Flock(int nBlue, int nRed, double speed, int turn, int minDist, int maxDist) {
    vBirds = new Vector(5, 5);
    for (int i=0; i < nBlue + nRed; i++)
    addBird(new Bird((i < nBlue) ? Color.blue : Color.red));
    Bird.maxSPEED = speed;
    Bird.maxTURN = turn;
    Barrier.minRANGE = minDISTANCE = minDist;
    Barrier.maxRANGE = maxDISTANCE = maxDist;
    public void addBird(Bird bird) { // add Bird to vector
    vBirds.addElement(bird);
    synchronized void removeBird(Color col) { // remove Bird from vector
    for (int i=0; i < vBirds.size(); i++) { // loop through vector of Birds
    Bird bTemp = (Bird)vBirds.elementAt(i);
    if (bTemp.getFeathers() == col) { // search for Bird of given colour
    vBirds.removeElementAt(i); // if found, remove Bird..
    break; // ..and stop searching
    * The move function simply tells each Bird in the Vector vBirds to move
    * according to the resultant Point of generalHeading.
    synchronized public void move() {
    for (int i=0; i < vBirds.size(); i++) {
    Bird bTemp = (Bird)vBirds.elementAt(i);
    bTemp.move(generalHeading(bTemp));
    * The display function simply draws each Bird in the Vector vBirds at its
    * current position.
    public void display(Graphics g) { // display each Bird in flock
    for (int i=0; i < vBirds.size(); i++) {
    Bird bTemp = (Bird)vBirds.elementAt(i);
    bTemp.display(g);
    public Point sumPoints(Point p1, double w1, Point p2, double w2) {
    return new Point((int)(w1*p1.x + w2*p2.x), (int)(w1*p1.y + w2*p2.y));
    public double sizeOfPoint(Point p) {
    return Math.sqrt(Math.pow(p.x, 2) + Math.pow(p.y, 2));
    public Point normalisePoint(Point p, double n) {
    if (sizeOfPoint(p) == 0.0) return p;
    else {
    double weight = n / sizeOfPoint(p);
    return new Point((int)(p.x * weight), (int)(p.y * weight));
    * The generalHeading function determines the point a Bird will turn towards
    * in the next timestep. The Bird b checks for all Birds (other than self)
    * that fall within the detection range. If the Bird is of a different colour
    * or closer than the separation distance then they are repulsed else the
    * Birds are attracted according to the flocking algorithm.
    private int generalHeading(Bird b) {
    if (b instanceof Barrier) return 0;
    Point pTarget = new Point(0, 0);
    int numBirds = 0; // total of Birds to average
    for (int i=0; i < vBirds.size(); i++) { // for each Bird in array
    Bird bTemp = (Bird)vBirds.elementAt(i); // retrieve element i
    int distance = b.getDistance(bTemp); // get distance to Bird
    if (!b.equals(bTemp) && distance > 0 && distance <= maxDISTANCE) {
    * If the neighbour is a sibling the algorithm tells the boid to align its
    * direction with the other Bird. If the distance between them differs from
    * minDISTANCE then a weighted forces is applied to move it towards that
    * distance. This force is stronger when the boids are very close or towards
    * the limit of detection.
    if (b.getFeathers().equals(bTemp.getFeathers())) { // if same colour
    Point pAlign = new Point((int)(100 * Math.cos(bTemp.getTheta() * Math.PI/180)), (int)(-100 * Math.sin(bTemp.getTheta() * Math.PI/180)));
    pAlign = normalisePoint(pAlign, 100); // alignment weight is 100
    boolean tooClose = (distance < minDISTANCE);
    double weight = 200.0;
    if (tooClose) weight *= Math.pow(1 - (double)distance/minDISTANCE, 2);
    else weight *= - Math.pow((double)(distance-minDISTANCE) / (maxDISTANCE-minDISTANCE), 2);
    Point pAttract = sumPoints(bTemp.getPosition(), -1.0, b.getPosition(), 1.0);
    pAttract = normalisePoint(pAttract, weight); // weight is variable
    Point pDist = sumPoints(pAlign, 1.0, pAttract, 1.0);
    pDist = normalisePoint(pDist, 100); // final weight is 100
    pTarget = sumPoints(pTarget, 1.0, pDist, 1.0);
    * In repulsion the target point moves away from the other Bird with a force
    * that is weighted according to a distance squared rule.
    else { // repulsion
    Point pDist = sumPoints(b.getPosition(), 1.0, bTemp.getPosition(), -1.0);
    pDist = normalisePoint(pDist, 1000);
    double weight = Math.pow((1 - (double)distance/maxDISTANCE), 2);
    pTarget = sumPoints(pTarget, 1.0, pDist, weight); // weight is variable
    numBirds++;
    if (numBirds == 0) return b.getTheta();
    else // average target points and add to position
    pTarget = sumPoints(b.getPosition(), 1.0, pTarget, 1/(double)numBirds);
    int targetTheta = (int)(180/Math.PI * Math.atan2(b.getPosition().y - pTarget.y, pTarget.x - b.getPosition().x));
    return (targetTheta + 360) % 360; // angle for Bird to steer towards
    ======================================================================
    * Barrier.class
    * This class creates and coordinates the movement of a flock of Birds.
    * @see Swarm.class
    * @see Flock.class
    * @see Bird.class
    * @author Duncan Crombie
    * @version 2.01, 21 September 1997
    import java.awt.*;
    class Barrier extends Bird {
    static int minRANGE, maxRANGE;
    Barrier(int x, int y) {
    super(x, y, 0, Color.black); // position Barrier and define color as black
    public void move(int dummy) {
    // do nothing
    public void display(Graphics g) { // paint Barrier
    g.setColor(Color.black);
    g.fillOval(this.iX-5, this.iY-5, 10, 10);
    g.setColor(Color.gray); // paint separation circle
    g.drawOval(this.iX-minRANGE, this.iY-minRANGE, 2*minRANGE, 2*minRANGE);
    g.setColor(Color.lightGray); // paint detection circle
    g.drawOval(this.iX-maxRANGE, this.iY-maxRANGE, 2*maxRANGE, 2*maxRANGE);
    =====================================================================
    import java.awt.*;
    import java.awt.event.*;
    public class SwarmFrame extends Frame implements ActionListener {
    public SwarmFrame() {
    super("Flocking Bird");
    MenuBar mb = new MenuBar();
    setMenuBar(mb);
    Menu fileMenu = new Menu("File");
    mb.add(fileMenu);
    MenuItem exitMenuItem = new MenuItem("Exit");
    fileMenu.add(exitMenuItem);
    exitMenuItem.addActionListener(this);
    Swarm swarmApplet = new Swarm();
    add(swarmApplet, BorderLayout.CENTER);
    swarmApplet.init();
    public void actionPerformed(ActionEvent evt) {
    if(evt.getSource() instanceof MenuItem) {
    String menuLabel = ((MenuItem) evt.getSource()).getLabel();
    if(menuLabel.equals("Exit")) {
    dispose();
    System.exit(0);
    =====================================================================
    import java.awt.*;
    public class SwarmApplication {
    public static void main(String[] args) {
    Frame frame = new SwarmFrame();
    frame.setBounds(10, 10, 600, 400);
    frame.setVisible(true);

  • Smart Objects...changing canvas size problem

    When changing the canvas size of a smart object, the layer on the original document will distort visually since it doesn't update the size of the smart object.
    Is there a solution to this, or an easy way to quickly update every instance of the smart object on the original doc?
    To clarify: I know that you can change the dimensions of the smart object on the original doc and it'll fix it, my question is if there's a way to automatically have that happen and have the original doc smart objects respect your canvas size changes on the smart object doc.
    Reproduce:
    1) Draw a circle
    2) Turn it into a smart object
    3) Go into the smart object, change the canvas size by increasing the height of the canvas. The smart object should now have a circle with blank space above/below it.
    4) Save the smart object
    5) The circle on the original document will now be squished.
    I'm using Photoshop CS5

    xg3 wrote:
    When changing the canvas size of a smart object, the layer on the original document will distort visually since it doesn't update the size of the smart object.
    When you change the canvas size of a document the only layer that will change is a backgroung layer for it does not support transparency so its pixels will be changed.  However a background layer should not distort it may be cropped  and have canvas added in which case the color of the empty canvas can be set in the canvas size dialog.  All other layer including Smart Object layer should not chang at all.  Layer positioning in relationship to the canvas  and the new canvas size is set during the canvas size change.  Layers can be any size and have any aspect ratio. Their sizes can be smaller, the same or larger then the canvas size. Even layer that can fit  within a documents canvas size may be positioned so that all, some or none of the layer is over the documents canvas.
    I do not know what you mean when you write the original document chages. A smart object layer has an embedded copy of an object. The original document is not touched. You can open the smart object layer embedded object in  Photoshop by double clicking on the smart object icon in the layers palette smart object layer and change it size. And distort it f you wish. When you use Photoshop save. Photoshop will change the enbedded object in the smart object layer. You can also leave the embedded smaro object as is and change the smart object layer size and distort it using transform on the smart object layer itsself.
    I think what you did was to open the smart object in photoshop change its canvas saze then save it. The updated smart object is realy round but you dont see that it is becaue it is being transformec ti fit the original documents canvas. If you do a Canvas size on the codument you will see the original docyment canvas size is not change and thet your now squaching a now changed taller object into a shorter canvas.  With each Smart Obkect layer there is as associated transform.
    No I was wrong I just tried that and it looks like the transform was not the problem as yo can see I dir a Ctrl+T so you can see the size of the smart object layer is now biger then the original document and is positioned centered canvas is still 300x300 white area in image

  • Scroll Positions do not work if Scroll Policy is 'off'

    I am using flex SDK 3.3.0.4852
    I have a canvas with
    canvas.horizontalScrollPolicy = "off";
    canvas.verticalScrollPolicy = "off";
    This canvas has an image in it, and I set the horizontal and vertical scroll positions programitically.
    canvas.horizontalScrollPosition = canvas.maxHorizontalScrollPosition;
    canvas.verticalScrollPosition = canvas.maxVerticalScrollPosition;
    then I save the scroll values in an xml file, and then on reopening of the xml file.. I do the following
    canvas.addEventListener("creationComplete", setScrollPositions);
    and in the method setScrollPositions(event) i do the following again
    canvas.horizontalScrollPosition = canvas.maxHorizontalScrollPosition;
    canvas.verticalScrollPosition = canvas.maxVerticalScrollPosition;
    But unfortunately it does not show any change in the scroll positions visually, and the default scroll positions persists. Though if i call an alert
    Alert.show(canvas.verticalScrollPosition.toString()); //it does show me some value, e.g. 56
    Now if i only set horizontal and vertical scrollPolicy = "on" ... all works fine. But the problem is that I want to hide my scrollbars and there is no other way I can do it. So please if there is any solution to it or if there is any workaround, do let me know. Thanks.

    i'm having the same problem and i just got a brand new dell..when i hold down the left click over the up or down arrows, my songs in itunes only go down one line rather than scrolling up or down while im holding down the left click...any help is appreciated..

  • Applet in a .jar file?

    I want to program a program which can be used as application or as applet. Is it possible to create a .jar file and use something inside as applet? What would the <applet> tag look like?

    Sorry, I guess I thought you had this working already. In any case, here is an example of some JApplet code that runs either as an applet on a web page or as an application in a JFrame. It is the applet from the html-applet tag example I provided above. It is missing some classes, so it won't compile of course, but it shows all the applet vs. application code. This methodology also works in older non-swing applets ...just follow a technique similar to what you see below:
    If you didn't need to see this ...please just ignore it. Good luck.
    /** Applet or application example. */
    public class RasterGameOfLife extends javax.swing.JApplet {
      RasterLifeCanvas canvas;                // The drawing area
      RasterLifeCanvas.LifeControls controls; // The drawing controls
      /** the applets init method sets up some gui components */
      public void init() {
        canvas = new RasterLifeCanvas();
        controls = canvas.getControls();
        getContentPane().setLayout( new java.awt.BorderLayout() );
        getContentPane().add( "Center", canvas );
        getContentPane().add( "South", controls );
      /** the applets destroy method cleans up after execution */
      public void destroy() {
        remove( controls );
        remove( canvas );
      /** the applets start method enables and begins an animation sequence */
      public void start() {
        controls.setEnabled( true );
        controls.startAnimation();
      /** the applets stop method stops and disables an animation sequence */
      public void stop() {
        controls.stopAnimation();
        controls.setEnabled( false );
       * main is where the alternative application code is placed
       * this code does not execute when the program is run as an applet
      public static void main(String args[]) {
        javax.swing.JFrame f = new javax.swing.JFrame();      // create a JFrame for the application
        final RasterGameOfLife life = new RasterGameOfLife(); // create an instance of the applet
        life.init();     // Manually call the init method
        life.start();    // Manually call the start method
        f.addWindowListener( new java.awt.event.WindowAdapter() {
          public void windowClosing( java.awt.event.WindowEvent e ) {
            life.stop(); // Manually call the stop method
            System.exit(0);
        f.getContentPane().add( "Center", life );
        // or sometimes I use this alternative to get the applets contentPane
        //f.getContentPane().add( "Center", life.getContentPane() );
        f.setSize( 734, 435 );
        f.show();
    }

  • Determining Applet Window location

    How can I get the actual window position of the root applet window (The Browser window, actually).
    No matter where I place the browser window, the root window always reports 0,0 for x,y (as shown below).
    I like to popup my dialogs centered in my applet, but that only works if the browser is displayed in the
    upper left corner of the display. As soon as the user moves it, the information below is incorrect.
    root window sun.beans.ole.OleEmbeddedFrame[frame0,0,0,730x480,invalid,layout=java.awt.BorderLayout,resizable,title=]

    Use the following to find your applet x,y locations on the screen:
    int x=this.getLocationOnScreen().x;
    int y=this.getLocationOnScreen().y;
    where this is the component whose screen coordinate is desired -- the example shown above can be used in the applet's init method.
    V.V.
    PS: you may have to include the following in your source file:
    import java.awt.*;

  • Multiple canvases overlapping other canvas

    I have 3 canvases in one form. The first one will appear at the top and the other 2 will appear at the bottom. I have created a radio button in the first canvas to allow the user to have to option to choose. If the first option is choosed, the 2nd canvas will appear at the bottom of the screen(3rd canvas will be hidden) and if the 2nd option is selected, the 3rd canvas will appear same position as 2nd canvas and the 2nd canvas will be hidden.
    The "VIEWPORT_Y_POS" and ""VIEWPORT_Y_POS_ON_CANVAS" for the 1st canvas is set to ZERO while the 2nd and 3rd is set to 200.
    The "HEIGHT" property for the 1st canvas is 155 and the other 2 canvases is 480.
    During the POST_NEW_FORM and after the user selected the second option, the 1st canvas and 3rd canvas display nicely(the 2nd canvas hidden). But after the data being displayed and some of the fields in the 3rd canvas has been enabled, the 3rd canvas being overlapped by the first canvas at the top portion.
    I have double checked the coding and there is no run-time setting the canvas viewport Y position property. What was wrong with the setting? This program has been running in our production server(Application Server 9.0.2) quite some time without any problem. But, when copied to our development server(application server 9.0.4), it gave me this kind of problem.
    Is this a bug for the newer version of application server? or it's the setting problem to the canvas?

    I have tried to set the viewport of the canvas programatically during run-time, but seems like the same problem happened.
    I tried to set the viewport Y position on canvas to Zero instead of 200 and then the viewport Y position to 200 at design-time. My problem solved!
    But the question is why the 2nd canvas didn't give me this kind of problem even I have set the viewport Y position on canvas same as the 3rd canvas(the canvas will appear same position as the 3rd canvas) wherelse the 3rd canvas did?
    Another question is why when I run this form on the Apps Server 9.0.2 no problem but Apps Server 9.0.4 did?
    Thanks.
    Cheong

  • Setting stacked canvas properties when inside a tab canvas

    Hi all,
    I grope setting the x and y position of a stacked canvas programmatically : I work inside a tab canvas , there is one multirecord based block which is split into two tab pages. The problem is that the x and y positions of each first item in each tab of the block are no the same. And I want to hide and show the stacked canvas on which is based the scrollbar of the block , according to the top_most_tab_page.
    The stacked canvas has the same width and height as the tab canvas ; it has viewport width set to the width of the scrollbar , say 0.415 ; it has viewport height set to the length of the scrollbar , say 1.833 ; the viewport X/Y position on canvas properties are set to 0.
    I tried to set the VIEWPORT_X_POS and VIEWPORT_Y_POS properties of the view programmatically to place the scrollbar just sticky with the first item when in each tab page , but the scrollbar is not displayed on the desired place. It is moved.
    So how to place the stacked canvas at the right position to be stuck with the left first item ?
    Thank you very much indeed.

    I did a little test and it works (it'll only take you 3 min)
    Create a new Form.
    Add 3 Canvases 1 Content and 2 Tab with the following Properties
    Content
    Vieport X Position on Canvas: 0
    Vieport Y Position on Canvas: 0
    Width: 540
    Height: 324
    Master Tabs
    Vieport X: 35
    Vieport Y: 20
    Vieport Width: 460
    Vieport Heigth: 280
    Detail Tabs
    Vieport X: 150
    Vieport Y: 95
    Vieport Width: 260
    Vieport Heigth: 160
    Then go to Layout editor and while viewing the Content Canvas go to the menu View -> Stacked View...
    From there select both tab canvases to be shown.
    Also add a dummy item (i.e a button )somewhere in the form otherwise nothing will appear when you run the form.

  • Tab canvas never displayed

    Hello alll,
    i have just created a form with master form and tab canvas
    have no reason why on run time only the master block is displayed ..?!!!
    ==================================================
    Have any one some reasons...??
    Regards,
    Abdetu..

    Hi again,
    i found it...
    My problem was that all canvases has same view port so i have changed the the view y position on canvas on the tab one and so it wa disappearing behind the content one since both have the same view y position =0
    Regards,
    Abdetu.

  • Tab canvas inside a tab canvas

    Anyone knows how to put a tab canvas inside a tab canvas.
    thanks.

    I did a little test and it works (it'll only take you 3 min)
    Create a new Form.
    Add 3 Canvases 1 Content and 2 Tab with the following Properties
    Content
    Vieport X Position on Canvas: 0
    Vieport Y Position on Canvas: 0
    Width: 540
    Height: 324
    Master Tabs
    Vieport X: 35
    Vieport Y: 20
    Vieport Width: 460
    Vieport Heigth: 280
    Detail Tabs
    Vieport X: 150
    Vieport Y: 95
    Vieport Width: 260
    Vieport Heigth: 160
    Then go to Layout editor and while viewing the Content Canvas go to the menu View -> Stacked View...
    From there select both tab canvases to be shown.
    Also add a dummy item (i.e a button )somewhere in the form otherwise nothing will appear when you run the form.

Maybe you are looking for