package com.imau.view;

import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.imau.base.BaseFraem;
import com.imau.controller.StudentController;
 import com.imau.entry.Student;

/**
 * 
* @author yangzj id,name,sex,age,image,民族
*/
public class StudentInfoView extends BaseFraem {


private static final long serialVersionUID = 1L;
private StudentController controller;
// 组件
private JLabel lid;
private JLabel lname;
private JLabel lno;
private JLabel lsex;
private JLabel lage;
private JLabel limage;
private JLabel lnation;

private JTextField tid;
private JTextField tname;
private JTextField tsex;
private JTextField tno;
private JTextField tage;
private JTextField timage;
private JTextField tnation;

private JButton submit, cancel;

private JPanel panel;

private Student student;

public StudentInfoView(Student student) {
	controller=new StudentController();
	this.setJMenuBar(initMenu());
	this.student=student;
	init();
	
	setFraem();
	

}

private void init() {
	
	lid = new JLabel("ID");
	lname = new JLabel("姓名");
	lno = new JLabel("学号");
	lage = new JLabel("年龄");
	lsex = new JLabel("性別");
	lnation = new JLabel("民族");
	limage = new JLabel("头像");


	tid = new JTextField(10);
	tid.setEnabled(false);
	tname = new JTextField(10);
	tno = new JTextField(10);
	tsex = new JTextField(10);
	tage = new JTextField(10);
	timage = new JTextField(10);
	tnation = new JTextField(10);
	
	submit=new JButton("确定");
	cancel=new JButton("取消");
	

	//学生有信息;填充
	if(student!=null) {
		tid.setText(student.getId()+"");
		tname.setText(student.getName());
		tno.setText(student.getNo());
		tage.setText(student.getAge()+"");
		tsex.setText(student.getSex());
		tnation.setText(student.getNation());
	}
	
	
	this.setLayout(new FlowLayout());
	panel = new JPanel();
	panel.setLayout(new GridLayout(7, 2));
	panel.add(lid);
	panel.add(tid);

	panel.add(lname);
	panel.add(tname);

	panel.add(lno);
	panel.add(tno);

	panel.add(lage);
	panel.add(tage);

	panel.add(lsex);
	panel.add(tsex);

	panel.add(lnation);
	panel.add(tnation);

	panel.add(submit);
	panel.add(cancel);

	this.add(panel);
	
	addEvent();
	
 	}

	private void addEvent() {
	submit.addActionListener(new MyListener2());
	cancel.addActionListener(new MyListener2());
 	}

	class MyListener2 implements ActionListener{

	@Override
	public void actionPerformed(ActionEvent e) {
	 
		if(e.getSource()==submit) 
		{
			//1.获取输入信心
			String id=tid.getText();
			String name = tname.getText();
			String no = tno.getText();
			long  age = Integer.valueOf(tage.getText());
			String sex=tsex.getText();
			String nation=tnation.getText();

			if(id!=null && !id.equals("")) {
				
				//修改请求
				Student student=new Student(Long.valueOf(id),name, no, age, sex, nation);
				
				if(controller.update(student)) {
					
					 
					JOptionPane.showMessageDialog(null, "操作成功");
					new StudentListView();
					dispose();
				}else {
					JOptionPane.showMessageDialog(null, "操作失败");
					
				}
				
				
			}else {
				
				
				Student student=new Student(name, no, age, sex, nation);
				//2. 添加请求
				if (controller.add(student)) {
					JOptionPane.showMessageDialog(null, "操作成功");
					new StudentListView();
					dispose();
				}else {
					JOptionPane.showMessageDialog(null, "操作失败");
				}
				
			}
			
			
			
		}else {
			
			new StudentListView();
			dispose();
		}
	}
	
  }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值