Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

147 строки
4.5 KiB

  1. package com.netsdk.demo.frame.AutoRegister;
  2. import java.awt.BorderLayout;
  3. import java.awt.Dimension;
  4. import java.awt.FlowLayout;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import java.awt.event.WindowAdapter;
  8. import java.awt.event.WindowEvent;
  9. import javax.swing.JButton;
  10. import javax.swing.JDialog;
  11. import javax.swing.JLabel;
  12. import javax.swing.JOptionPane;
  13. import javax.swing.JPanel;
  14. import javax.swing.JPasswordField;
  15. import javax.swing.JTextField;
  16. import com.netsdk.common.BorderEx;
  17. import com.netsdk.common.DeviceManagerListener;
  18. import com.netsdk.common.Res;
  19. /**
  20. * 在树上修改设备
  21. */
  22. public class ModifyDeviceDialog extends JDialog{
  23. private static final long serialVersionUID = 1L;
  24. private DeviceManagerListener listener;
  25. public void addDeviceManagerListener(DeviceManagerListener listener) {
  26. this.listener = listener;
  27. }
  28. private String deviceId = "";
  29. private String username = "";
  30. private String password = "";
  31. public ModifyDeviceDialog(String deviceId, String username, String password){
  32. setTitle(Res.string().getModifyDevice());
  33. setLayout(new BorderLayout());
  34. setModal(true);
  35. pack();
  36. setSize(220, 180);
  37. setResizable(false);
  38. setLocationRelativeTo(null);
  39. setDefaultCloseOperation(DISPOSE_ON_CLOSE); // 释放窗体
  40. this.deviceId = deviceId;
  41. this.username = username;
  42. this.password = password;
  43. ModifyDevicePanel addDevicePanel = new ModifyDevicePanel();
  44. add(addDevicePanel, BorderLayout.CENTER);
  45. addWindowListener(new WindowAdapter() {
  46. public void windowClosing(WindowEvent e){
  47. dispose();
  48. }
  49. });
  50. }
  51. /*
  52. * 修改设备面板
  53. */
  54. private class ModifyDevicePanel extends JPanel {
  55. private static final long serialVersionUID = 1L;
  56. public ModifyDevicePanel() {
  57. BorderEx.set(this, "", 2);
  58. setLayout(new FlowLayout());
  59. JLabel deviceIdLabel = new JLabel(Res.string().getDeviceID(), JLabel.CENTER);
  60. JLabel usernameLabel = new JLabel(Res.string().getUserName(), JLabel.CENTER);
  61. JLabel passwordLabel = new JLabel(Res.string().getPassword(), JLabel.CENTER);
  62. deviceIdLabel.setPreferredSize(new Dimension(60, 21));
  63. usernameLabel.setPreferredSize(new Dimension(60, 21));
  64. passwordLabel.setPreferredSize(new Dimension(60, 21));
  65. deviceIdTextField = new JTextField();
  66. usernameTextField = new JTextField();
  67. passwordPasswordField = new JPasswordField();
  68. deviceIdTextField.setPreferredSize(new Dimension(120, 20));
  69. usernameTextField.setPreferredSize(new Dimension(120, 20));
  70. passwordPasswordField.setPreferredSize(new Dimension(120, 20));
  71. JButton modifyDeviceBtn = new JButton(Res.string().getModify());
  72. JButton cancelBtn = new JButton(Res.string().getCancel());
  73. modifyDeviceBtn.setPreferredSize(new Dimension(90, 21));
  74. cancelBtn.setPreferredSize(new Dimension(90, 21));
  75. add(deviceIdLabel);
  76. add(deviceIdTextField);
  77. add(usernameLabel);
  78. add(usernameTextField);
  79. add(passwordLabel);
  80. add(passwordPasswordField);
  81. add(modifyDeviceBtn);
  82. add(cancelBtn);
  83. deviceIdTextField.setText(deviceId);
  84. usernameTextField.setText(username);
  85. passwordPasswordField.setText(password);
  86. // 修改
  87. modifyDeviceBtn.addActionListener(new ActionListener() {
  88. @Override
  89. public void actionPerformed(ActionEvent arg0) {
  90. if(deviceIdTextField.getText().equals("")) {
  91. JOptionPane.showMessageDialog(null, Res.string().getInput() + Res.string().getDeviceID(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE);
  92. return;
  93. }
  94. if(usernameTextField.getText().equals("")) {
  95. JOptionPane.showMessageDialog(null, Res.string().getInput() + Res.string().getUserName(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE);
  96. return;
  97. }
  98. if((new String(passwordPasswordField.getPassword()).trim()).equals("")) {
  99. JOptionPane.showMessageDialog(null, Res.string().getInput() + Res.string().getPassword(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE);
  100. return;
  101. }
  102. dispose();
  103. listener.onDeviceManager(deviceIdTextField.getText(),
  104. usernameTextField.getText(),
  105. new String(passwordPasswordField.getPassword()).trim());
  106. }
  107. });
  108. // 取消,关闭
  109. cancelBtn.addActionListener(new ActionListener() {
  110. @Override
  111. public void actionPerformed(ActionEvent arg0) {
  112. dispose();
  113. }
  114. });
  115. }
  116. }
  117. private JTextField deviceIdTextField;
  118. private JTextField usernameTextField;
  119. private JPasswordField passwordPasswordField;
  120. }