中国地质大学北京信息管理与信息系统——Java程序设计第三次上机part1,成绩录入界面再次改进(原版看第二次上机作业)

package Nobody_care;

import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;

public class homework_2 {
	static double fenzi=0.0,fenmu=0.0;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		JFrame jf=new JFrame("成绩录入界面");
		jf.setLayout(new GridLayout(7,2));
		JLabel jl0=new JLabel("学生姓名");
		JTextField jt0=new JTextField("");
		JLabel jl1=new JLabel("课程名称");
		JTextField jt1=new JTextField();
		JLabel jl2=new JLabel("课程学分");
		JTextField jt2=new JTextField();
		JLabel jl3=new JLabel("课程成绩");
		JTextField jt3=new JTextField();
		JLabel jl4=new JLabel("开设专业");
		JTextField jt4=new JTextField();
		JButton jb1=new JButton("提交");
		JButton jb2=new JButton("重置");
		JLabel xue=new JLabel("学分绩点");
		JLabel xian=new JLabel("");
		jb2.addActionListener(new AbstractAction() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				jt0.setText("");
				jt1.setText("");
				jt2.setText("");
				jt3.setText("");
				jt4.setText("");
			}
		});
		
		jb1.addActionListener(new AbstractAction() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				try {
					File file=new File("C:\\Users\\Dav\\Desktop\\java_text.txt");
					if(!file.exists()) {
						file.createNewFile();
					}
					///Users/morty/eclipse-workspace/Nobody care
					FileWriter fileWriter=new FileWriter("C:/Users/Dav/Desktop/java_text.txt",true);
					fileWriter.write(jl0.getText()+" ");fileWriter.write(jt0.getText()+' ');
					fileWriter.write(jl1.getText()+" ");fileWriter.write(jt1.getText()+' ');
					fileWriter.write(jl2.getText()+" ");fileWriter.write(jt2.getText()+" ");
					fileWriter.write(jl3.getText()+" ");fileWriter.write(jt3.getText()+" ");
					fileWriter.write(jl4.getText()+" ");fileWriter.write(jt4.getText()+" ");
					//fenmu+=Double.parseDouble(jt2.getText());
					//fenzi+=Double.parseDouble(jt2.getText())*get(Double.parseDouble(jt3.getText()));
					//fileWriter.write("\n累积学分:"+fenzi/fenmu+"\n");
					double a=get(Double.parseDouble(jt3.getText()));
					xian.setText(a+"");
					fileWriter.close();
				}catch(IOException e1){
					e1.printStackTrace();
				}
				new myjd1();
			}
		});
		jf.add(jl0);jf.add(jt0);
		jf.add(jl1);jf.add(jt1);jf.add(jl2);jf.add(jt2);
		jf.add(jl3);jf.add(jt3);jf.add(jl4);jf.add(jt4);
		jf.add(jb1);jf.add(jb2);jf.add(xue);jf.add(xian);
		jf.setBounds(500,250,400,400);
		jf.setVisible(true);
		jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
	}
	public static double get(Double n) {
		Double j=0.0;
		if(n>=90) {
			j=4.0;
		}else if(n>=85) {
			j=3.5;
		}else if(n>=80) {
			j=3.0;
		}else if(n>=75){
			j=2.5;
		}else if(n>=70) {
			j=2.0;
		}else if(n>=65) {
			j=1.5;
		}else if(n>=60){
			j=1.0;
		}
		return j;
	}
}
class myjd1 extends JDialog{
	public myjd1() {
		this.setVisible(true);this.setBounds(500,250,200,80);Container c = this.getContentPane();
		JLabel l1= new JLabel("提交成功",JLabel.CENTER);
		c.add(l1);
	}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值