import javax.swing.*;
import javax.swing.table.*;
import java.awt.event.*;
import java.awt.*;
public class Dialogo extends JDialog implements ActionListener{
DefaultTableModel mode;
JTable tabela;
JButton botao;
Long id ;
public Dialogo(JComponent frame){
setTitle("frame");
setLayout(new FlowLayout());
mode = new DefaultTableModel(){
public Class getColumnClass(int column){
return getValueAt(0, column).getClass();
}
};
JPanel panel = new JPanel();
botao = new JButton("Trans");
panel.add(botao);
JPanel panel2 = new JPanel();
mode.addColumn("ID");
mode.addColumn("NOME");
mode.addColumn("TRANSFERENCIA");
mode.addRow(new Object[]{1,"Fulano", false});
mode.addRow(new Object[]{2, "Ciclano", false});
tabela = new JTable(mode);
panel2.add(new JScrollPane (tabela));
add(panel);
add(panel2);
botao.addActionListener(this);
setSize(200,300);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==botao){
int i=0;
while(i <=mode.getRowCount()-1){
if (mode.getValueAt(i,2)==Boolean.TRUE){
try{
id = Long.parseLong(mode.getValueAt(i, 0).toString());
///System.out.println(getId());
}catch(Exception ex){ex.printStackTrace();}
// dtm.removeRow(i);
break;
}
else { i++;}
}
//setVisible(false);
setVisible(false);
}
}
public Long getId(){
return id;
}
}
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Principal extends JFrame implements ActionListener{
JButton botao ;
JLabel teste;
public Principal(){
super("TESTE!!");
setLayout(new FlowLayout());
setDefaultCloseOperation(EXIT_ON_CLOSE);
botao = new JButton("TEste");
getContentPane().add(botao);
teste = new JLabel("Teste");
getContentPane().add(new JPanel().add(teste));
botao.addActionListener(this);
setSize(400,330);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == botao ){
Dialogo dia = new Dialogo(null);
System.out.println(dia.getId());
}
}
public static void main(String[] args){
new Principal();
}
}