【发布时间】:2014-01-15 02:46:26
【问题描述】:
我有一个 JPanel 表单,其中包含一个 JList 和一些 JButton。 JPanel 看起来像这样
当我单击“添加列表”按钮时,会显示一个单独的 JFrame 表单。 JFrame 表单将如下所示
当点击JFrame上的添加按钮时,我需要将JTextfield(命名为List Name)的值添加到上一个JPanel上的JList中。我想知道如何将值从 JFrame 传递到 JPanel?任何建议将不胜感激。
这是 JPanel 表单的代码(使用 Designer GUI)
package multimediaproject;
public class musicPlayerPanel extends javax.swing.JPanel {
public musicPlayerPanel() {
initComponents();
}
private void initComponents() {
//...here is the generated code by using designer GUI
}
// Variables declaration - do not modify
//..generated code
// End of variables declaration
}
这是JFrame表单的代码(使用Designer GUI)
package multimediaproject;
public class addListFrame extends javax.swing.JFrame {
public addListFrame() {
initComponents();
this.setLocation(515, 0);
setVisible(true);
}
private void initComponents() {
//..here is the generated code by using Designer GUI
}
private void addBtnActionPerformed(java.awt.event.ActionEvent evt){
//some validation
if(...)
{
//validation
}
else
{
//IF VALUE IS CORRECT, ADD the List Name JTextfield value to the JList on the previous JPanel
errorMessage.setText("");
}
}
public static void main(String args[]) {
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new addListFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
//....generated code
// End of variables declaration
}
【问题讨论】:
-
"如有任何建议,我们将不胜感激。" 1) 为了尽快获得更好的帮助,请发帖 SSCCE。 2)请不要忘记添加“?”提问!有些人在页面中搜索“?”如果“问题”中不存在,则直接转到下一个(实际)问题。 3) Java 类以大写字母开头。用它。 4)不要扩展框架/面板等,我想那是“你的 IDE 说话”。