0
Ah, so I was creating a show with Swing, heunderlined text reads the name that the user puts, and then shows it to him, very simple thing, I’m still very new, but when I created the class "Botaoaction" (which was the one that showed the user’s name) I started the code and gave the following error
Formulario.java:28: error: cannot find symbol
BotaoAction action = new BotaoAction(t);
^
code used:
package swing;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class Formulario{
public static void main(String[] args){
JFrame f = new JFrame();
f.setTitle("Janela");
f.setSize(300,200);
f.setLocation(500,300);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel p = new JPanel();
JLabel one = new JLabel("Digite seu nome:");
p.add(one);
JTextField t = new JTextField(10);
p.add(t);
JButton b = new JButton("OK");
BotaoAction action = new BotaoAction(t);
b.addActionListener(action);
p.add(b);
f.add(p);
f.setVisible(true);
}
}
code I used in the class "Botaoaction":
package swing;
public class BotaoAction implements ActionListener{
private JTextField t;
public BotaoAction(JTextField t){
this.t = t;
}
public void actionPerformed(ActionEvent e){
String nome = t.getText();
JOptionPane.showMessageDialog(null, "Foi digitedo" + nome);
}
}