Bem, criei o seguinte código :
package Interface;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class teste_Interface extends JFrame implements ActionListener
{
private static teste_Interface janela;
private JPanel pane;
private JButton botao;
public teste_Interface(String title)
{
setTitle(title);
}
public void MontaJanela(int width, int height, int x, int y)
{
pane = new JPanel();
botao = new JButton("Click me... if you can!");
botao.setLocation(new Point(80, 300));
botao.addActionListener
(
new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
MsgBox("Bem feito feito");
}
}
);
pane.add(botao);
add(pane);
setSize(width, height);
setLocation(x, y);
setVisible(true);
}
public void MsgBox(String text)
{
JOptionPane.showMessageDialog(this, text, "Alerta",
JOptionPane.INFORMATION_MESSAGE);
}
public static void main(String arg[])
{
janela = new teste_Interface("My window");
janela.MontaJanela(480, 640, 40, 40);
janela.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
@Override
public void actionPerformed(ActionEvent e)
{
}
}
o que eu quero fazer é colocar o botão em um outro local da tela, mas eu não consigo fazer isso utilizando o método setLocation, consegui fazer isso apenas quando coloquei ele dentro do ActionListener, mas ae só quando o suário clicar nele… queria saber como faço isso antes da janela aparecer?
se alguém pudesse me ajudar eu agradeceria…