package点餐;importjava.awt.BorderLayout;importjava.awt.Toolkit.*;importjava.awt.event.*;importjavax.swing.*;publicclassorderformextendslogoimplementsActionListener{JPanel...
package 点餐;
import java.awt.BorderLayout;
import java.awt.Toolkit.*;
import java.awt.event.*;
import javax.swing.*;
public class orderform extends logo implements ActionListener
{
JPanel m1,m2;
JScrollPane scroll;
private String[] columnL ={"菜号","菜名","单价","数量","总计"};
private String[][] rowData = {{"1","套餐一","5", "0","0"},
{"2","套餐二","4.5", "0","0"},
{"3","套餐三","7", "0","0"},
{"4","套餐四","9", "0","0"},
{"5","套餐五","10", "0","0"}};
private JTable jTable;
private JButton submit = new JButton("提交");
private JButton cencal = new JButton("取消");
@SuppressWarnings("empty-statement")
public orderform()
{
this.setTitle("理工城院电子点餐系统 V1.0");//题目
m1 = new JPanel();
m2 = new JPanel();
jTable = new JTable(rowData,columnL);
submit.addActionListener(this);
cencal.addActionListener(this);
//jTable.enable(false);
scroll = new JScrollPane();
scroll.add(jTable);
//scroll.setVisible(true);
// m1.setVisible(true);
// m1.setSize(900,400);
m2.add(submit);
m2.add(cencal);
//m2.setSize(900,50);
this.setLayout(new BorderLayout());
add(BorderLayout.NORTH,scroll);
add(BorderLayout.SOUTH,m2);
this.add(m1);
this.setLocation(250, 140); //设置窗口的起始位置
this.setSize(900, 450);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if( e.getSource() == submit)
{
Double sumtemp = 0.0;
for( int i = 0; i < 5; i++)
{
rowData[i][3] = jTable.getValueAt(i, 3).toString();
Double temp1 = Double.parseDouble(rowData[i][3]);
Double temp2 = Double.parseDouble(rowData[i][2]);
temp1 = temp1*temp2;
sumtemp += temp1;
rowData[i][4] = temp1.toString();/**/
//rowData[i][4]= jTable.getValueAt(i, 3).toString();
}
jTable.updateUI();
JOptionPane.showMessageDialog(this,
sumtemp.toString()+"元", "总计",
JOptionPane.INFORMATION_MESSAGE);
}
else if( e.getSource() == cencal )
{
new menu_next();
setVisible(false);
}
}
public static void main(String[] args)
{
orderform a = new orderform();
a.setVisible(true);
}
}
展开