1
The code below I got from the Internet is working for me.
In the main
, it executes a form with the name to type and the button ok
.
I wanted to run, no main
, shortly after the
new MeuPrograma();
one System.out.println("##")
where it displayed the name that the guy typed there in the field of swing
How do I do that?
public class MeuPrograma extends JFrame {
public static JTextField text = new JTextField(10);
private static final long serialVersionUID = 1L;
private JLabel labelNome;
private JTextField textFieldNome;
private JButton buttonOk;
public MeuPrograma() {
setTitle("Programa Swing1");
setLayout(new FlowLayout());
labelNome = new JLabel("Nome: ");
textFieldNome = new JTextField(15);
buttonOk = new JButton("OK");
// --> adiciona os componentes a janela
add(labelNome);
add(textFieldNome);
add(buttonOk);
// --> ajusta o tamanho, a posicao e a acao ao fechar
pack();
setLocationRelativeTo(null);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
// --> mostra a janela
setVisible(true);
}
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
// --> cria um novo objeto do tipo Swing1
// por causa da execucao multithreading da
// API swing,isso deve ser feito dessa forma:
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new MeuPrograma();
}
});
i want to display the system.out.println after q the guy click ok
– Adriano
If it is desktop, System.out.println will not display anything, because it only displays on the console, unless the user starts the application via command line. Explain better where you want to show off and why.
– user28595
I actually have a code that generates a pdf using itext, I want to take this typed value and play inside a variable.. so I want to know how to get the value that was typed when the guy click ok
– Adriano