Java图形界面

Java图形界面

·从窗口界面输入学生信息(创建学生对象。如未录取,则显示“该生分数不足,未录取”。·点击“统计”按钮,显示已录取的所有学生信息(包括学号,姓名,分数等)。·从窗口界面输入学生信息(创建学生对象)。
·输入后,点击界面“录取”按钮,如录取,则显示对话框提示“学号XX
姓名XX已录取”。
如未录取,则显示“该生分数不足,未录取”。
·点击“统计”按钮,显示已录取的所有学生信息(包括学号,姓名,分数等)。
界面有菜单,分别有(录取,统计,退出3个菜单项),“录取”及“统计”功能和同名按钮功能一样。“退出”菜单项,关闭窗口并退出程
序。

 public class student
{
	public 
	double zong,tiyu;
	String xuehao,name;
	public student(String xuehao,String name,double zong,double tiyu)
	{
		this.zong=zong;
		this.name=name;
		this.xuehao=xuehao;
		this.tiyu=tiyu;	
	}
	public double getZong() 
	{
		return zong;
	}
	
	public void setZong(double zong) 
	{
		this.zong = zong;
	}
	
	public double getTiyu() 
	{
		return tiyu;
	}
	
	public void setTiyu(double tiyu) 
	{
		this.tiyu = tiyu;
	}
	
	public String getXuehao() 
	{
		return xuehao;
	}
	
	public void setXuehao(String xuehao)
	{
		this.xuehao = xuehao;
	}
	
	public String getName() 
	{
		return name;
	}
	
	public void setName(String name) 
	{
		this.name = name;
	}
	


}

这部分为学生类的创建包括变量的set和get方法


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.math.*;
import javax.swing.JOptionPane;
public class chuangkoss 
{
	 public static void main(String args[])
	   {
		  new MYWin (); 
	   }
}
class MYWin extends JFrame 
{	
	student[] a1=new student[6];
	private static final long serialVersionUID = -5195884673007466869L;
	JTextField atext,btext,ctext,dtext;
	JButton a,b,c;
	JDialog lu;
	JTextArea  q1;
	int i=0;
	Box baseBox,boxV1,boxV2,boxV3; 
	 MYWin ()
	{

		boxV1=Box.createVerticalBox();
        boxV1.add(new JLabel("总成绩"));
        boxV1.add(Box.createVerticalStrut(40));
        boxV1.add(new JLabel("体育"));
        boxV1.add(Box.createVerticalStrut(40));
        boxV1.add(new JLabel("学号"));
        boxV1.add(Box.createVerticalStrut(40));
        boxV1.add(new JLabel("姓名"));
		atext=new JTextField(10);
		btext=new JTextField(10);
		ctext=new JTextField(10);
		dtext=new JTextField(10);
		a=new JButton("录取");
		b=new JButton("统计");
		c=new JButton("退出");
		 boxV2=Box.createVerticalBox();
		 boxV2.add(atext);
		 boxV2.add(Box.createVerticalStrut(8));
		 boxV2.add(btext);
		 boxV2.add(Box.createVerticalStrut(8));
		 boxV2.add(ctext);
		 boxV2.add(Box.createVerticalStrut(8));
		 boxV2.add(dtext);
		 boxV3=Box.createVerticalBox();
		 boxV3.add(a);
		 boxV3.add(Box.createVerticalStrut(8));
		 boxV3.add(b);
		 boxV3.add(Box.createVerticalStrut(8));
		 boxV3.add(c);

		 baseBox=Box.createHorizontalBox();
		 baseBox.add(boxV1);
	     baseBox.add(Box.createHorizontalStrut(10));
	     baseBox.add(boxV2);
	     baseBox.add(Box.createHorizontalStrut(10));
	     baseBox.add(boxV3);
	      JTextArea q1=new JTextArea (10,20); 
		setLayout(new FlowLayout());

		add(baseBox);
		add(q1);
		validate();
		setBounds(100,100,600,250);
		setVisible(true);
		
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		a.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e)
				{
					String s1 = atext.getText();
					String s2 = btext.getText();
					String s3 = ctext.getText();
					String s4 = dtext.getText();
			  try
			  {

				  Double b1 = Double.parseDouble(s1);
				  Double b2 = Double.parseDouble(s2);
			
					 student temp = new student(s3,s4,b1,b2);
					 if(temp.getZong()>300)
					 {
						JOptionPane.showMessageDialog(null, temp.name+temp.xuehao+"恭喜您被录取");
						a1[++i] = temp;
					 }
						else
							if(temp.zong>290&&temp.tiyu>95)
						{
								JOptionPane.showMessageDialog(null, temp.name+temp.xuehao+"恭喜您被录取");
						}
					else
					{
						JOptionPane.showMessageDialog(null, "很抱歉,您未被录取");
					}
			  } 
			  catch(NullPointerException ee)
			  {
				System.out.println("空指针异常      22");
			  }
				
					
				}
				});
		b.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e)
			{for(int j=i;j>0;j--)
					{
				    q1.append(a1[j].name+"被录取") ;
				    q1.append("\n") ;

					}
			}
			});
		c.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e)
			{
				System.exit(0);
			}
			});

	}


}

这里为窗口部分的创建以及功能的实现
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值