Java Code Examples for javax.swing.JLabel.setLocation()

The following are Jave code examples for showing how to use setLocation() of the javax.swing.JLabel class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: Proyecto-DASI   File: VisorCreacionEscenarios1.java   View Source Code Vote up 7 votes
public void addEntidadEnEscenario (String rutaIcono, String idEntidad, Point puntoLoc){
         JLabel label = new JLabel();
       
//          String rutaImagen=directorioTrabajo+rutaIconos+imageniconoMujer;
//           numeroRobots= escenrioSimComp.getNumRobots();
//           numeroRobots++;
//           intervalNumRobots.setText(""+numeroRobots);
//           identEntidad=tipoEntidad+numeroRobots;
//           escenrioSimComp.addRoboLoc(identEntidad, new Point(coordX,coordY));
//           intervalNumRobots.setText(""+numeroRobots);
           label.setText(idEntidad);
        label.setBounds(10, 10, 100, 100);
        this.add(label);
        label.setVisible(true);
        label.setIcon(new ImageIcon(rutaIcono));
        label.setLocation(puntoLoc);
        moverComp.registerComponent(label);
        this.listaEntidadesEnEscenario.add(label);
        System.out.println( "Se crea la entidad : "+label.getText()+ " Punto : =" + puntoLoc );
//       tablaEntidadesEnEscenario.put(identEntidad, label);
    }
 
Example 2
Project: myster   File: MessageManager.java   View Source Code Vote up 7 votes
public MessagePreferencesPanel() {
    setLayout(null);

    refuseMessages = new JCheckBox("Refuse Messages");
    refuseMessages.setSize(150, 25);
    refuseMessages.setLocation(10, 25);
    refuseMessages.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            updateEnabled();
        }
    });
    add(refuseMessages);

    denyMessageLabel = new JLabel("Refusal Message:");
    denyMessageLabel.setSize(150, 25);
    denyMessageLabel.setLocation(20, 50);
    add(denyMessageLabel);

    denyMessageText = new JTextField(REFUSAL_MESSAGE_DEFAULT);
    denyMessageText.setSize(400, 25);
    denyMessageText.setLocation(25, 75);
    add(denyMessageText);

    setSize(STD_XSIZE, STD_YSIZE);
}
 
Example 3
Project: freecol   File: MapViewer.java   View Source Code Vote up 6 votes
private JLabel enterUnitOutForAnimation(final Unit unit,
                                        final Tile sourceTile) {
    Integer i = unitsOutForAnimation.get(unit);
    if (i == null) {
        final JLabel unitLabel = createUnitLabel(unit);

        i = 1;
        Point tileP = calculateTilePosition(sourceTile);
        Point unitP = calculateUnitLabelPositionInTile(unitLabel.getWidth(),
            unitLabel.getHeight(), tileP);
        unitLabel.setLocation(unitP);
        unitsOutForAnimationLabels.put(unit, unitLabel);
        gui.getCanvas().add(unitLabel, JLayeredPane.DEFAULT_LAYER);
    } else {
        i++;
    }
    unitsOutForAnimation.put(unit, i);
    return unitsOutForAnimationLabels.get(unit);
}
 
Example 4
Project: FreeCol   File: MapViewer.java   View Source Code Vote up 6 votes
private JLabel enterUnitOutForAnimation(final Unit unit,
                                        final Tile sourceTile) {
    Integer i = unitsOutForAnimation.get(unit);
    if (i == null) {
        final JLabel unitLabel = createUnitLabel(unit);

        i = 1;
        unitLabel.setLocation(calculateUnitLabelPositionInTile(
                unitLabel.getWidth(), unitLabel.getHeight(),
                calculateTilePosition(sourceTile)));
        unitsOutForAnimationLabels.put(unit, unitLabel);
        gui.getCanvas().add(unitLabel, JLayeredPane.DEFAULT_LAYER);
    } else {
        i++;
    }
    unitsOutForAnimation.put(unit, i);
    return unitsOutForAnimationLabels.get(unit);
}
 
Example 5
Project: myster   File: ProgressWindow.java   View Source Code Vote up 6 votes
public ProgressPanel() {
    setLayout(null);

    progressBar = new ProgressBar();
    progressBar.setLocation(PROGRESS_X_OFFSET, PROGRESS_Y_OFFSET);
    progressBar.setSize(440, 10);
    progressBar.setForeground(Color.blue);
    add(progressBar);

    textLabel = new JLabel();
    textLabel.setLocation(X_TEXT_OFFSET, Y_TEXT_OFFSET);
    textLabel.setSize(X_SIZE - X_TEXT_OFFSET - ADDITIONAL_X_SIZE, 20);
    add(textLabel);

    additionalLabel = new JLabel();
    additionalLabel.setLocation(X_SIZE - ADDITIONAL_X_SIZE, Y_TEXT_OFFSET);
    additionalLabel.setSize(ADDITIONAL_X_SIZE, 20);
    add(additionalLabel);
}
 
Example 6
Project: Progetto-B   File: CardListener.java   View Source Code Vote up 5 votes
/**
 * When the cursor hovers over a card, the card is moved to the front.
 *
 * @param e
 */
@Override
public void mouseEntered(MouseEvent e) {
    if (game.getPhase().equals(PLAY_CARDS)) {
        JLabel label = (JLabel) e.getComponent();
        cardPanel.getCardsPane().setLayer(label, 1);
        String card = (String) label.getClientProperty("name");
        label.setIcon(new ImageIcon("src/resources/images/" + card + "_BLACK.png"));
        Point p = label.getLocation();
        Point p1 = new Point(p.x, HIGH_Y);
        label.setLocation(p1);
        cardPanel.updateUI();
    }
}
 
Example 7
Project: Progetto-B   File: CardListener.java   View Source Code Vote up 5 votes
/**
 * When the cursor exits a card, the card is moved back to its original
 * depth.
 *
 * @param e
 */
@Override
public void mouseExited(MouseEvent e) {
    if (game.getPhase().equals(PLAY_CARDS)) {
        JLabel label = (JLabel) e.getComponent();
        cardPanel.getCardsPane().setLayer(label, cardPanel.getLabelLayer(label));
        String card = (String) label.getClientProperty("name");
        label.setIcon(new ImageIcon("src/resources/images/" + card + ".png"));
        Point p = label.getLocation();
        Point p1 = new Point(p.x, LOW_Y);
        label.setLocation(p1);
        cardPanel.updateUI();
    }
}
 
Example 8
Project: geomapapp   File: StartUp.java   View Source Code Vote up 5 votes
public StartUp( int which ) {
	try {
		URL url = null;
		switch (which) {
			case MapApp.MERCATOR_MAP:
				url = cl.getResource(startUpPath +"smallmapV3.jpg"); //New version3 images
				break;
			case MapApp.SOUTH_POLAR_MAP:
				url = cl.getResource(startUpPath + "MapAppSouthV3.jpg");
				break;
			case MapApp.NORTH_POLAR_MAP:
				url = cl.getResource(startUpPath + "MapAppNorthV3.jpg");
				break;
			case MapApp.WORLDWIND:
				url = cl.getResource(startUpPath + "VirtualOceanV3.jpg");
				break;
			default:
				url = cl.getResource(startUpPath + "smallmap.jpg");
		}
		image = ImageIO.read(url);
	} catch (Exception ex) {
		System.out.println(ex + " null");
		image=null;
	}
	setLayout(null);
	label = new JLabel("Initializing MapApp...");
	label.setFont( new Font("SansSerif", Font.PLAIN, 12) );
	label.setForeground( Color.black );
//	add( label );
	label.setLocation(10, 50);
	label.setSize( label.getPreferredSize() );
	JButton button = new JButton( "Abort" );
	add( button );
	button.setLocation( 3, 3);
	button.setSize( button.getPreferredSize() );
	button.addActionListener( this );
//	System.out.println( getComponentCount() + " components" );
	setBorder( BorderFactory.createLineBorder(Color.black, 2) );
}
 
Example 9
Project: Progetto-A   File: PartitaOfflineGuiView.java   View Source Code Vote up 5 votes
private JLabel stampaCartaMobileDeckShuffle(int x, int y, String carta, int spazio) {
    JLabel card = new JLabel(caricaImmagine("dominio/immagini/mazzo/" + carta + ".png"));
    
    card.setBounds(x, y, 75, 113);
    
    sfondo.add(card);
    sfondo.repaint();
    
    for(int i = 0; i < ((this.getWidth()/2 + 20) - x - 8*spazio); i++) {
        card.setLocation(x + i, y);
        pausa(1);
        sfondo.repaint();
    }
    return card;
}
 
Example 10
Project: Progetto-A   File: PartitaOnlineGuiView.java   View Source Code Vote up 5 votes
private JLabel stampaCartaMobileDeckShuffle(int x, int y, String carta, int spazio) {
    JLabel card = new JLabel(caricaImmagine("dominio/immagini/mazzo/" + carta + ".png"));

    card.setBounds(x, y, 75, 113);

    sfondo.add(card);
    sfondo.repaint();

    for (int i = 0; i < ((this.getWidth() / 2 + 20) - x - 8 * spazio); i++) {
        card.setLocation(x + i, y);
        pausa(1);
        sfondo.repaint();
    }
    return card;
}
 
Example 11
Project: freecol   File: UnitMoveAnimation.java   View Source Code Vote up 4 votes
/**
 * {@inheritDoc}
 */
@Override
public void executeWithUnitOutForAnimation(JLabel unitLabel) {
    final SwingGUI gui = (SwingGUI)getGUI();
    final float scale = gui.getMapScale();
    final int movementRatio = (int)(Math.pow(2, this.speed + 1) * scale);
    final Rectangle r1 = gui.getTileBounds(this.sourceTile);
    final Rectangle r2 = gui.getTileBounds(this.destinationTile);
    final Rectangle bounds = r1.union(r2);
    final double xratio = ImageLibrary.TILE_SIZE.width
        / (double)ImageLibrary.TILE_SIZE.height;

    // Tile positions should be valid at this point.
    final Point srcP = gui.getTilePosition(this.sourceTile);
    if (srcP == null) {
        logger.warning("Failed move animation for " + this.unit
            + " at source tile: " + this.sourceTile);
        return;
    }
    final Point dstP = gui.getTilePosition(this.destinationTile);
    if (dstP == null) {
        logger.warning("Failed move animation for " + this.unit
            + " at destination tile: " + this.destinationTile);
        return;
    }
        
    final int labelWidth = unitLabel.getWidth();
    final int labelHeight = unitLabel.getHeight();
    final Point srcPoint = gui.calculateUnitLabelPositionInTile(labelWidth,
        labelHeight, srcP);
    final Point dstPoint = gui.calculateUnitLabelPositionInTile(labelWidth,
        labelHeight, dstP);
    final int stepX = (srcPoint.getX() == dstPoint.getX()) ? 0
        : (srcPoint.getX() > dstPoint.getX()) ? -1 : 1;
    final int stepY = (srcPoint.getY() == dstPoint.getY()) ? 0
        : (srcPoint.getY() > dstPoint.getY()) ? -1 : 1;

    int dropFrames = 0;
    Point point = srcPoint;
    while (!point.equals(dstPoint)) {
        long time = System.currentTimeMillis();
        point.x += stepX * xratio * movementRatio;
        point.y += stepY * movementRatio;
        if ((stepX < 0 && point.x < dstPoint.x)
            || (stepX > 0 && point.x > dstPoint.x)) {
            point.x = dstPoint.x;
        }
        if ((stepY < 0 && point.y < dstPoint.y)
            || (stepY > 0 && point.y > dstPoint.y)) {
            point.y = dstPoint.y;
        }
        if (dropFrames <= 0) {
            unitLabel.setLocation(point);
            gui.paintImmediatelyCanvasIn(bounds);
            int timeTaken = (int)(System.currentTimeMillis()-time);
            final int waitTime = ANIMATION_DELAY - timeTaken;
            if (waitTime > 0) {
                Utils.delay(waitTime, "Animation interrupted.");
                dropFrames = 0;
            } else {
                dropFrames = timeTaken / ANIMATION_DELAY - 1;
            }
        } else {
            dropFrames--;
        }
    }
    gui.refresh();
}
 
Example 12
Project: Proyecto-DASI   File: VisorCreacionEscenarios1.java   View Source Code Vote up 4 votes
public JLabel crearIconoRobVict(String tipoEntidad, int coordX, int coordY){
        
        JLabel label = new JLabel();
        int correccionX=-30;
        int correccionY=-93;
//        int correccionX=0;
//        int correccionY=0;
        coordX=coordX+correccionX;
        coordY=coordY+correccionY;
        String rutaImagen;
        String identEntidad;
       if ( tipoEntidad.startsWith("Robot")){
           rutaImagen=directorioTrabajo+rutaIconos+imageniconoRobot;
           numeroRobots= escenarioActualComp.getNumRobots();
           
         
//           intervalNumRobots.setText(""+numeroRobots);
             numeroRobots++;
             identEntidad=tipoEntidad+numeroRobots;
           escenarioActualComp.addRoboLoc(identEntidad, new Point(coordX,coordY));
           intervalNumRobots.setText(""+numeroRobots);
//           label.setText(tipoEntidad+numeroRobots);
           
       }
       else{
        rutaImagen=directorioTrabajo+rutaIconos+imageniconoMujer;
        mumeroVictimas= escenarioActualComp.getNumVictimas();
        mumeroVictimas++;
//         intervalNumVictimas.setText(""+mumeroVictimas);
         identEntidad=tipoEntidad+mumeroVictimas;
         escenarioActualComp.addVictimLoc(identEntidad, new Point(coordX,coordY));
//         mumeroVictimas=escenrioSimComp.getNumVictimas();
         intervalNumVictimas.setText(""+mumeroVictimas);
//         identEntidad=tipoEntidad+mumeroVictimas;
//         label.setText(tipoEntidad+mumeroVictimas);
       }
        
        label.setText(identEntidad);
        label.setBounds(10, 10, 100, 100);
//        label.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
//            @Override
//            public void mouseDragged(java.awt.event.MouseEvent evt) {
//                jLabelMouseDragged(evt);
//            }
//            public void mouseReleased(java.awt.event.MouseEvent evt) {
//                jLabelMouseReleased(evt);
//            }
//        });
        
        this.add(label);
        label.setVisible(true);
        
//        label.setIcon(new ImageIcon("E:\\FicheroRed\\Github\\rosaceSIM\\src\\utilsDiseniaEscenariosRosace\\Robot.png"));
        label.setIcon(new ImageIcon(rutaImagen));
        label.setLocation(coordX, coordY);
        this.listaEntidadesEnEscenario.add(label);
        System.out.println( "Se crea la entidad : "+label.getText()+ " Coordenadas : X =" + coordX +" , Y = " +coordY );
//       tablaEntidadesEnEscenario.put(identEntidad, label);
//       listaEntidadesEnEscenario.add(label);
        
       moverComp.registerComponent(label);
        return label;
    }
 
Example 13
Project: Proyecto-DASI   File: VisorMovimientoEscenario.java   View Source Code Vote up 4 votes
public synchronized void cambiarPosicionRobot(String idRobot, int nueva_coordx, int nueva_coordy) {

//        String numeroRobot = getNumeroRobot(idRobot);
//       System.out.println("Peticiones de cambio de posicion  Robot : "+ idRobot+ " CoordX: " +nueva_coordx + " CoordY: " +nueva_coordy );
        //JLabel jlabelRobot = new JLabel();
        if (tablaEntidadesEnEscenario!=null){
        JLabel jlabelRobot = tablaEntidadesEnEscenario.get(idRobot);

        if (jlabelRobot != null) {
//            JOptionPane.showMessageDialog(panelVisor, "Se llama idRobot:"+valor_idRobot+" X:"+nueva_coordx+ "Y:"+nueva_coordy);
//            jlabelRobot.setBounds(jlabelRobot.getX()+10, jlabelRobot.getY()+10, jlabelRobot.getWidth(), jlabelRobot.getHeight());
//            jlabelRobot.setBounds(nueva_coordx, nueva_coordy, jlabelRobot.getWidth(), jlabelRobot.getHeight());
            jlabelRobot.setLocation(nueva_coordx, nueva_coordy);
//            this.notifyAll();

            //Eliminar de la visualizacion
//            jlabelRobot.setVisible(false);
//            panelVisor.remove(jlabelRobot);
            //Eliminar de la variable mapa que almacena identificadores y posiciones de los robots
//            robotslabel.remove(numeroRobot);

            //Crear una nueva label en la nueva posicion
            //crear el label y posicionarlo en el JPanel
//            JLabel label = new JLabel("");
//            String rutaIconoRobot = directorioTrabajo + "/" + rutassrc + rutapaqueteConstructorEscenariosROSACE + imageniconoRobot;
//
//            label.setIcon(new javax.swing.ImageIcon(rutaIconoRobot));
//
//            label.setText(numeroRobot);
//            label.setEnabled(true);
//            label.setVisible(true);
//
//            Dimension size = label.getPreferredSize();
//            label.setBounds(nueva_coordx, nueva_coordy, size.width, size.height);
//
//            panelVisor.add(label);
//
//            robotslabel.put(numeroRobot, label);   //Lo anoto en el Map: la clave es el numero del robot y contenido es el label creado

//            System.out.println("NUEVA Localizacion del robot " + label.getText() + "-> (" + label.getLocation().x + "," + label.getLocation().y + ")");
        } else 
            System.out.println("jlabel nulo");
        }else {
             System.out.println("Tabla de robots y victimas null ");
                }


//        System.out.println("Localizacion del robot " + jlabelRobot.getText() + "-> " + jlabelRobot.getBounds());
//        System.out.println("Localizacion del robot " + jlabelRobot.getText() + "-> " + jlabelRobot.getLocationOnScreen());
    }
 
Example 14
Project: Progetto-B   File: CardPanel.java   View Source Code Vote up 2 votes
/**
 * Changes the location of the card.
 *
 * @param x
 * @param y
 * @param card
 */
public void moveCard(int x, int y, JLabel card) {
    card.setLocation(x, y);
}