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

中国地质大学北京信息管理与信息系统——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,信息管理,getText,add,中国地质大学,import,new,jf,JLabel
来源: https://blog.csdn.net/MortyC99430/article/details/122045136