Ecco il codice che ho scritto per quella funzione:
codice:import java.awt.Point; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import javax.swing.JTable; public class DoubleClickListener extends MouseAdapter{ private JTable t; private PanelAppFiltro paf; private MyMenuFrame padre; private Archivio arc; int idcliente; private int clickRow = 1 ; //Questo campo contiene l'indice della riga su cui si //deve fare doppio click per aprire la finestra; //puoi anche passarlo nel costruttore o gestirlo in altro modo private ClienteAcquirente cliente; public DoubleClickListener(MyMenuFrame mf, Archivio arc, JTable t){ this.arc = arc; this.padre = mf; this.t = t; //int idcliente; } public void mouseClicked(MouseEvent e){ //A noi interessa solo l'evento di click //arc.getNumContact(); if(e.getClickCount() < 2) //se non è doppio click ritorno return; if(e.getButton() != MouseEvent.BUTTON1)//Considero solo i click del pulsante sinistro; return; //se vuoi gestire l'evento anche se si fa dopppio //click col tasto destro commenta questo if int x = Integer.parseInt ((String)t.getValueAt(t.getSelectedRow(), 2)); System.out.println(x); try { String str; // array che mi da il nome(prima stringa), // cognome(seconda stringa) ecc.. BufferedReader in = new BufferedReader(new FileReader( "ARCHIVIO.txt")); // "ARCHIVIO.txt")); int idcliente=1; int cicliWhile = 0; while ((str = in.readLine()) != null) { cicliWhile++; if(cicliWhile == x){ String[] strcliente; strcliente = str.split("#"); ClienteAcquirente cliente = new ClienteAcquirente( strcliente[0], strcliente[1], idcliente, strcliente[3], strcliente[4], strcliente[5],strcliente[6], strcliente[7],Double.parseDouble(strcliente[8]), strcliente[9], strcliente[10], strcliente[11]); arc.add(cliente); System.out.print(str); break; } } in.close(); } catch (IOException ev) { } this.padre.pannelloVisibile.setVisible(false); this.padre.pannelloVisibile = new PanelAppFiltro(arc, this.padre/*clickedRow+1*/); //System.out.println("asd "+this.padre.getNumContact(idcliente)); this.padre.getContentPane().add(this.padre.pannelloVisibile); this.padre.pannelloVisibile.setVisible(true); System.out.println("buonasera"); JTable t = (JTable)e.getSource(); //Ricavo la tabella che ha prodotto l'evento int clickedRow = t.rowAtPoint(e.getPoint()); //Calcolo la riga su cui si è fatto click if(clickedRow != clickRow) //Se non è la riga che mi interessa ritorno return; //Potrei costruire la nuova finestra tipo popup??? } private int rowAtPoint(Point point) { return idcliente; } }

Rispondi quotando
