📄 modifystudinfopanel.java
字号:
gridBagConstraints.gridy = 3;
gridBagConstraints.weightx = 5.0;
gridBagConstraints.weighty = 0.1;
add(studentid, gridBagConstraints);
year.setColumns(20);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 6;
gridBagConstraints.weightx = 5.0;
gridBagConstraints.weighty = 0.1;
add(year, gridBagConstraints);
java.util.List<ClassInfo> list=null;
ClassDao classdao=new ClassDao();
list=classdao.getAllClass();
Iterator<ClassInfo> iter=list.iterator();
while(iter.hasNext())//这里的Iterator因为已经设定了<ClassInfo>,所以iter.next()不用强制转化为ClassInfo;
classid.addItem(iter.next().getClassID());
classid.setPreferredSize(new java.awt.Dimension(130, 23));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 5;
gridBagConstraints.weightx = 5.0;
gridBagConstraints.weighty = 0.1;
add(classid, gridBagConstraints);
sex.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "男",
"女" }));
sex.setPreferredSize(new java.awt.Dimension(130, 23));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 4;
gridBagConstraints.weightx = 5.0;
gridBagConstraints.weighty = 0.1;
add(sex, gridBagConstraints);
jLabel15.setBorder(javax.swing.BorderFactory
.createLineBorder(new java.awt.Color(0, 0, 0)));
jLabel15.setPreferredSize(new java.awt.Dimension(125, 140));
jLabel15.setText("photo");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 4;
gridBagConstraints.gridy = 2;
gridBagConstraints.gridwidth = 3;
gridBagConstraints.gridheight = 3;
gridBagConstraints.weightx = 5.0;
add(jLabel15, gridBagConstraints);
photo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
photoActionPerformed(evt);
}
});
photo.setText("\u63d2\u5165\u76f8\u7247");
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 4;
gridBagConstraints.gridy = 5;
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.weightx = 5.0;
gridBagConstraints.weighty = 0.1;
add(photo, gridBagConstraints);
family.setColumns(20);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 3;
gridBagConstraints.gridy = 5;
gridBagConstraints.weightx = 5.0;
gridBagConstraints.weighty = 0.1;
add(family, gridBagConstraints);
day.setColumns(20);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 5;
gridBagConstraints.gridy = 6;
gridBagConstraints.weightx = 5.0;
gridBagConstraints.weighty = 0.1;
add(day, gridBagConstraints);
identification.setColumns(20);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 7;
gridBagConstraints.weightx = 5.0;
gridBagConstraints.weighty = 0.1;
add(identification, gridBagConstraints);
month.setColumns(20);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 3;
gridBagConstraints.gridy = 6;
gridBagConstraints.weightx = 5.0;
gridBagConstraints.weighty = 0.1;
add(month, gridBagConstraints);
querystudentid.setColumns(20);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 1;
gridBagConstraints.weightx = 5.0;
gridBagConstraints.weighty = 0.1;
add(querystudentid, gridBagConstraints);
jScrollPane1.setBorder(javax.swing.BorderFactory.createTitledBorder(
null, "\u8bf4\u660e",
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
javax.swing.border.TitledBorder.DEFAULT_POSITION,
new java.awt.Font("宋体", 0, 12), new java.awt.Color(0, 0, 0)));
jScrollPane1.setPreferredSize(new java.awt.Dimension(600, 120));
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 9;
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
gridBagConstraints.weightx = 5.0;
gridBagConstraints.weighty = 0.1;
add(jScrollPane1, gridBagConstraints);
}
private void queryActionPerformed(java.awt.event.ActionEvent evt) {
StudentInfoDao studentinfodao=new StudentInfoDao();
StudentInfo studentinfo=studentinfodao.getStudentInfo(querystudentid.getText().trim());
if(studentinfo!=null){
studentid.setText(studentinfo.getStudentID());
name.setText(studentinfo.getStudentName());
age.setText(studentinfo.getAge());
sex.setSelectedItem(studentinfo.getSex());
classid.setSelectedItem(studentinfo.getClassID());
family.setText(studentinfo.getFamily());
identification.setText(studentinfo.getIdentification());
String[] birth=studentinfo.getBirthday().split("-");
year.setText(birth[0]);
month.setText(birth[1]);
day.setText(birth[2]);
begintime.setText(studentinfo.getBeginTime());
jTextArea1.setText(studentinfo.getRemarks());
InputStream input=studentinfo.getOLEPhoto();
byte[] by=null;
if(input!=null){
try{
by=new byte[input.available()];
ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
int ch;
while ((ch = input.read()) !=-1)
bytestream.write(ch);
by=bytestream.toByteArray();
}catch(IOException e){
e.printStackTrace();
}
}
if(by!=null){
ImageIcon image=new ImageIcon(by);
image.setImage(image.getImage().getScaledInstance(150, 200,Image.SCALE_DEFAULT));
jLabel15.setIcon(image);
jLabel15.setText("");
}
save=querystudentid.getText().trim();
}else{
JOptionPane.showMessageDialog(null, "对不起,没有该学号,请重新输入!");
}
}
private void photoActionPerformed(java.awt.event.ActionEvent evt) {
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"JPG & GIF Images", "jpg", "gif");
chooser.setFileFilter(filter);
int returnVal = chooser.showOpenDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION){
lujin=chooser.getSelectedFile().getPath();
jLabel15.setIcon(new ImageIcon(lujin.trim()));
}
}
private void okActionPerformed(java.awt.event.ActionEvent evt) {
if(studentid.getText().equals("")||age.getText().equals("")
||sex.getSelectedItem().equals("")||identification.getText().equals("")
||classid.getSelectedItem().equals("")||name.getText().equals("")
||family.getText().equals("")||begintime.getText().equals("")){
JOptionPane.showMessageDialog(null, "请填好资料");
return ;
}
StudentInfoDao studentinfodao=new StudentInfoDao();
StudentInfo studentinfo=new StudentInfo();
studentinfo.SetStudentID(studentid.getText().trim());
studentinfo.SetStudentName(name.getText().trim());
studentinfo.SetAge(age.getText().trim());
studentinfo.SetSex(sex.getSelectedItem().toString().trim());
studentinfo.SetClassID(classid.getSelectedItem().toString().trim());
studentinfo.SetFamily(family.getText().trim());
studentinfo.SetBirthday(year.getText().trim()
+"-"+month.getText().trim()+"-"+day.getText().trim());
studentinfo.SetIdentification(identification.getText().trim());
studentinfo.setBeginTime(begintime.getText().trim());
studentinfo.SetRemarks(jTextArea1.getText().trim());
if(lujin!=null){
try{
studentinfo.SetOLEPhoto(new FileInputStream(lujin.trim()));
}catch(IOException e){
}
}
try{
studentinfodao.modifyStudentInfo(studentinfo,save);
}catch(Exception e){
e.printStackTrace();
return;
}
}
private String save;
private String lujin;
private javax.swing.JTextField age;
private javax.swing.JTextField begintime;
private javax.swing.JComboBox classid;
private javax.swing.JTextField day;
private javax.swing.JTextField family;
private javax.swing.JTextField identification;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel13;
private javax.swing.JLabel jLabel14;
private javax.swing.JLabel jLabel15;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextField month;
private javax.swing.JTextField name;
private javax.swing.JButton ok;
private javax.swing.JButton photo;
private javax.swing.JButton query;
private javax.swing.JTextField querystudentid;
private javax.swing.JComboBox sex;
private javax.swing.JTextField studentid;
private javax.swing.JTextField year;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -