Ho copiincollato pari pari il tuo codice in un programma scritto 100% col blocco note...
Ora, a te capire perchè quello scritto 75% ide non funziona, quello scritto 100% uomo non ha problemi.codice:import java.awt.*; import javax.swing.*; import java.awt.event.*; public class SpostaLabel extends JFrame implements MouseListener { private JLabel jLabel1; private JLabel jLabel5; public SpostaLabel() { Container c = getContentPane(); c.setLayout( null ); jLabel1 = new JLabel("Label 1"); jLabel1.setBounds(10, 10, 130, 18); jLabel1.addMouseListener( this ); jLabel5 = new JLabel("5"); jLabel5.setBounds(10, 100, 130, 18); c.add( jLabel1 ); c.add( jLabel5 ); setTitle("Sposta Label"); setSize(800, 600); setDefaultCloseOperation( EXIT_ON_CLOSE ); setVisible( true ); } public void mouseExited(MouseEvent me) { } public void mouseClicked(MouseEvent me) { } public void mousePressed(MouseEvent me) { } public void mouseReleased(MouseEvent me) { } public void mouseEntered(MouseEvent evt) { int randomx, randomy, randomex, prex, prey; prey = jLabel1.getY(); prex = jLabel1.getX(); do randomx = (int)(Math.random() * 1000); while (randomx >= 350); do randomy = (int)(Math.random() * 1000); while (randomy >= 350); if ((randomy >= 500) && (randomx >= 500)) { randomy = 100;randomx = 150; } jLabel1.setBounds(randomx, randomy, 130, 18); jLabel5.setText(String.valueOf(Integer.parseInt(jLabel5.getText())+1)); randomx = randomy = 401; } public static void main(String[] args) { SpostaLabel sl = new SpostaLabel(); } }
Ciao.![]()



Rispondi quotando