一次测试
This commit is contained in:
@@ -12,7 +12,7 @@ public class Home extends JFrame implements ActionListener {
|
|||||||
JMenuItem StockMenuItem,InventoryMenuItem,SalesMenuItem;
|
JMenuItem StockMenuItem,InventoryMenuItem,SalesMenuItem;
|
||||||
|
|
||||||
Home() {
|
Home() {
|
||||||
super("城市进销存信息管理系统");
|
super("超市进销存信息管理系统");
|
||||||
menuBar = new JMenuBar();
|
menuBar = new JMenuBar();
|
||||||
menu = new JMenu("菜单");
|
menu = new JMenu("菜单");
|
||||||
StockMenuItem = new JMenuItem("库存信息管理");
|
StockMenuItem = new JMenuItem("库存信息管理");
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public class Main extends JFrame implements ActionListener {
|
|||||||
String sql = "select * from user where username='"+tf1.getText()+"' and password='"+tf2.getText()+"'"; ;
|
String sql = "select * from user where username='"+tf1.getText()+"' and password='"+tf2.getText()+"'"; ;
|
||||||
try {
|
try {
|
||||||
ResultSet rs = jdbc.query(sql);
|
ResultSet rs = jdbc.query(sql);
|
||||||
jdbc.close();
|
|
||||||
if(rs.next()&&tf3.getText().equals(jl5.getText())) {
|
if(rs.next()&&tf3.getText().equals(jl5.getText())) {
|
||||||
JOptionPane.showMessageDialog(null, "登录成功");
|
JOptionPane.showMessageDialog(null, "登录成功");
|
||||||
new Home();
|
new Home();
|
||||||
@@ -70,4 +70,5 @@ public class Main extends JFrame implements ActionListener {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new Main();
|
new Main();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -37,6 +37,7 @@ public class SalesProductManagement extends JFrame implements ActionListener {
|
|||||||
text10=new JTextField(5);
|
text10=new JTextField(5);
|
||||||
|
|
||||||
btn1=new JButton("结算");
|
btn1=new JButton("结算");
|
||||||
|
btn1.addActionListener(this);
|
||||||
|
|
||||||
|
|
||||||
add(panel1);
|
add(panel1);
|
||||||
@@ -70,9 +71,35 @@ public class SalesProductManagement extends JFrame implements ActionListener {
|
|||||||
setSize(500,500);
|
setSize(500,500);
|
||||||
setLocationRelativeTo(null);
|
setLocationRelativeTo(null);
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 添加窗口关闭功能
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
// 判断事件源是否为结算按钮
|
||||||
|
if (e.getSource() == btn1) {
|
||||||
|
try {
|
||||||
|
// 获取单价(从文本框提取数字部分)
|
||||||
|
double applePrice = Double.parseDouble(text2.getText().replace("元", ""));
|
||||||
|
double bananaPrice = Double.parseDouble(text5.getText().replace("元", ""));
|
||||||
|
double orangePrice = Double.parseDouble(text8.getText().replace("元", ""));
|
||||||
|
|
||||||
|
// 获取数量(处理空输入情况)
|
||||||
|
int appleCount = text3.getText().trim().isEmpty() ? 0 : Integer.parseInt(text3.getText().trim());
|
||||||
|
int bananaCount = text6.getText().trim().isEmpty() ? 0 : Integer.parseInt(text6.getText().trim());
|
||||||
|
int orangeCount = text9.getText().trim().isEmpty() ? 0 : Integer.parseInt(text9.getText().trim());
|
||||||
|
|
||||||
|
// 计算总金额
|
||||||
|
double total = (applePrice * appleCount) + (bananaPrice * bananaCount) + (orangePrice * orangeCount);
|
||||||
|
|
||||||
|
// 显示结果,保留两位小数
|
||||||
|
text10.setText(String.format("%.2f元", total));
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
// 处理输入非数字的情况
|
||||||
|
JOptionPane.showMessageDialog(this, "请输入有效的数字", "输入错误", JOptionPane.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static void main(String[] args) {
|
||||||
|
new SalesProductManagement();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user