private void init() { add(jlName); add(jtfName); add(jlSex);
if (student.getSex().equals(\男\)) { jrbMan.setSelected(true); } else {
jrbWoman.setSelected(true); }
bgSex.add(jrbMan); bgSex.add(jrbWoman); add(jrbMan); add(jrbWoman); add(jlBirth); add(jtfBirth); add(jlPhone); add(jtfPhone); add(jlQQ); add(jtfQQ);
add(jlEntranceTime);
jtfEntranceTime.setEditable(isUpdateGradeble); add(jtfEntranceTime);
add(jlClass);
jtfClass.setEditable(isUpdateGradeble); // 设置限权 add(jtfClass);
jtfPhoto.setEditable(false);
jtfPhoto.setText(student.getPhoto()); add(jtfPhoto);
// 添加上传照片的监听
jbPhoto.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try {
File file = upload.choose(); if (file != null)
jtfPhoto.setText(file.getPath()); } catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } } });
add(jbPhoto);
add(jlAddr);
jtaAddr.setLineWrap(true); add(jtaAddr);
jbQueryInfo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String name = jtfName.getText().trim(); if (\.equals(name)) {
JOptionPane.showMessageDialog(UpdateInfo.this, \请输入自己的姓名!\); return; }
student.setStudentName(name);
student.setSex(jrbMan.isSelected() ? \男\ : \女\); String date = jtfBirth.getText().trim(); if (\.equals(date)) {
student.setBirth(null);
} else if (date.matches(\)) {
student.setBirth(StudentManage.shiftDate(date)); } else {
JOptionPane.showMessageDialog(UpdateInfo.this, \输入出生日期格式不正确!\\n正确格式为:2011-08-12\);
return; }
if (isUpdateGradeble) { String entranceTime = jtfEntranceTime.getText().trim();
if (\.equals(entranceTime)) { // student.setBirth(null); } else if (entranceTime
.matches(\)) { student.setEntranceTime(StudentManage .shiftDate(entranceTime)); } else {
JOptionPane.showMessageDialog(UpdateInfo.this,
\输入入学时间格式不正确!\\n正确格式为:2011-08-12\);
return;
\);
\);
} }
student.setPhone(jtfPhone.getText().trim()); student.setQq(jtfQQ.getText().trim());
String classes = jtfClass.getText().trim(); if (\.equals(classes)) {
JOptionPane.showMessageDialog(UpdateInfo.this, \学生班级不能为空!\); return; }
student.setClasses(classes);
student.setPhoto(student.getStudentID().trim() + student.setHomeAddr(jtaAddr.getText().trim()); // 上传照片 try {
if (upload.getInputStream() != null) { upload.upload(imagePath
+ student.getStudentID().trim() + }
} catch (FileNotFoundException e1) {
JOptionPane.showMessageDialog(UpdateInfo.this, \上传照片失败,找不到文件!\); e1.printStackTrace(); return;
} catch (IOException e1) {
JOptionPane.showMessageDialog(UpdateInfo.this, \上传照片失败,上传错误!\); e1.printStackTrace(); return; } finally {
upload.colseStream(); // 关闭文件流 }
if (StudentManage.update(student)) {
JOptionPane.showMessageDialog(UpdateInfo.this, \个人信息修改成功!\); setVisible(false); } else {
JOptionPane.showMessageDialog(UpdateInfo.this,
求!\);
} } }
\个人信息修改失败!可能是修改内容不符合要
} } });
add(jbQueryInfo);
jbCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(false); } });
add(jbCancel);
com.ccniit.student.view.ImagePanel类
说明:此类是得到一个图片的路径然后把这个图片读取出来,显示在调用这个类的组件里面,这个类继承了JPanel,可以直接添加在窗口组件上面。这个类是用来读取学生照片,照片会根据窗口的大小来方法或缩小图片,但是图片不会失真 关键代码:
package com.ccniit.student.view;
import java.awt.Graphics;
import javax.swing.ImageIcon; import javax.swing.JPanel;
// 初始化图片的类
public class ImagePanel extends JPanel { private ImageIcon image; private int width; private int height;
private int imageWidth; private int imageHeight; private double rateImage; private double rateFrame;
ImagePanel(String path) {
image = new ImageIcon(path);
imageWidth = image.getIconWidth(); imageHeight = image.getIconHeight();
}
rateImage = (double) imageHeight / imageWidth; }
public ImageIcon getImageIcon() { return this.image; }
protected void paintComponent(Graphics g) { int frameWidth = this.getWidth(); int frameHeight = this.getHeight();
rateFrame = (double) frameHeight / frameWidth; if (rateFrame < rateImage) { height = frameHeight;
width = (int) (height / rateImage); } else {
width = frameWidth;
height = (int) (width * rateImage); }
// System.out.println(width + \
g.drawImage(image.getImage(), 0, 0, width, height, this); }
com.ccniit.student.view.ShowImage类
说明:这个类是显示放大过后的图片,当老师点击学生的图片的会new这个类的对象来,然后把这个图片重新显示在一个比较大的窗口里面,所以图片就会放大。
package com.ccniit.student.view;
import javax.swing.JDialog;
public class ShowImage extends JDialog { public ShowImage(ImagePanel image) { setSize(700, 700); setLocation(600, 0); add(image); } }
com.ccniit.student.view.Uploading类
说明:此类是上传照片的类,进入主界面的添加学生或修改学生成绩的时候就会new这个