急需一個JAVA編程
難度在計算器以上的!!!!真的很急!!!!謝謝啊……
追问:那還有其他的嗎?
難度在計算器以上的!!!!真的很急!!!!謝謝啊……
追问:那還有其他的嗎?
答案:什么意思啊?这个是我以前课程设计做的带日期计算的计算器import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.lang.*;
public class Jisuanqi extends JFrame implements ActionListener{
String s1="",s2="";
int e1=0,e2=0,e3=0,e4=0,e5=0,e6=0,day1=0;
double arg=0;
boolean isArithmetic=true; //默认为算术运算
Boolean start=true;
String op="=";
String strDate="";
JFrame f=new JFrame("多功能计算器");
JTextField display=new JTextField("0");
JLabel sta=new JLabel("算数运算");
JPanel p=new JPanel();
JPanel p1=new JPanel();
JPanel p2=new JPanel();
JButton b17=new JButton("清零");
JButton b18=new JButton("转换");
JButton b19=new JButton("取余");
JButton b[]=new JButton[16];
String s[]={"1","2","3","+","4","5","6","-","7","8","9","*",".","0","=","/"};
public void init(){
p.setLayout(new GridLayout(4,4)); //计算器键盘设置为网格布局管理器
f.setLayout(new BorderLayout());
f.add(p1,"North");
p1.setLayout(new BorderLayout());
p1.add(sta,"North");
p1.add(display,"South");
display.setEditable(false);
f.add(p,"Center");
f.add(p2,"South");
for(int i=0;i<16;i++){
b[i]=new JButton(s[i]);
p.add(b[i]);
b[i].addActionListener(this);
}
p2.add(b17);
p2.add(b18);
p2.add(b19);
b19.addActionListener(this);
b17.addActionListener(new ActionListener(){ //给清零键增加事件监听器
public void actionPerformed(ActionEvent e){
if(isArithmetic){ //如果是算术运算
display.setText("0");
sta.setText("算数运算"); //在label中显示算数运算
arg=0;
op="=";
start=true;
}
else{ //是日期计算
display.setText("");
sta.setText("日期运算"); //在label中显示日期运算
strDate="";
op="=";
start=true;
}
}
});
b18.addActionListener(new ActionListener(){ //给转换键增加事件监听器
public void actionPerformed(ActionEvent e){
isArithmetic=!isArithmetic;
if(isArithmetic){ //如果是算术运算
display.setText("0");
sta.setText("算数运算");
}
else{ //是日期计算
display.setText("");
sta.setText("日期运算");
}
arg=0;
strDate="";
op="=";
start=true;
}
});
p2.setLayout(new GridLayout(1,2));
f.setSize(300,300); //设置框架大小
f.setVisible(true); //设置为可见
}
public void actionPerformed(ActionEvent evt){
String s=evt.getActionCommand();
if(isArithmetic){ //如果是算数运算
if('0'<=s.charAt(0)&&s.charAt(0)<='9'||s.equals(".")){ //如果选择1到9数字或者小数点
if(start) display.setText(s);
else display.setText(display.getText()+s);
start=false;
}
else{
if(start){
if(s.equals("-")){ //重新开始运算时候选择-则为负号
display.setText(s);
start=false;
}
else op=s; //计算中间选择-则为运算符
}
else{
double x=Double.parseDouble(display.getText()); //X为文本框中的数字
calculate(x); //调用calculate()方法
op=s; start=true;
}
}
}
else { //如果是日期运算
if('0'<=s.charAt(0)&&s.charAt(0)<='9'||s.equals("/")){ //如果选择0到9或者/
if(start) display.setText(s);
else display.setText(display.getText()+s);
start=false;
}
else{
GongYuan n=new GongYuan();
if(s.equals("-")) {
s1=display.getText();start=true; //s1为按下减号后文本框内容
Riqi m=new Riqi();
m.fenli(s1);
e1=m.a; //第一个日期的年
e2=m.b; //第一个日期的月
e3=m.c; //第一个日期的日
day1=n.Change(e1,e2,e3); //转换为天数
}
if(s.equals("=")){
s2=display.getText(); //s2为按下等号后的文本框内容
Riqi m=new Riqi();
m.fenli(s2);
e4=m.a; //第二个日期的年
e5=m.b; //第二个日期 的月
e6=m.c; //第二个日期的日
if(e1>0&&e1<9999&&e2>0&&e2<=12&&e3>0&&e3<=31&&e4>0&&e4<9999&&e5>0&&e5<=12&&e6>0&&e6<=31)
//129行判断输入的内容格式是否正确
display.setText(day1-n.Change(e4,e5,e6)+""); //显示结果
else display.setText("输入错误");
}
&nb
上一个:武汉java培训机构哪里好?
下一个:java是什么啊?