Pessoal estou fazendo um exercicio da faculdade, que ao clicar em um botão a uma imagem irá rolar na tela (cair de cima para baixo), até tocar a borda de baixo… No entando, preciso atrivuir valor a uma variavel inteira, para que ela vá se incrementanto e entre num loop para ir modificando a posição da figura. Olhem para mim o código abaixo e tentem identificar o erro para mim por favor:
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
/**
* @author volnei
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class Teste extends JFrame {
public int linha = 75;
public int coluna = 95;
private javax.swing.JPanel jContentPane = null;
private javax.swing.JButton jButton = null;
private javax.swing.JLabel jLabel = null;
public static void main(String[] args) {
new Teste();
}
/**
* This is the default constructor
*/
public Teste() {
super();
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize() {
this.setSize(300, 200);
this.setContentPane(getJContentPane());
this.setVisible(true);
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private javax.swing.JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new javax.swing.JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJButton(), null);
jContentPane.add(getJLabel(), null);
}
return jContentPane;
}
/**
* This method initializes jButton
*
* @return javax.swing.JButton
*/
private javax.swing.JButton getJButton() {
if(jButton == null) {
jButton = new javax.swing.JButton();
jButton.setBounds(86, 17, 121, 35);
jButton.setText("Mostrar");
jButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
JLabel label = getJLabel();
label.setIcon(new ImageIcon("c:\\imagem.gif"));
}
});
}
return jButton;
}
private javax.swing.JLabel getJLabel() {
while (linha < 200) {
if(jLabel == null) {
jLabel = new javax.swing.JLabel();
jLabel.setBounds(coluna, linha, 108, 32);
jLabel.setText("");
}
return jLabel;
int linha = (linha.value) + 1 ; //Esssa atribuição está dando erro ao compilar.
}
}
public void setJLabel(javax.swing.JLabel label) {
jLabel = label;
}
}
Já aproveitando a pergunta, num sei se esse tipo de código está certo, pois preciso de fazer um jogo de Tetris onde as peças vai caindo, mas o código acima é só o protótipo, então gostaria de saber se alguém saberia me responder como controlar o tempo para que aconteça o loop para atualização das peças e como se faz para que ao exibir a peça em uma nova posição a exibida anteriormente seja apagada…
Obrigado.