帮我修改一下我的java编程,急用!!

2025-06-28 12:33:56
推荐回答(1个)
回答1:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Computer extends JFrame{
JTextField imputyear=new JTextField(5);
JTextField imputmount=new JTextField(5);
JTextField imputday=new JTextField(5);
JTextField nowtime=new JTextField(10);
JButton computer=new JButton("计算");
ComputerListener listener=new ComputerListener();
Computer(){
setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setLayout(new FlowLayout());
add(new JLabel("年"));
add(imputyear);
add(new JLabel("月"));
add(imputmount);
add(new JLabel("日"));
add(imputday);
add(computer);
add(new JLabel("第多少天"));
add(nowtime);
computer.addActionListener(listener);
}
/*class OperationListenerimplements ItemListener{
public void itemstaticchanged(ItemEvent e){
computer=computer.getcomputer().toString();
}
}
computer.addItemListener(new Operationlistener());*/
public class ComputerListener implements ActionListener{
public void actionPerformed(ActionEvent e){
try{
int year=Integer.parseInt(imputyear.getText().trim());
int mount=Integer.parseInt(imputmount.getText().trim());
int day=Integer.parseInt(imputday.getText().trim());
String s1=year+"年"+mount+"月"+day+"日";
int time=20;
switch(mount-1)
{
case 11:
time+=30;
case 10:
time+=31;
case 9:
time+=30;
case 8:
time+=31;
case 7:
time+=31;
case 6:
time+=30;
case 5:
time+=31;
case 4:
time+=30;
case 3:
time+=31;
case 2:
{
if((year%4==0&&year%100!=0)||year%400==0)
time+=29;
else
time+=28;
}
case 1:
time+=31;
default:break;
}
time+=day;
Integer integer = new Integer(time);
computer.addActionListener( listener);
nowtime.setText(""+time);
}catch(Exception exp){
System.out.println("请重新输入");
}
}
}
public static void main(String[] args){

Computer com=new Computer();
com.setBounds(100, 100, 400, 400);
com.setTitle("天数计算器");
}
}