用java语言设计一个形如windows操作系统附件中的计算器界面(程序代码)

大哥们,打扰一下,用java语言设计一个形如windows操作系统附件中的计算器界面(程序代码)
最新回答
诗露砉雨

2024-09-25 00:22:45

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.math.*;
public class zuoye10_3{
public static void main(String args[]){
MathWindow win=new MathWindow();
}
}
class MathWindow extends JFrame implements ActionListener{
JButton button1,button2,button3,button4;
JTextField text1,text2,text3;
MathWindow(){
text1=new JTextField(10);
text2=new JTextField(10);
text3=new JTextField(10);
button1=new JButton("加");
button2=new JButton("减");
button3=new JButton("乘");
button4=new JButton("除");
setLayout(new FlowLayout());
add(text1);
add(text2);
add(text3);
add(button1);
add(button2);
add(button3);
add(button4);
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
button4.addActionListener(this);
setBounds(200,200,260,190);
setVisible(true);
validate();
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}

public void actionPerformed(ActionEvent e){
if(e.getSource()==button1){
String s1=text1.getText();
String s2=text2.getText();
BigInteger n;
BigInteger n1=new BigInteger(s1);
BigInteger n2=new BigInteger(s2);
n=n1.add(n2);
text3.setText(n.toString());}

else if(e.getSource()==button2){
String s1=text1.getText();
String s2=text2.getText();
BigInteger n;
BigInteger n1=new BigInteger(s1);
BigInteger n2=new BigInteger(s2);
n=n1.subtract(n2);
text3.setText(n.toString());}

else if(e.getSource()==button3){
String s1=text1.getText();
String s2=text2.getText();
BigInteger n;
BigInteger n1=new BigInteger(s1);
BigInteger n2=new BigInteger(s2);
n=n1.multiply(n2);
text3.setText(n.toString());}

else if(e.getSource()==button4){
String s1=text1.getText();
String s2=text2.getText();
BigInteger n;
BigInteger n1=new BigInteger(s1);
BigInteger n2=new BigInteger(s2);
n=n1.divide(n2);
text3.setText(n.toString());}

}
}
↘琪子

2024-09-25 00:30:44

兄弟,莫名奇妙和人要个代码还不给分,木有人给的