annotate rep/gui/JTableTest.java @ 31:593f915dd6ff JOINandPUT

for JOIN and PUT Testing
author pin
date Sat, 10 Nov 2007 12:52:24 +0900
parents
children 8dce4348966c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31
593f915dd6ff for JOIN and PUT Testing
pin
parents:
diff changeset
1 package rep.gui; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.FocusEvent; import java.awt.event.FocusListener; import javax.swing.*; import javax.swing.event.AncestorEvent; import javax.swing.event.AncestorListener; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; class JTableTest extends JFrame implements ActionListener, FocusListener, ListSelectionListener{ /** * */ private static final long serialVersionUID = 1L; private JTable tb; JTableTest() { getContentPane().setLayout(new FlowLayout()); tb = new JTable(10, 5); tb.setValueAt("AAA", 0, 0); tb.setValueAt("BBB", 1, 1); tb.setValueAt("CCC", 2, 2); tb.addFocusListener(this); JScrollPane sp = new JScrollPane(tb); sp.setPreferredSize(new Dimension(230, 80)); getContentPane().add(sp); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setTitle("JTableTest"); setSize(250, 120); setVisible(true); } public static void main(String[] args) { new JTableTest(); } public void actionPerformed(ActionEvent event) { //if(event.getSource() == tb){ // int a = tb.getSelectedColumn(); // int b = tb.getSelectedRow(); // System.out.println("Selected item is " + a + ":" + b); //} } public void focusGained(FocusEvent event) { int column = tb.getSelectedColumn(); int row = tb.getSelectedRow(); System.out.println("Gained item is " + column + ":" + row); } public void focusLost(FocusEvent event) { } public void valueChanged(ListSelectionEvent event) { int column = tb.getSelectedColumn(); int row = tb.getSelectedRow(); Object value = tb.getValueAt(row, column); System.out.println("Gained item is " + column + ":" + row + "," + value); } }