毕业论文写作

毕业设计需求

在jsp计算毕业设计中如何使用swing编程计算两个商品总量

 标题:在jsp计算毕业设计中如何使用swing编程计算两个商品总量

价格:0元

类型:常见毕业问题

 

 

在jsp计算毕业设计中如何使用swing编程计算两个商品总量

图片
点击上方“蓝字”,关注我们.

 

  在毕业设计中如何利用swing编程来实现计算总量呢?我们的需求是:设计一个图形用户界面。界面中包括三个标签、三个文本框和一个按钮。三个标签分别是【商品1数量】、【商品2数量】、【总量】。按钮的标题为【计算总量】。要求在文本框中输入商品1数量、商品2数量,单击计算总量按钮后在文本框中显示总量。
实现代码:
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JTextField;public class SummationForm extends JFrame implements ActionListener {    private static final long serialVersionUID = -3059616600875760053L;    JLabel labMathematics, labEnglish, labTotal;    JTextField textMathematics, textEnglish, textTotal;    static JButton butSummation;    public SummationForm() {        labMathematics = new JLabel("商品数量1");        labEnglish = new JLabel("商品数量2");        labTotal = new JLabel("总量");        textMathematics = new JTextField("", 10);        textEnglish = new JTextField("", 10);        textTotal = new JTextField("", 10);        butSummation = new JButton("计算总量");        labMathematics.setBounds(30, 30, 120, 30);        textMathematics.setBounds(180, 30, 120, 30);        labEnglish.setBounds(30, 80, 120, 30);        textEnglish.setBounds(180, 80, 120, 30);        labTotal.setBounds(30, 130, 120, 30);        textTotal.setBounds(180, 130, 120, 30);        butSummation.setBounds(160, 180, 120, 30);        add(labMathematics);        add(textMathematics);        add(labEnglish);        add(textEnglish);        add(labTotal);        add(textTotal);        add(butSummation);        setLayout(null);        setBounds(200, 100, 400, 300);        // 窗口在屏幕中间显示        setLocationRelativeTo(null);        setTitle("求总量");        setResizable(false);        setVisible(true);    }    public static void main(String[] args) {        SummationForm summationForm = new SummationForm();        butSummation.addActionListener(summationForm);        summationForm.add(butSummation);    }    public void actionPerformed(ActionEvent e) {        JButton jb = (JButton) e.getSource();        if (jb == butSummation) {            String Mathematics = textMathematics.getText();            String English = textEnglish.getText();            try {                int a = Integer.parseInt(Mathematics);                int b = Integer.parseInt(English);                int t = a + b;                textTotal.setText(String.valueOf(t));            } catch (Exception e2) {                JOptionPane.showMessageDialog(this, "输入的格式错误!", "提示对话框", JOptionPane.DEFAULT_OPTION);            }        }    }}

 

效果图如下:

 

捕获10.JPG

 

 

 

————————————————

版权声明:本文为CSDN专家-sinjack的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/technologist_36/article/details/118353517?spm=1001.2014.3001.5502

 

最新毕业设计成品

版权所有© 帮我毕业网 并保留所有权利

QQ 1370405256 微信 biyebang

QQ:629001810微信:biyebang

收缩