java编程产检类型题 --- 程序界面[库存查询]

网友投稿 263 2022-11-29

java编程产检类型题 --- 程序界面[库存查询]

程序界面 — 库存查询

import javax.swing.*;import java.awt.*;import java.awt.event.ActionListener;public class Exam5 { public void createAndShow(){ JFrame frame = new JFrame("库存查询窗口"); // 创建顶层容器(窗口) frame.setSize(400,300); // 设置容器大小 frame.setLocation(300,200); // 设置容器初始位置 frame.setVisible(true); // 设置容器可见 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 设置容器关闭方式 JPanel jPanel = new JPanel(); // 添加中间容器 JComboBox jComboBox = new JComboBox<>(); // 添加下拉列表组件 jComboBox.addItem("请选择商品"); // 添加下拉列表元素 jComboBox.addItem("色拉油"); jComboBox.addItem("齐心汽水"); jComboBox.addItem("米酒"); jComboBox.addItem("冰淇淋"); jComboBox.addItem("蛋糕"); JTextField jTextField1 = new JTextField(5); // 添加文本组件 JLabel jLabel1 = new JLabel("单价"); // 添加标签组件 JTextField jTextField2 = new JTextField(5); JLabel jLabel2 = new JLabel("库存"); jComboBox.addActionListener(e->{ // 配置下拉列表动作监听 String goods = (String) jComboBox.getSelectedItem(); // 返回当前所选项并转化为字符串的形式 if ("色拉油".equals(goods)){ jTextField1.setText("56"); jTextField2.setText("232"); }else if ("齐心汽水".equals(goods)){ jTextField1.setText("8"); jTextField2.setText("50"); }else if ("米酒".equals(goods)){ jTextField1.setText("10"); jTextField2.setText("109"); }else if ("冰淇淋".equals(goods)){ jTextField1.setText("20"); jTextField2.setText("48"); }else { jTextField1.setText("90"); jTextField2.setText("30"); } }); jPanel.add(jComboBox); // 组件的层层嵌套 jPanel.add(jLabel1); jPanel.add(jTextField1); jPanel.add(jLabel2); jPanel.add(jTextField2); frame.add(jPanel, BorderLayout.PAGE_START); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { // 启动一个线程去运行 @Override public void run() { Exam5 e = new Exam5(); e.createAndShow(); } }); }}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:SpringMVC中如何获取@PathVariable的值
下一篇:【Python数据分析与处理 实训04】--- 探索1960 - 2014美国犯罪数据(时间序列处理应用)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~