Ciao a tutti ragazzi, avrei bisogno di aiuto con un programma!
Questo programma dovrebbe far inserire la password nella textfield e alla pressione del tasto ok, confrontarla con quella presente in un file di testo. Se la password corrisponde, visualizzare accesso confermato, altrimenti no.. Il problema è che non so come far passare all'ascoltatore nella classe ActionListener la stringa della textfield per poi confrontarla con quella del file..
Questo è il main:
codice:package grafica1; import java.awt.Button; import java.awt.Container; import java.awt.GridLayout; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPasswordField; import javax.swing.JTextField; public class Grafica1 { public static void main(String[] args) throws FileNotFoundException, IOException { String t; JFrame frame = new JFrame ("Prima interfaccia"); frame.setSize(180,200); FileReader f1 = new FileReader ("prova.txt"); BufferedReader br1 = new BufferedReader(f1); t=br1.readLine(); Container c1 = frame.getContentPane(); c1.add(new JLabel("Nome:")); JTextField t1 = new JTextField(); JLabel l1 = new JLabel ("Cognome:"); JTextField t2 = new JTextField(); JLabel l2 = new JLabel ("Password:"); JPasswordField p1 = new JPasswordField (); Button b1 = new Button ("OK"); Button b2 = new Button ("Annulla"); frame.add(t1); frame.add(l1); frame.add(t2); frame.add(l2); frame.add(p1); frame.add(b1); frame.add(b2); frame.setLayout(new GridLayout(4,2,20,20)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }
La classe con l'ascoltatore non saprei come fare.. mi dareste una mano? Grazie

Rispondi quotando

