Я создал графический интерфейс с использованием Netbeans, который попросил пользователя ввести содержимое в textfields
и textareas
. Когда я пытаюсь использовать его в других классах, текст, введенный в textfield
, не появляется, когда я использую метод getText
. Вместо этого текст, который появляется в textfield
, указанный с использованием опции редактирования текста в Netbeans, появляется всякий раз, когда используется метод getText
. Является ли проблема связана с каким-то упорядочением или порядком? Поскольку я верю, что текст из графического интерфейса, ссылается на то, что пользователь действительно вводит его.Проблема с текстовым полем Java Swing
public class GUI extends javax.swing.JFrame {
public GUI() {
initComponents();
}
public void Grow(){
initComponents();
}
/**
* 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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jTextField1 = new javax.swing.JTextField();
jPanel1 = new javax.swing.JPanel();
username = new javax.swing.JTextField();
UsernameLabel = new javax.swing.JLabel();
PasswordLabel = new javax.swing.JLabel();
subject = new javax.swing.JTextField();
SubjectLabel = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
message = new javax.swing.JTextArea();
jLabel1 = new javax.swing.JLabel();
salutation = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
sendbutton = new javax.swing.JButton();
password = new javax.swing.JPasswordField();
jTextField1.setText("jTextField1");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBackground(new java.awt.Color(204, 204, 255));
jPanel1.setBorder(new javax.swing.border.LineBorder(java.awt.SystemColor.controlDkShadow, 3, true));
username.setText("Enter your text here");
UsernameLabel.setFont(new java.awt.Font("Arial", 1, 13)); // NOI18N
UsernameLabel.setForeground(new java.awt.Color(255, 51, 51));
UsernameLabel.setText("Username");
PasswordLabel.setFont(new java.awt.Font("Arial", 1, 13)); // NOI18N
PasswordLabel.setForeground(new java.awt.Color(255, 51, 51));
PasswordLabel.setText("Password");
subject.setText("Enter your text here");
subject.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
subject.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
subjectActionPerformed(evt);
}
});
SubjectLabel.setFont(new java.awt.Font("Arial", 1, 13)); // NOI18N
SubjectLabel.setForeground(new java.awt.Color(255, 51, 51));
SubjectLabel.setText("Subject");
message.setColumns(20);
message.setRows(5);
message.setText("Enter your text here");
jScrollPane1.setViewportView(message);
jLabel1.setFont(new java.awt.Font("Arial", 1, 13)); // NOI18N
jLabel1.setForeground(new java.awt.Color(255, 51, 51));
jLabel1.setText("Message");
salutation.setText("Enter your text here");
jLabel2.setFont(new java.awt.Font("Arial", 1, 13)); // NOI18N
jLabel2.setForeground(new java.awt.Color(255, 51, 51));
jLabel2.setText("Salutation");
sendbutton.setForeground(new java.awt.Color(255, 51, 51));
sendbutton.setText("Send");
sendbutton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sendbuttonActionPerformed(evt);
}
});
password.setText("Enter your text here");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel2)
.addComponent(SubjectLabel))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(salutation)
.addComponent(subject))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(UsernameLabel, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(PasswordLabel))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(username)
.addComponent(password))
.addGap(47, 47, 47))
.addComponent(jLabel1)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(sendbutton)))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(username, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(UsernameLabel)
.addComponent(subject, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(SubjectLabel))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(PasswordLabel)
.addComponent(salutation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2)
.addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 20, Short.MAX_VALUE)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(11, 11, 11)
.addComponent(sendbutton))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
private void subjectActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void sendbuttonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
MMMMain object = new MMMMain();
object.MassMail();
}
/**
* @param args the command line arguments
*/
public void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(GUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new GUI().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JLabel PasswordLabel;
private javax.swing.JLabel SubjectLabel;
private javax.swing.JLabel UsernameLabel;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextField jTextField1;
public javax.swing.JTextArea message;
public javax.swing.JPasswordField password;
public javax.swing.JTextField salutation;
public javax.swing.JButton sendbutton;
public javax.swing.JTextField subject;
public javax.swing.JTextField username;
// End of variables declaration
}
У вас, похоже, мало что нужно для _no_ кода релевантного программирования событий, и этот _does_ кажется проблемой, вызванной событиями. Все, что я вижу, это пустой 'actionPerformed' и другой' actionPerformed' с экземпляром класса, который не существует в вашем коде. Как мы должны вывести все из этого? Это уже достаточно плохо, ваш вопрос неясен. Вам необходимо ** ручной код ** [** минимальный, полный, испытанный и читаемый пример **] (http://stackoverflow.com/help/mcve), чтобы мы могли его протестировать и лучше объяснять твоя проблема. –