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();
}
}
}
}
六
最新推荐文章于 2024-05-10 18:55:23 发布