Ошибка написание интерфейса для mail client - Java

Узнай цену своей работы

Формулировка задачи:

Добрый день. Недавно начал осваивать написание мэйл клиентов на java. У меня есть код, но и имеется маленькая ошибка с геттером. На вид очень простая, но мне не по зубам. Помогите пожалуйста. Вот сама ошибка:
Листинг программы
  1. public String getType() {
  2. return (String) typeComboBox.getSelectedItem();
А Вот весь код:
Листинг программы
  1. package javamailproject;
  2. import java.awt.event.WindowAdapter;
  3. import java.awt.event.WindowEvent;
  4. import javax.swing.JOptionPane;
  5. public class ConnectDialog extends javax.swing.JDialog {
  6. public ConnectDialog(java.awt.Frame parent) {
  7. super(parent, true);
  8. setTitle("Connection...");
  9. addWindowListener(new WindowAdapter() {
  10. @Override
  11. public void windowClosing(WindowEvent e) {
  12. actionCancel();
  13. }
  14. });
  15. setLocationRelativeTo(parent);
  16. initComponents();
  17. }
  18. private void actionConnect() {
  19. if (serverTextField.getText().trim().length() < 1
  20. || usernameTextField.getText().trim().length() < 1
  21. || passwordField.getPassword().length < 1
  22. || smtpServerTextField.getText().trim().length() < 1) {
  23. JOptionPane.showMessageDialog(this, "Error!", "Fill all gaps!", JOptionPane.ERROR_MESSAGE);
  24. return;
  25. }
  26. dispose();
  27. }
  28. private void actionCancel() {
  29. System.exit(0);
  30. }
  31. public String getType() {
  32. return (String) typeComboBox.getSelectedItem();
  33. }
  34. public String getServer() {
  35. return serverTextField.getText();
  36. }
  37. public String getUsername() {
  38. return usernameTextField.getText();
  39. }
  40. public String getPassword() {
  41. return new String(passwordField.getPassword());
  42. }
  43. public String getSmtpServer() {
  44. return smtpServerTextField.getText();
  45. }
  46. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  47. private void initComponents() {
  48. connectPanel = new javax.swing.JPanel();
  49. typeLabel = new javax.swing.JLabel();
  50. typeComboBox = new javax.swing.JComboBox();
  51. serverLabel = new javax.swing.JLabel();
  52. serverTextField = new javax.swing.JTextField();
  53. usernameLabel = new javax.swing.JLabel();
  54. usernameTextField = new javax.swing.JTextField();
  55. passwordLabel = new javax.swing.JLabel();
  56. smtpServerLabel = new javax.swing.JLabel();
  57. smtpServerTextField = new javax.swing.JTextField();
  58. passwordField = new javax.swing.JPasswordField();
  59. connectButton = new javax.swing.JButton();
  60. cancelButton = new javax.swing.JButton();
  61. setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
  62. connectPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Установка соединения"));
  63. typeLabel.setText("Тип протокола:");
  64. typeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "pop3" }));
  65. serverLabel.setText("Сервер:");
  66. usernameLabel.setText("Имя пользователя:");
  67. passwordLabel.setText("Пароль:");
  68. smtpServerLabel.setText("SMTP сервер:");
  69. passwordField.setText("jPasswordField1");
  70. javax.swing.GroupLayout connectPanelLayout = new javax.swing.GroupLayout(connectPanel);
  71. connectPanel.setLayout(connectPanelLayout);
  72. connectPanelLayout.setHorizontalGroup(
  73. connectPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  74. .addGroup(connectPanelLayout.createSequentialGroup()
  75. .addGroup(connectPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  76. .addGroup(connectPanelLayout.createSequentialGroup()
  77. .addGroup(connectPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
  78. .addComponent(passwordLabel)
  79. .addComponent(usernameLabel)
  80. .addComponent(smtpServerLabel))
  81. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
  82. .addComponent(serverLabel)
  83. .addGroup(connectPanelLayout.createSequentialGroup()
  84. .addComponent(typeLabel)
  85. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
  86. .addGroup(connectPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  87. .addComponent(typeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  88. .addComponent(serverTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
  89. .addComponent(smtpServerTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
  90. .addComponent(usernameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE)
  91. .addComponent(passwordField, javax.swing.GroupLayout.DEFAULT_SIZE, 150, Short.MAX_VALUE))
  92. .addContainerGap())
  93. );
  94. connectPanelLayout.setVerticalGroup(
  95. connectPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  96. .addGroup(connectPanelLayout.createSequentialGroup()
  97. .addGroup(connectPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  98. .addComponent(typeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  99. .addComponent(typeLabel))
  100. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  101. .addGroup(connectPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  102. .addComponent(serverTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  103. .addComponent(serverLabel))
  104. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  105. .addGroup(connectPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  106. .addComponent(usernameLabel)
  107. .addComponent(usernameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  108. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  109. .addGroup(connectPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  110. .addComponent(passwordLabel)
  111. .addComponent(passwordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
  112. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  113. .addGroup(connectPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  114. .addComponent(smtpServerTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  115. .addComponent(smtpServerLabel)))
  116. );
  117. connectButton.setText("OK");
  118. connectButton.addMouseListener(new java.awt.event.MouseAdapter() {
  119. public void mouseClicked(java.awt.event.MouseEvent evt) {
  120. connectButtonMouseClicked(evt);
  121. }
  122. });
  123. cancelButton.setText("Отмена");
  124. cancelButton.addMouseListener(new java.awt.event.MouseAdapter() {
  125. public void mouseClicked(java.awt.event.MouseEvent evt) {
  126. cancelButtonMouseClicked(evt);
  127. }
  128. });
  129. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  130. getContentPane().setLayout(layout);
  131. layout.setHorizontalGroup(
  132. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  133. .addComponent(connectPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  134. .addGroup(layout.createSequentialGroup()
  135. .addGap(38, 38, 38)
  136. .addComponent(connectButton, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
  137. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  138. .addComponent(cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
  139. .addContainerGap(53, Short.MAX_VALUE))
  140. );
  141. layout.setVerticalGroup(
  142. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  143. .addGroup(layout.createSequentialGroup()
  144. .addComponent(connectPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  145. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  146. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  147. .addComponent(connectButton)
  148. .addComponent(cancelButton))
  149. .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  150. );
  151. pack();
  152. }// </editor-fold>
  153. private void connectButtonMouseClicked(java.awt.event.MouseEvent evt) {
  154. actionConnect();
  155. }
  156. private void cancelButtonMouseClicked(java.awt.event.MouseEvent evt) {
  157. actionCancel();
  158. }
  159. // Variables declaration - do not modify
  160. private javax.swing.JButton cancelButton;
  161. private javax.swing.JButton connectButton;
  162. private javax.swing.JPanel connectPanel;
  163. private javax.swing.JPasswordField passwordField;
  164. private javax.swing.JLabel passwordLabel;
  165. private javax.swing.JLabel serverLabel;
  166. private javax.swing.JTextField serverTextField;
  167. private javax.swing.JLabel smtpServerLabel;
  168. private javax.swing.JTextField smtpServerTextField;
  169. private javax.swing.JComboBox typeComboBox;
  170. private javax.swing.JLabel typeLabel;
  171. private javax.swing.JLabel usernameLabel;
  172. private javax.swing.JTextField usernameTextField;
  173. // End of variables declaration
  174. }
Заранее огромное спасибо!

Решение задачи: «Ошибка написание интерфейса для mail client»

textual
Листинг программы
  1. return typeComboBox.getSelectedItem().toString()

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

6   голосов , оценка 3.667 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы