Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Inserting a Line in front(top ) of a imageview Problems. (x,y) issues

Andre LopesSep 8 2012 — edited Sep 16 2012
Hi Guys, so, im making a concept of a Round-robin , i think. Its called Fila Circular in Portuguese. Anyway, the thing is, every time the user press Push, a ball(aka circle) must enter the [index] of the hexagon. But, im having issues making the path.


When i Mess the X, the Y changes. When i Mess the Y, the X changes.

Heres the Fully Code, and a picture so you can analyze , in that picture, the startX was very clsoe to 0 as startY was also.But when i moved the endX, it came down all the way.

First the link :
http://img17.imageshack.us/img17/5696/duvidajavafx.jpg

Now the Code of the two Classes :

Please help me.

package filacircular;

import java.net.MalformedURLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.effect.BlendMode;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
import javafx.scene.paint.Color;
import javafx.scene.shape.CubicCurve;
import javafx.scene.shape.Line;

/**
 *
 * @author André
 */
public class FilaCircular extends Application {

    private int vet[] = new int[5];
    private int begin;
    private int last;
    private boolean queueFull;

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        Controle c = new Controle();

        StackPane root = new StackPane();
        Scene scene = new Scene(root, 750, 750, Color.GHOSTWHITE);

        ImageView imv = null;
        GridPane gp = new GridPane();
        gp.setHgap(5);
        gp.setVgap(5);

        //
        Button pushBeginBt = new Button("Push From Begin");
        pushBeginBt.setPrefSize(150, 25);
        
        Button pushEndBt = new Button("Push From End");
        pushEndBt.setPrefSize(150,25);

        Button pullBeginBt = new Button("Pull From Begin");
        pullBeginBt.setPrefSize(150, 25);
        
        Button pullEndBt = new Button("Pull From End");
        pullEndBt.setPrefSize(150,25);

        Label sizeLabel = new Label("Size");
        TextField textSize = new TextField("5");
        textSize.setEditable(false);
       

        Label beginLabel = new Label("Begin");
        TextField textBegin = new TextField("");
        textBegin.setEditable(false);
        
        
        Label lastLabel = new Label("Last Var");
        TextField textLast = new TextField("");
        textLast.setEditable(false);
       
        
        Label queueLabel = new Label("Queue");
        TextField textqueueFull = new TextField("");
        textqueueFull.setEditable(false);
        queueLabel.setPrefSize(100,10);
        
        try {
            imv = c.getImage();
            gp.add(imv,8,25);
            imv.toBack();
            imv.setOpacity(0.5);
         
        } catch (MalformedURLException ex) {
            System.out.println("\nError While Loading Image : \n");
            System.out.println(ex.getMessage() + " Finished Transmitting Error;");
        }
        
        Line l4 = c.getPathTo4();
        gp.setGridLinesVisible(true);
        gp.add(l4,8,25);
        gp.toBack();
        l4.toFront();
        l4.setVisible(true);
        
      
        System.out.println("X: " + imv.getX());
        System.out.println("Y: " + imv.getY());
        
        gp.add(textSize,1, 13);
        gp.add(sizeLabel, 3, 13);

        gp.add(textBegin,1, 15);
        gp.add(beginLabel, 3, 15);

        gp.add(textLast,1, 17);
        gp.add(lastLabel, 3, 17);

        gp.add(textqueueFull,1, 19);
        gp.add(queueLabel, 3, 19);

        gp.add(pushBeginBt,1, 5);
        gp.add(pushEndBt,4,5);
        
        gp.add(pullBeginBt,1, 10);
        gp.add(pullEndBt,4,10);
        
       
        root.getChildren().add(gp);
        primaryStage.setTitle("Minha Pilha Circular");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

     public boolean enQueue(int elem)
    {
        if(isFull()) return false;
        else{
            vet[last++] = elem;
            if(last == vet.length) last = 0;
            if(last == begin) queueFull = true;
        return true;
        } 
    }
    
     
     
     
     
     
     
    public boolean isFull()
    {return queueFull;}
    
    private int size()
    {
     if (last >= begin && !queueFull)return vet.length + last - begin;
     return vet.length + last - begin;
    }
    
     public boolean isEmpty()
    {return (size()==0);}
    
    public int front()
    {
        return vet[begin];
        
    }
    
    public int deQueue()
    {
        
    int aux = vet [begin++];

    if(begin==vet.length) begin = 0;
    queueFull = false;
    return aux;
    
    }
     
     
    public int[] getVet() {
        return vet;
    }

    public void setVet(int[] vet) {
        this.vet = vet;
    }

    public int getBegin() {
        return begin;
    }

    public void setBegin(int begin) {
        this.begin = begin;
    }

    public int getLast() {
        return last;
    }

    public void setLast(int last) {
        this.last = last;
    }

    public boolean isQueueFull() {
        return queueFull;
    }

    public void setQueueFull(boolean queueFull) {
        this.queueFull = queueFull;
    }
}
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package filacircular;

import java.io.File;
import java.net.MalformedURLException;
import javafx.animation.PathTransition;
import javafx.scene.Node;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.shape.CubicCurve;
import javafx.scene.shape.CubicCurveBuilder;
import javafx.scene.shape.Line;
import javafx.scene.shape.LineBuilder;
import javafx.scene.shape.Path;
import javafx.util.Duration;

/**
 *
 * @author André Vinícius Lopes
 */
public class Controle {

    public ImageView getImage() throws MalformedURLException
    {
        
        String path = "D://FilaCircular.jpg";
        String f = new File(path).toURI().toURL().toExternalForm();
       
        
        ImageView imv = new ImageView(f);
        return imv;
    }
    
    
    public PathTransition getPathToStack(Node n, Path p)
    {
        PathTransition pt = new PathTransition();
        pt.setNode(n);
        pt.setPath(p);
        pt.setDuration(Duration.millis(2000));
        
        
        return pt;
    }
    
   public Line getPathTo4()
   {
     Line l = LineBuilder.create()
             
             .startX(100)
             .startY(-50)
             .endX(300)
             .endY(50)
             .build();
     
              
      
      
       return l;
   }
    
    
}
Edited by: Andre Lopes on 08/09/2012 21:43
This post has been answered by jmart on Sep 12 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 14 2012
Added on Sep 8 2012
12 comments
379 views