package org.jljc.frame;
class MyReader implements ActionListener{ //监听 a等于字符串aaa
private GsgL container;
public MyReader(GsgL container){
this.container=container;}
public void actionPerformed(ActionEvent e)
{ String a="aaa";}
}
public class GsgL extends JFrame{
private MyReader myReader;
public GsgL(String title) {
super(title);
init();}
public void init(){
table=new JTable(13,2);
table.setValueAt("检测时间",0,0);
//如何把监听得到的a="aaa"值赋到table表格的
table.setValueAt(a,0,1);}
}
class MyReader implements ActionListener{ //监听 a等于字符串aaa
private GsgL container;
public MyReader(GsgL container){
this.container=container;}
public void actionPerformed(ActionEvent e)
{ String a="aaa";}
}
public class GsgL extends JFrame{
private MyReader myReader;
public GsgL(String title) {
super(title);
init();}
public void init(){
table=new JTable(13,2);
table.setValueAt("检测时间",0,0);
//如何把监听得到的a="aaa"值赋到table表格的
table.setValueAt(a,0,1);}
}
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;class MyReader implements ActionListener { // 监听 a等于字符串aaa
private GsgL frame; public MyReader(GsgL frame) {
this.frame = frame;
} public void actionPerformed(ActionEvent e) {
String a = "aaa";
frame.fireTableChanged(a);
}
}public class GsgL extends JFrame {
private MyReader myReader;
private JButton button;
private JTable table; public GsgL(String title) {
super(title);
init();
} public void init() {
table = new JTable(13, 2);
((DefaultTableModel) table.getModel())
.setColumnIdentifiers(new String[] { "1", "2" });
getContentPane().add(new JScrollPane(table)); button = new JButton("Test");
myReader = new MyReader(this);
button.addActionListener(myReader);
getContentPane().add(button, BorderLayout.SOUTH);
} public void fireTableChanged(String cont) {
table.setValueAt("检测时间", 0, 0);
table.setValueAt(cont, 0, 1);
((DefaultTableModel) table.getModel()).fireTableRowsUpdated(0, 0);
} public static void main(String[] args) {
GsgL frame = new GsgL("Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 150);
frame.setVisible(true);
}
}