📄 jf_view_student.java
字号:
package appstu.view;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JSplitPane;
import javax.swing.JPanel;
import java.awt.FlowLayout;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JButton;
import java.awt.GridLayout;
import javax.swing.JTextField;
import java.awt.Dimension;
import javax.swing.JInternalFrame;
import appstu.util.RetrieveObject;
import appstu.util.SendFocuseAdapter;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import javax.swing.DefaultDesktopManager;
import appstu.util.ProduceMaxBh;
import javax.swing.table.DefaultTableModel;
import appstu.util.JdbcAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
public class JF_view_student extends JInternalFrame {
BorderLayout borderLayout1 = new BorderLayout();
JSplitPane jSplitPane1 = new JSplitPane();
JPanel jPanel1 = new JPanel();
FlowLayout flowLayout1 = new FlowLayout();
JLabel jLabel1 = new JLabel();
JComboBox jComboBox1 = new JComboBox();
JLabel jLabel2 = new JLabel();
JComboBox jComboBox2 = new JComboBox();
JButton jBadd = new JButton();
JButton jBsave = new JButton();
JPanel jPanel3 = new JPanel();
GridLayout gridLayout1 = new GridLayout();
JLabel jLabel3 = new JLabel();
JTextField jTextField1 = new JTextField();
JLabel jLabel4 = new JLabel();
JTextField jTextField2 = new JTextField();
JLabel jLabel5 = new JLabel();
JTextField jTextField3 = new JTextField();
JLabel jLabel6 = new JLabel();
JTextField jTextField4 = new JTextField();
JLabel jLabel7 = new JLabel();
JComboBox jComboBox3 = new JComboBox();
JLabel jLabel8 = new JLabel();
JTextField jTextField5 = new JTextField();
JLabel jLabel9 = new JLabel();
JTextField jTextField6 = new JTextField();
JScrollPane jScrollPane1 = new JScrollPane();
JTable jTable1 = new JTable();
JButton jBrefresh = new JButton();
JButton jBexit = new JButton();
JButton jBdel = new JButton();
String gradeID[] = null;
String classID[] = null;
public JF_view_student() {
try {
jbInit();
initialize();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(borderLayout1);
jSplitPane1.setOrientation(JSplitPane.VERTICAL_SPLIT);
jSplitPane1.setOpaque(false);
jSplitPane1.setVerifyInputWhenFocusTarget(false);
jPanel1.setLayout(flowLayout1);
jLabel1.setText("所属年级:");
jLabel2.setToolTipText("");
jLabel2.setText("所属班级:");
jBadd.setText("添加");
jBadd.addActionListener(new JF_view_student_jBadd_actionAdapter(this));
jBsave.setMnemonic('0');
jBsave.setText("存盘");
jBsave.addActionListener(new JF_view_student_jBsave_actionAdapter(this));
jPanel3.setLayout(gridLayout1);
gridLayout1.setColumns(4);
gridLayout1.setRows(4);
jLabel3.setText("学生编号");
jTextField1.setEnabled(false);
jTextField1.setText("");
jLabel4.setText("班级名称");
jTextField2.setEnabled(false);
jTextField2.setText("");
jLabel5.setText("学生姓名");
jTextField3.setText("");
jLabel6.setText("年龄");
jTextField4.setText("");
jLabel7.setText("性别");
jLabel8.setText("家庭地址");
jTextField5.setText("");
jLabel9.setText("联系电话");
jTextField6.setText("");
jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.
HORIZONTAL_SCROLLBAR_ALWAYS);
jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.
VERTICAL_SCROLLBAR_ALWAYS);
jBrefresh.setText("刷新");
jBrefresh.addActionListener(new JF_view_student_jBrefresh_actionAdapter(this));
jBexit.setText("退出");
jBexit.addActionListener(new JF_view_student_jBexit_actionAdapter(this));
flowLayout1.setAlignment(FlowLayout.RIGHT);
this.setClosable(true);
jBdel.setText("删除");
jBdel.addActionListener(new JF_view_student_jBdel_actionAdapter(this));
jTable1.addMouseListener(new JF_view_student_jTable1_mouseAdapter(this));
jComboBox1.addItemListener(new JF_view_student_jComboBox1_itemAdapter(this));
jComboBox2.addItemListener(new JF_view_student_jComboBox2_itemAdapter(this));
jPanel1.add(jLabel1);
jPanel1.add(jComboBox1);
jPanel1.add(jLabel2);
jPanel1.add(jComboBox2);
jPanel1.add(jBrefresh);
jPanel1.add(jBadd);
jPanel1.add(jBdel);
jPanel1.add(jBsave);
jPanel1.add(jBexit);
jSplitPane1.add(jPanel3, JSplitPane.BOTTOM);
jPanel3.add(jLabel3);
jPanel3.add(jTextField1);
jPanel3.add(jLabel4);
jPanel3.add(jTextField2);
jPanel3.add(jLabel5);
jPanel3.add(jTextField3);
jPanel3.add(jLabel6);
jPanel3.add(jTextField4);
jPanel3.add(jLabel7);
jPanel3.add(jComboBox3);
jPanel3.add(jLabel9);
jPanel3.add(jTextField5);
jPanel3.add(jLabel8);
jPanel3.add(jTextField6);
jTextField3.addKeyListener(new SendFocuseAdapter(jTextField4));
jTextField4.addKeyListener(new SendFocuseAdapter(jTextField5));
jTextField5.addKeyListener(new SendFocuseAdapter(jTextField6));
//jTextField6.addKeyListener(new SendFocuseAdapter(jTextField7));
jSplitPane1.add(jScrollPane1, JSplitPane.TOP);
this.getContentPane().add(jSplitPane1, java.awt.BorderLayout.CENTER);
jScrollPane1.getViewport().add(jTable1);
this.getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
setSize(640,440);
setVisible(true);
jSplitPane1.setDividerLocation(220);
}
public void initialize(){
String sqlStr = null;
sqlStr = "select gradeID,gradeName from tb_gradeinfo";
RetrieveObject retrieve = new RetrieveObject();
java.util.Collection collection = null;
java.util.Iterator iterator = null;
collection = retrieve.getTableCollection(sqlStr);
iterator = collection.iterator();
gradeID = new String[collection.size()];
int i = 0;
while(iterator.hasNext()){
java.util.Vector vdata = (java.util.Vector)iterator.next();
gradeID[i] = String.valueOf(vdata.get(0));
jComboBox1.addItem(vdata.get(1));
i++;
}
/**/
}
//添加一条数据
public void jBadd_actionPerformed(ActionEvent e) {
/*String classid = "0" + String.valueOf(jComboBox1.getSelectedIndex() + 1)
+ "0" + String.valueOf(jComboBox2.getSelectedIndex() + 1);*/
String classid = null;
int index = jComboBox2.getSelectedIndex();
if (index < 0){
JOptionPane.showMessageDialog(null,"班级名称为空,请重新选择班级","系统提示",JOptionPane.ERROR_MESSAGE);
return;
}
classid = classID[index];
String sqlMax = "select max(stuid) from tb_studentinfo where classID = '" + classid + "'";
ProduceMaxBh pm = new appstu.util.ProduceMaxBh();
String stuid = null;
stuid = pm.getMaxBh(sqlMax,classid);
jTextField1.setText(stuid);
//jTextField2.setText(jComboBox1.getSelectedItem().toString() + jComboBox2.getSelectedItem().toString());
jTextField2.setText(jComboBox2.getSelectedItem().toString());
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
jTextField6.setText("");
jComboBox3.removeAllItems();
jComboBox3.addItem("男");
jComboBox3.addItem("女");
jTextField3.requestFocus();
}
public void jBexit_actionPerformed(ActionEvent e) {
javax.swing.DefaultDesktopManager manger = new DefaultDesktopManager();
int result = JOptionPane.showOptionDialog(null,"是否退出学生基本信息录入?","系统提示",
JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,
null,new String[] {"是","否"},"否");
if (result == JOptionPane.YES_OPTION) {
manger.closeFrame(this);
}
}
public void jBsave_actionPerformed(ActionEvent e) {
int result = JOptionPane.showOptionDialog(null,"是否存盘学生基本数据信息?","系统提示",
JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE,
null,new String[] {"是","否"},"否");
if (result == JOptionPane.NO_OPTION) return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -