Bom dia !
Pessoal, sou novo em java estou aprendendo na faculdade, estou com um problema que está me quebrando a cabeça.
Fiz um míni programa onde contém um JFtextFIeld que é para o usuário digitar um número e um botão ok pra quando o usuário clicar ele chamar a função do fatorial e mostrar o resultado no segundo JTextField só que não consigo fazer a chamada da função e nem para o segundo JtextField receber o resultado, gostaria de uma ajuda e também da opinião sobre o código fonte.
obrigado desde de já
import javax.swing.;
import java.awt.;
import java.awt.event.;
import java.text.;
import java.lang.*;
public class NovoAction extends JPanel {
private JLabel lblNome;
private JTextField txtNome;
private JButton ok;
private JButton fechar;
private JTextField result;
private JLabel lblResul;
private int numero;
public NovoAction(){
lblNome =new JLabel("DIGITE UM NÚMERO");
txtNome=new JTextField("",16);
ok=new JButton("OK");
fechar=new JButton("Fechar");
result=new JTextField("",15);
lblResul=new JLabel("FATORIAL DESTE NÚMERO É");
}
public void init(){
setLayout(new GridLayout(4,5));
FlowLayout centro=new FlowLayout(FlowLayout.CENTER);
ButtonHandler buttonHandler=new ButtonHandler();
ok.addActionListener(buttonHandler);
fechar.addActionListener(buttonHandler);
txtNome.addActionListener(new ButtonHandler());
txtNome.setToolTipText("NO MÁXIMO 8 CARACTERES");
JPanel auxText =new JPanel(centro);
auxText.add(lblNome);
auxText.add(txtNome);
JPanel auxBut = new JPanel(centro);
auxBut.add(ok);
auxBut.add(fechar);
JPanel auxResul =new JPanel(centro);
auxResul.add(lblResul);
auxResul.add(result);
add(auxText);
add(auxBut);
add(auxResul);
}
class ButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent ae){
if(ae.getSource() == ok){
JOptionPane.showMessageDialog(null,"O TEXT DIGITADO FOI==> "+""+txtNome.getText());
}
}
public void actionPeformed(ActionEvent ea){
if(ea.getSource()==txtNome){
String texto=txtNome.getText();
if(texto.length()>8){
texto=texto.substring(0,7);
txtNome.setText(texto);
}
}
}
}
public int Fatorial(){
String x=txtNome.getText();
int aux=Integer.parseInt(x);
int fat=1;
int cont=1;
while(cont>=aux){
fat=fat*cont;
cont=cont+1;
}
return fat;
}
public static void main(String[] args){
NovoAction Novoaction = new NovoAction();
Novoaction.init();
JFrame frame= new JFrame("ANALISANDO FATORIAL");
frame.getContentPane().add(Novoaction);
frame.pack();
frame.setVisible(true);
}
}