关闭

浙江工业大学简易绩点计算器Java版

635人阅读 评论(0) 收藏 举报
分类:

工大绩点计算器Java版。编译环境eclipse,jdk1.7 。

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.lang.String;
import java.util.Vector;

public class jidian extends JFrame implements ActionListener 
{
    JButton bt1,bt2,bt3,bt4,bt5; 
    JTextField score,credit,course;
    Vector<String> Course=new Vector<>();
    Vector Score=new Vector();
    Vector Credit=new Vector();
    static double jidian=0;
    TextField t2; 
    TextArea Area;
    int[] sc=new int[10];
    jidian() 
    {
       	super("浙江工业大学绩点计算器  by Ning");
    	addWindowListener(new WindowAdapter()
        {
        	public void windowClosing(WindowEvent e) 
        	{
        		System.exit(0);
        	}
        }); 
        setSize(500,250); 
        setLocation(400,200);
        setResizable(false);
        setLayout(new FlowLayout());
        Area=new TextArea ("",5,33);
        Area.setEditable(false); 
        score=new JTextField(3);
        credit=new JTextField(3);
        course=new JTextField(6);
        t2=new TextField(10);
        t2.setEditable(false);
        bt1=new JButton("添加"); 
        bt2=new JButton("计算");
        bt3=new JButton("重新计算");
        bt4=new JButton("退出");
        bt5=new JButton("撤销"); 
        add(new JLabel("科目:"));
        add(course);
        add(new JLabel("分数:"));
        add(score);
        add(new JLabel("学分:"));
        add(credit);
        JPanel jp2= new JPanel();
        jp2.add(bt1);
        jp2.add(bt5);
        add(jp2);
        add(Area);
        add(new JLabel("绩点 :"));
        add(t2);
        add(bt2);
        add(bt3);
        JPanel jp1= new JPanel();
        jp1.add(bt4);
        add(jp1); 
        bt1.addActionListener(this);
        bt2.addActionListener(this);
        bt3.addActionListener(this);
        bt4.addActionListener(this);
        bt5.addActionListener(this);
    }
    public void actionPerformed(ActionEvent e) 
    {
    	if (e.getSource()==bt1)//添加
    	{		
			String s1=score.getText();
			String s2=credit.getText();
			String s3=course.getText();
			double n1,n2;
			n1=Double.parseDouble(s1);
			n2=Double.parseDouble(s2);
			if(Course.size()==0)
			{
				Area.setText("");
			}
			Score.add(n1);
			Credit.add(n2);
			Course.add(s3);
			Area.append(s3+"  分数:"+n1+"  学分:"+n2+"\n");   
		    score.setText("");
		    course.setText("");
		    credit.setText("");
		    t2.setText("");
			score.requestFocus();
		}
	    if (e.getSource()==bt2)//计算
	    {
	    	double zongfen=0;
	    	double zongxuefen=0;
	    	double a,b;
	    	if(Course.size()==0)
	    		jidian=0;
	    	else
	    	{
	    		for(int i=0;i<Score.size();i++)
	    		{
	    			a=(double) Score.get(i);
	    			b=(double) Credit.get(i);
	    			if(a>=60)
	    			{	
	    				zongfen=(a-50)/10*b+zongfen;
	    			}
	    			else
	    			{
	    				zongfen=zongfen+0;
	    			}
	    			zongxuefen=b+zongxuefen;
	    		
	    		}
	    		jidian=zongfen/zongxuefen;
	    		jidian=(double)Math.round(jidian*10000)/10000;
	    	}
	    	t2.setText(String.valueOf(jidian));
	    }
		if (e.getSource()==bt3)//清除
	    {
	    	score.requestFocus();
	    	t2.setText("");
	        Area.setText("");
	        for(int i=0;i<Course.size();i++)
	        {
	        	Course.remove(i);
	        	Score.remove(i);
	        	Credit.remove(i);
	        }
	        jidian=0;
	    }    
	    if (e.getSource()==bt4)//退出
	    {
	    	for (int i=0; i<100000000; i++);
	        dispose();
	    }
	    if (e.getSource()==bt5)//撤销
	    {
	    	t2.setText("");
	    	if(Course.size()==0)
	    	{
	    		Area.setText("");
	    		Area.append("没有课程,不能撤销输入!"+"\n"); 
	    	}
	    	else
	    	{
	    		Area.setText("");
	    		Course.remove(Course.size()-1);
		    	Score.remove(Score.size()-1);
		    	Credit.remove(Credit.size()-1);
		    	for(int i=0;i<Course.size();i++)
		    	{
		    		Area.append(Course.get(i)+"  分数:"+Score.get(i)+"  学分:"+Credit.get(i)+"\n");
		    	}
		    	Area.append("已删除上一个课程!请重新输入该课程。"+"\n"); 
	    	}
	     }
    }
	public static void main(String args[]) 
	{
		jidian l=new jidian();
	    l.setVisible(true);
	}
}


0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:9135次
    • 积分:154
    • 等级:
    • 排名:千里之外
    • 原创:5篇
    • 转载:2篇
    • 译文:0篇
    • 评论:33条
    文章分类
    最新评论