Salve a tutti, il mio problema riguarda il recupero dei valori da JTextFiel e JPasswordField.
Al click sul mio JButton un evento mi richiama la classe Click dove per testare il tutto stampo su console i valori dei 2 campi...ovviamente senza risultati sperati!
codice:package com.lorenzo.programmi.mailGrafica; import java.awt.Color; import java.awt.Dimension; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import javax.swing.ImageIcon; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JPasswordField; import javax.swing.JTextField; import com.lorenzo.programmi.mail.Click; public class Index extends JFrame { private static final long serialVersionUID = 1L; public static final int LARGHEZZA = 300; public static final int ALTEZZA = 500; private JLabel userTxt; private JLabel passTxt; private JLabel lblImmagine; private JTextField userInp; private JPasswordField passInp; private JPanel panel; private JCheckBox check; public Index() { java.awt.Container c = getContentPane(); c.setLayout(new GridBagLayout()); GridBagConstraints cs = new GridBagConstraints(); panel = new JPanel(new GridBagLayout()); GridBagConstraints cst = new GridBagConstraints(); String user = "<html><i style=\"font-size: 10px;\">Username:[/i] </html>"; userTxt = new JLabel(user); cst.anchor = GridBagConstraints.WEST; cst.gridx = 0; cst.gridy = 0; cst.ipadx = 5; cst.ipady = 5; panel.add(userTxt, cst); cst.gridx = 0; cst.gridy = 1; userInp = new JTextField(); userInp.setColumns(15); panel.add(userInp, cst); String pass = "<html><i style=\"font-size: 10px;\">Password:[/i] </html>"; passTxt = new JLabel(pass); cst.gridx = 0; cst.gridy = 2; cst.insets = new Insets(10, 0, 0, 0); panel.add(passTxt, cst); cst.gridx = 0; cst.gridy = 2 * 2; cst.insets = new Insets(0, 0, 0, 0); passInp = new JPasswordField(); passInp.setColumns(15); panel.add(passInp, cst); cst.gridx = 0; cst.gridy = 5; cst.ipadx = 10; cst.ipady = 30; String ricordami = "<html><i style=\"font-size: 8px;color: gray;\">Ricordami[/i]</html>"; check = new JCheckBox(ricordami); check.setMnemonic(KeyEvent.VK_G); check.setSelected(true); check.setBackground(Color.white); panel.add(check, cst); JButton button = new JButton("Login"); button.setLayout(null); button.setPreferredSize(new Dimension(80, 20)); cst.anchor = GridBagConstraints.EAST; cst.gridx = 0; cst.gridy = 6; cst.ipadx = 0; cst.ipady = 0; ActionListener l = new Click(userInp.getText(), passInp.getPassword()); button.addActionListener(l); panel.add(button, cst); panel.setBounds(0, 100, 300, 400); panel.setBackground(Color.white); lblImmagine = new JLabel(new ImageIcon("images/gmail.png")); lblImmagine.setBounds(0, 0, 300, 100); cs.anchor = GridBagConstraints.CENTER; cs.insets = new Insets(0, 0, 0, 20); cs.gridx = 0; cs.gridy = 0; c.add(lblImmagine, cs); cs.gridx = 0; cs.gridy = 1; cs.insets = new Insets(30, 0, 100, 50); c.add(panel, cs); c.setBackground(Color.white); setTitle("GMail Login"); setResizable(false); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(LARGHEZZA, ALTEZZA); setVisible(true); } }

Rispondi quotando

