📄 managerpanel.java
字号:
/* * ManagerPanel.java * * Created on 2004年1月16日, 下午3:38 */package romulus.Manager;import javax.swing.*;import java.util.*;/** * * @author S */public class ManagerPanel extends javax.swing.JPanel { /** Creates new form ManagerPanel */ public ManagerPanel(ManagerToolSet mts) { initComponents(); this.mts = mts; } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ private void initComponents() {//GEN-BEGIN:initComponents java.awt.GridBagConstraints gridBagConstraints; AddUserPanel = new javax.swing.JPanel(); UsernameTextField = new javax.swing.JTextField(); AddUserButton = new javax.swing.JButton(); ChangePassPanel = new javax.swing.JPanel(); PassTextField = new javax.swing.JTextField(); CommitButton = new javax.swing.JButton(); ListScrollPane = new javax.swing.JScrollPane(); TestList = new javax.swing.JList(); UserScrollPane = new javax.swing.JScrollPane(); UserList = new javax.swing.JList(); AssignTestPanel = new javax.swing.JPanel(); UserComboBox = new javax.swing.JComboBox(); TestComboBox = new javax.swing.JComboBox(); AssignButton = new javax.swing.JButton(); setLayout(new java.awt.BorderLayout()); setFont(getFont()); addComponentListener(new java.awt.event.ComponentAdapter() { public void componentShown(java.awt.event.ComponentEvent evt) { formComponentShown(evt); } }); AddUserPanel.setLayout(new java.awt.GridBagLayout()); AddUserPanel.setBorder(new javax.swing.border.TitledBorder(null, "\u65b0\u5efa\u7528\u6237\u540d", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, getFont())); AddUserPanel.setFont(getFont()); UsernameTextField.setFont(getFont()); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 10); gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; AddUserPanel.add(UsernameTextField, gridBagConstraints); AddUserButton.setFont(getFont()); AddUserButton.setText("\u65b0\u5efa\u7528\u6237"); AddUserButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { AddUserButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 10); gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; AddUserPanel.add(AddUserButton, gridBagConstraints); add(AddUserPanel, java.awt.BorderLayout.NORTH); ChangePassPanel.setLayout(new java.awt.GridBagLayout()); ChangePassPanel.setBorder(new javax.swing.border.TitledBorder(null, "\u57fa\u672c\u4fe1\u606f", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, getFont())); ChangePassPanel.setFont(getFont()); PassTextField.setFont(getFont()); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 10); gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; ChangePassPanel.add(PassTextField, gridBagConstraints); CommitButton.setFont(getFont()); CommitButton.setText("\u4fee\u6539\u5bc6\u7801"); CommitButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { CommitButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 10); gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; ChangePassPanel.add(CommitButton, gridBagConstraints); ListScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); ListScrollPane.setFont(getFont()); TestList.setFont(getFont()); TestList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); TestList.setEnabled(false); ListScrollPane.setViewportView(TestList); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 10); gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; ChangePassPanel.add(ListScrollPane, gridBagConstraints); UserScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); UserScrollPane.setFont(getFont()); UserList.setFont(getFont()); UserList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION); UserList.addListSelectionListener(new javax.swing.event.ListSelectionListener() { public void valueChanged(javax.swing.event.ListSelectionEvent evt) { UserListValueChanged(evt); } }); UserScrollPane.setViewportView(UserList); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 10); gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; ChangePassPanel.add(UserScrollPane, gridBagConstraints); add(ChangePassPanel, java.awt.BorderLayout.CENTER); AssignTestPanel.setLayout(new java.awt.GridBagLayout()); AssignTestPanel.setBorder(new javax.swing.border.TitledBorder(null, "\u5b89\u6392\u8003\u8bd5\u9879\u76ee", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, getFont())); AssignTestPanel.setFont(getFont()); UserComboBox.setFont(getFont()); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 10); gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; AssignTestPanel.add(UserComboBox, gridBagConstraints); TestComboBox.setFont(getFont()); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 10); gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; AssignTestPanel.add(TestComboBox, gridBagConstraints); AssignButton.setFont(getFont()); AssignButton.setText("\u5b89\u6392\u8003\u8bd5"); AssignButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { AssignButtonActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 10); gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; AssignTestPanel.add(AssignButton, gridBagConstraints); add(AssignTestPanel, java.awt.BorderLayout.SOUTH); }//GEN-END:initComponents private void UserListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_UserListValueChanged // Add your handling code here: try{ Vector tests = this.mts.getUserTests((String)(this.UserList.getSelectedValue())); String pass = this.mts.getUserPass((String)(this.UserList.getSelectedValue())); this.testlist = new DefaultListModel(); for(Iterator ite = tests.iterator(); ite.hasNext(); ){ this.testlist.addElement(ite.next()); } this.TestList.setModel(testlist); this.PassTextField.setText(pass); } catch(Exception e){ e.printStackTrace(); firePropertyChange(RomulusManagerClientFrame.ShowMSGProp, RomulusManagerClientFrame.ExitMSGProp, "Errors"); } }//GEN-LAST:event_UserListValueChanged private void formComponentShown(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentShown // Add your handling code here: clearAll(); }//GEN-LAST:event_formComponentShown private void AssignButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AssignButtonActionPerformed // Add your handling code here: try{ firePropertyChange(RomulusManagerClientFrame.ShowMSGProp, "", "Assign test successful"); this.mts.assignTest((String)(this.usercombo.getSelectedItem()), (String)(this.testcombo.getSelectedItem())); } catch(Exception e){ e.printStackTrace(); firePropertyChange(RomulusManagerClientFrame.ShowMSGProp, RomulusManagerClientFrame.ExitMSGProp, "Errors"); } }//GEN-LAST:event_AssignButtonActionPerformed private void CommitButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CommitButtonActionPerformed // Add your handling code here: try{ if(!this.UserList.isSelectionEmpty()){ firePropertyChange(RomulusManagerClientFrame.ShowMSGProp, "", "Change password successful"); this.mts.setUserPass((String)(this.UserList.getSelectedValue()), (String)(this.PassTextField.getText())); } } catch(Exception e){ e.printStackTrace(); firePropertyChange(RomulusManagerClientFrame.ShowMSGProp, RomulusManagerClientFrame.ExitMSGProp, "Errors"); } }//GEN-LAST:event_CommitButtonActionPerformed private void AddUserButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddUserButtonActionPerformed // Add your handling code here: try{ if(this.mts.AddNewUser(this.UsernameTextField.getText())){ clearAll(); firePropertyChange(RomulusManagerClientFrame.ShowMSGProp, "", "Add a new username successful"); } else{ firePropertyChange(RomulusManagerClientFrame.ShowMSGProp, "", "Add a new username failed"); } } catch(Exception e){ e.printStackTrace(); firePropertyChange(RomulusManagerClientFrame.ShowMSGProp, RomulusManagerClientFrame.ExitMSGProp, "Add a new username error"); } }//GEN-LAST:event_AddUserButtonActionPerformed private void clearAll(){ this.UsernameTextField.setText(null); this.PassTextField.setText(null); this.UserList.removeAll(); this.TestList.removeAll(); this.UserComboBox.removeAllItems(); this.TestComboBox.removeAllItems(); try{ Vector users = mts.getUsers(); this.userlist = new DefaultListModel(); for(Iterator ite = users.iterator(); ite.hasNext(); ){ this.userlist.addElement(ite.next()); } this.UserList.setModel(userlist); this.usercombo = new DefaultComboBoxModel(users); this.UserComboBox.setModel(this.usercombo); this.testcombo = new DefaultComboBoxModel(mts.getTests()); this.TestComboBox.setModel(this.testcombo); } catch(Exception e){ e.printStackTrace(); firePropertyChange(RomulusManagerClientFrame.ShowMSGProp, RomulusManagerClientFrame.ExitMSGProp, "Errors"); } } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JComboBox UserComboBox; private javax.swing.JButton AddUserButton; private javax.swing.JScrollPane UserScrollPane; private javax.swing.JPanel AssignTestPanel; private javax.swing.JPanel ChangePassPanel; private javax.swing.JTextField UsernameTextField; private javax.swing.JPanel AddUserPanel; private javax.swing.JList TestList; private javax.swing.JButton AssignButton; private javax.swing.JComboBox TestComboBox; private javax.swing.JList UserList; private javax.swing.JButton CommitButton; private javax.swing.JTextField PassTextField; private javax.swing.JScrollPane ListScrollPane; // End of variables declaration//GEN-END:variables private ManagerToolSet mts; private DefaultListModel userlist; private DefaultListModel testlist; private DefaultComboBoxModel usercombo; private DefaultComboBoxModel testcombo; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -