📄 market.java
字号:
package outLook;
import outLook.*;
import source.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class market extends JFrame implements ActionListener,ItemListener
{
private JTextField priceT,ammountT;
private JButton confirmB,cancelB;
private JTextArea showInf;
private JLabel priceL,ammountL,total1L,total2L,payL;
private static double price=0,total=0,rebateRate=1,payOriginal=0,payBack=0;
private static int ammount=0,flag=0,select=0;
private JComboBox payC;
public market()
{
super("模拟收银系统");
this.setSize(270,600);
this.setLocation(450,80);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
showInf=new JTextArea("");
priceL=new JLabel("商品单价:");
ammountL=new JLabel("商品数量:");
payL=new JLabel("收款方式:");
total1L=new JLabel ("总计:");
total2L=new JLabel ("尚未统计");
priceT=new JTextField("",4);
ammountT=new JTextField("",4);
confirmB=new JButton("确 定");
cancelB=new JButton("重 置");
confirmB.addActionListener(this);
cancelB.addActionListener(this);
Object strategy[]={"正常收款","打9折收款","打8折收款","打7折收款",
"满700返300","满500返200","满300返100"};
payC=new JComboBox(strategy);
JPanel panel=new JPanel(new BorderLayout());
JPanel panel1=new JPanel(new GridLayout(5,2));
JPanel panel2=new JPanel(new GridLayout(2,2));
panel1.add(ammountL);
panel1.add(ammountT);
panel1.add(priceL);
panel1.add(priceT);
panel1.add(payL);
panel1.add(payC);
panel1.add(confirmB);
panel1.add(cancelB);
panel2.add(total1L);
panel2.add(total2L);
JScrollPane jScrollPane = new JScrollPane(showInf,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
//jScrollPane1.getViewport().add(panel, null);
panel.add(panel1,"North");
panel.add(jScrollPane,"Center");
panel.add(panel2,"South");
this.add(panel);
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==confirmB)
{
select=payC.getSelectedIndex();
try
{
price=Double.parseDouble(priceT.getText());
if(price<=0)
{
JOptionPane.showMessageDialog(null,"商品价格必须大于零","Error",JOptionPane.ERROR_MESSAGE);
return;
}
}
catch (Exception e1)
{
JOptionPane.showMessageDialog(null,"商品价格输入有误","Error",JOptionPane.ERROR_MESSAGE);
return;
}
try
{
ammount=Integer.parseInt(ammountT.getText());
//String server=JOptionPane.showInputDialog("输入服务器IP");
//JOptionPane.showConfirmDialog(null,"找到了","Warning",JOptionPane.DEFAULT_OPTION,JOptionPane.WARNING_MESSAGE,null);
if(ammount<=0)
{
JOptionPane.showMessageDialog(null,"商品数量必须大于零") ;return;
}
}
catch (Exception e1)
{
JOptionPane.showMessageDialog(null,"商品数量输入有误","Error",JOptionPane.ERROR_MESSAGE);
return;
}
showInf.append("原收:"+ammount*price+" ");
buy(select);
showInf.append(" 收费方式:"+(String)(payC.getSelectedItem())+"\n");
showInf.append("***********************************************\n");
total2L.setText(""+total);
//JOptionPane.showMessageDialog(null,null,""+total,JOptionPane.PLAIN_MESSAGE) ;
}
if(e.getSource()==cancelB)
{
priceT.setText("");
ammountT.setText("");
payC.setSelectedIndex(0);
}
}
public void itemStateChanged(ItemEvent e)
{
}
public void buy(int select)
{
switch(select)
{
case 0:;break;
case 1:rebateRate=0.9;flag=1;break;
case 2:rebateRate=0.8;flag=1;break;
case 3:rebateRate=0.7;flag=1;break;
case 4:;payOriginal=700;payBack=300;flag=2;break;
case 5:;payOriginal=500;payBack=200;flag=2;break;
case 6:;payOriginal=300;payBack=100;flag=2;break;
}
context contextIns=new context(flag,price,ammount,rebateRate,payOriginal,payBack);
String temp=contextIns.getPay();
total+=Double.parseDouble(temp);
showInf.append("实收:"+contextIns.getPay()+"\n");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -