中国地质大学北京信息管理与信息系统——Java程序设计第三次上机(录入界面又又改进了)

2021/12/20 17:19:34

本文主要是介绍中国地质大学北京信息管理与信息系统——Java程序设计第三次上机(录入界面又又改进了),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

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
				String xf="[1-9]";
				String xm="^[\\u4e00-\\u9fa5_a-zA-Z_]{1,10}";
				String cj="^(100|(([1-9]){1}[0-9]?|0{1})((\\.)([0-9]){1,2})?)$";
				if(!jt0.getText().matches(xm)) {
					jt0.setText("");
				}else if(!jt1.getText().matches(xm)){
					jt1.setText("");
				}else if(!jt2.getText().matches(xf)) {
					jt2.setText("");
				}else if(!jt3.getText().matches(cj)) {
					jt3.setText("");
				}else if(!jt4.getText().matches(xm)) {
					jt4.setText("");
				}
				else {
					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);
	}
}

无语了,感觉木有意思



这篇关于中国地质大学北京信息管理与信息系统——Java程序设计第三次上机(录入界面又又改进了)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程