用java语言设计一个形如windows操作系统附件中的计算器界面(程序代码)
2个回答
展开全部
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());}
}
}
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());}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询