If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > JAVA > How can I pass the table value by actionPerformed

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-03-11, 07:32
dba.zhif dba.zhif is offline
Registered User
 
Join Date: Aug 2010
Posts: 7
How can I pass the table value by actionPerformed

Hi all

The below code is failed.
The problem is happened on the table value failed to be passed by actionPerformed.

If anyone can check for me??

Thanks,
zhif

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;


public class Test implements ActionListener {
JTable output;
DefaultTableModel model;
JScrollPane scrollPane;
JButton showButton;

String[] columnNames = {"NAME", "AGE"};
Object[][] data = {{"Nancy","8"},{"PAUL","10"}, {"Jack","5"}};


public Container createContentPane() {


//Create Button
showButton = new JButton("Show All Information");
showButton.setActionCommand("Show All Information");
showButton.addActionListener(this);


//Create funcPane
JPanel funcPane = new JPanel();
funcPane.add(showButton, BorderLayout.PAGE_END);

//Create the content-pane-to-be.
JPanel contentPane = new JPanel(new BorderLayout());
contentPane.setOpaque(true);

//Create a scrolled table.
model = new DefaultTableModel();
output = new JTable(model);
scrollPane = new JScrollPane(output);

//Add the text area to the content pane.
contentPane.add(funcPane, BorderLayout.CENTER);
contentPane.add(scrollPane, BorderLayout.PAGE_END);

return contentPane;
}


private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("Data Dictionary Maintainance");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);

//Create and set up the content pane.
Test t = new Test();
frame.setContentPane(t.createContentPane());

//Display the window.
frame.setSize(1200, 750);
frame.setVisible(true);
}

public void actionPerformed(ActionEvent e) {

String source = e.getActionCommand();

if(source == "Show All Information"){
model = new DefaultTableModel(data, columnNames);
}//End of "Show All Information"

}

public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On