Olá, galera, tudo bem?
Sou iniciante em java, mas consegui criar uma lógica que utilizo aqui no trampo, mas gostaria de deixar ela mais sofisticada colocando-a uma interface gráfica. Então andei pesquisando pela net e achei o “Windows Builder” instalei esse pacote com a interface gráfica e até montei a tela visual, mas não sei o que acontece quando clico no “play” lá em cima ele não inicia e guando vou no modo “design” e clico no play ele funciona mais os botões que criei não faz nada quando clico uma que já implementei o “Action Listener” coloquei o evento no botão, mais nada acontece. vou jogar o código aqui em baixa para você verem.
Detalhe não programei nada ainda somente queria fazer funcionar para q eu possa programar a lógica que fiz.
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.JButton;
public class NumerosNovos2 extends JPanel implements ActionListener {
private JTextField txtTotal;
private JTextField textField_1;
private JTextField textField_2;
private JTextField textField_3;
private JTextField textField_4;
JTextPane textPane;
JButton btnSalvar;
JButton btnGerar;
/**
* Create the panel.
*/
public NumerosNovos2() {
JLabel lblNewLabel = new JLabel("N\u00FAmero 01");
JLabel lblTotal = new JLabel("Total");
txtTotal = new JTextField();
txtTotal.setColumns(10);
JLabel lblContatos = new JLabel("Contatos");
textField_1 = new JTextField();
textField_1.setColumns(10);
JLabel lblNmero = new JLabel("N\u00FAmero 02");
JLabel lblInicial = new JLabel("Inicial");
textField_2 = new JTextField();
textField_2.setColumns(10);
JLabel lblFinal = new JLabel("Final");
textField_3 = new JTextField();
textField_3.setColumns(10);
JLabel lblContatos_1 = new JLabel("Contatos");
textField_4 = new JTextField();
textField_4.setColumns(10);
textPane = new JTextPane();
JButton btnSalvar = new JButton("SALVAR");
JButton btnGerar = new JButton("GERAR");
GroupLayout groupLayout = new GroupLayout(this);
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addContainerGap()
.addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
.addComponent(lblNewLabel)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(lblTotal)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(txtTotal, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addGap(18)
.addComponent(lblContatos)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(textField_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addComponent(lblNmero)
.addComponent(textPane, GroupLayout.PREFERRED_SIZE, 428, GroupLayout.PREFERRED_SIZE)
.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
.addGroup(groupLayout.createSequentialGroup()
.addComponent(btnGerar)
.addGap(18)
.addComponent(btnSalvar))
.addGroup(groupLayout.createSequentialGroup()
.addComponent(lblInicial)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(textField_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(lblFinal)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(textField_3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(lblContatos_1)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(textField_4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
.addContainerGap(12, Short.MAX_VALUE))
);
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addContainerGap()
.addComponent(lblNewLabel)
.addPreferredGap(ComponentPlacement.UNRELATED)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(lblTotal)
.addComponent(txtTotal, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(lblContatos)
.addComponent(textField_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(18)
.addComponent(lblNmero)
.addGap(18)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(lblInicial)
.addComponent(textField_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(lblFinal)
.addComponent(textField_3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(lblContatos_1)
.addComponent(textField_4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(ComponentPlacement.RELATED, 28, Short.MAX_VALUE)
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(btnSalvar)
.addComponent(btnGerar))
.addPreferredGap(ComponentPlacement.UNRELATED)
.addComponent(textPane, GroupLayout.PREFERRED_SIZE, 216, GroupLayout.PREFERRED_SIZE)
.addGap(22))
);
setLayout(groupLayout);
btnSalvar.addActionListener(this);
btnGerar.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent evento) {
if (evento.getSource() == btnSalvar) {
JOptionPane.showMessageDialog(null, "teste salvar");
System.out.println("Salvar");
} else if (evento.getSource() == btnGerar) {
JOptionPane.showMessageDialog(null, "teste gerar");
String t = (String)txtTotal.getText();
textPane.setText(t);
}
}
public static void main(String[] args) {
NumerosNovos2 c = new NumerosNovos2();
c.setVisible(true);
}
}