我在我的项目中在 Mac 上的 netbeans 上创建了一个 jform,我通过拖放自动创建了他,`我放了三个按钮和一个 jtextarea。在项目的主体中,我创建了一个此 jform 类型的新对象。jform 出现,但 jtextarea 中的文本不出现。
netbeans 像这样自动创建 initcomponent:
private void initComponents() {
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton4 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("reply");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton2.setText("reply-all");
jButton3.setText("delete");
jButton4.setText("forward");
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 363, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton4)))
.addContainerGap(23, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2)
.addComponent(jButton3)
.addComponent(jButton4))
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 232, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(15, Short.MAX_VALUE))
);
pack();
}
我像这样创建构造函数:
public MailRead(Email a){
java.awt.EventQueue.invokeLater(() -> {
new MailRead().setVisible(true);
});
Date d=new Date();
this.a=a;
a=new Email("ffd", "edgvxsfz", "h6v4gtrwd","ujyhrstegfw", d,21334231);
initComponents();
//System.out.println("-----Email from : "+a.getMittente()+"-----"+"\n"+"-----Object : "+a.getObj()+"-----\n"+a.getEmail());
String text= "-----Email from : "+a.getMittente()+"-----"+"\n"+"-----Object : "+a.getObj()+"-----\n"+a.getEmail();
jTextArea1=new JTextArea(text);
}
电子邮件代码是这样的:
import java.io.Serializable;
import java.util.Date;
public class Email implements Serializable{
String mittente;
String destinatario;
String email;
Date dataInvio;
int id;
String obj;
boolean isnew;
public Email(String mittente, String destinatario,String obj, String email, Date dataInvio,int id) {
this.mittente = mittente;
this.destinatario = destinatario;
this.email = email;
this.dataInvio = dataInvio;
this.id=id;
this.obj=obj;
isnew=true;
}
public String getMittente() {
return mittente;
}
public void setMittente(String mittente) {
this.mittente = mittente;
}
public String getDestinatario() {
return destinatario;
}
public void setDestinatario(String destinatario) {
this.destinatario = destinatario;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getObj() {
return obj;
}
public void setObj(String obj) {
this.obj = obj;
}
public Date getDataInvio() {
return dataInvio;
}
public void setDataInvio(Date dataInvio) {
this.dataInvio = dataInvio;
}
public int getId() {
return id;
}
public boolean isIsnew() {
return isnew;
}
public void setIsnew(boolean isnew) {
this.isnew = isnew;
}
@Override
public String toString() {
return "Email{" + "mittente=" + mittente + ", destinatario=" + destinatario + ", email=" + email + ", dataInvio=" + dataInvio + ", id=" + id + '}';
}
在承包商中,我在实际代码中分配了值,我使用 MailRead 的参数如何解决在 jtextarea 中阅读电子邮件?