urgent:display result from JTable

need help making the following in my code work:

1.how do i display the whole table in my code using a dialog box or JOptionPane.

2. i want to display a message beneath the table show the total price of items selected from the JComboBox .

3.is there any way i could add a method or sommething that display detail of each item seleted from the list in a seperate column of the JTable in my code.say for instance,if i selects beans,1 cup, 100 and it display protein in a seperate column in the JTable.

Thanks in advance.

my code:

'\n'

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.border.*;

import javax.swing.table.*;

import java.util.*;

publicclass BreakFastextends JFrameimplements ActionListener{

private JList ingredient;

private JTable table;

private DefaultTableModel model;

private JButton move;

private String[] food;

private JComboBox box,box1;

private String[] units;

privatedouble[] price={100,150,200,250,300,350,400};

private JButton finish;

public BreakFast(){

Container c=getContentPane();

c.setLayout(new FlowLayout());

food =new String[]{"Corn Flakes","Beans","Shredded Bread","Mushroom",

"eggs","Milks","Butter","Sugar","water","Oil"};

ingredient =new JList(food);

ingredient.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

ingredient.setVisibleRowCount(4);

JPanel p =new JPanel();

p.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));

move =new JButton(">>>");

move.addActionListener(this);

//meal = new JTextArea(5,20);

//meal.setEditable(false);

p.add(new JScrollPane(ingredient),"Wast");

JPanel p2 =new JPanel();

p2.setBorder(new BevelBorder(BevelBorder.RAISED));

units =new String[]{"2 cups","3 cups","4 cups","5 cups","1 mudu","2 mudu",

"3 mudu","4 mudu","5 mudu","6 mudu","7 mudu","8 mudu","9 mudu",

"1 bag"};

box =new JComboBox(units);

box.addActionListener(this);

box1 =new JComboBox();

//box1.setEditable(true);

box1.addActionListener(this);

for(int i=0;i<price.length;i++){

box1.addItem(price[i]);

}

model =new DefaultTableModel();

//model.addColumn("No.");

model.addColumn("Food Items");

model.addColumn("Units");

model.addColumn("Price");

table =new JTable(model);

JScrollPane pane =new JScrollPane(table);

pane.setPreferredSize(new Dimension(350,100));

finish =new JButton("Finish");

finish.addActionListener(this);

p.add(box,"West");

p.add(box1,"Center");

p.add(move,"East");

p2.add(pane,"North");

p2.add(finish,"South");

c.add(p);

c.add(p2);

setSize(450,300);

setVisible(true);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

publicvoid actionPerformed(ActionEvent e){

Object[] value = ingredient.getSelectedValues();

if(e.getSource() == move){

for(int i=0;i >< value.length;i++){

String word = (String)value[i];

Vector<Object> data =new Vector<Object>();

data.addElement( word );

data.addElement( box.getSelectedItem() );

data.addElement( box1.getSelectedItem());

model.addRow( data );

}

}

if(e.getSource() == finish){

JOptionPane.showMessageDialog(BreakFast.this,table,"Selection Summary",JOptionPane.PLAIN_MESSAGE);

System.exit(0);

}

}

publicstaticvoid main(String[] arg){

new BreakFast();

}

}

[7157 byte] By [kc81a] at [2007-11-26 14:26:11]
# 1
Multi-Post: http://forum.java.sun.com/thread.jspa?messageID=9429032Ignored.
es5f2000a at 2007-7-8 2:19:19 > top of Java-index,Desktop,Core GUI APIs...