::::::更新::::::
我尝试更新我的 JFrame
以将 LinkedList 作为参数,它看起来像...
public userLogin(LinkedList<dataUser> ll) {
initComponents();
}
我的 main 现在用 ... 调用它
userLogin frame = new userLogin(userLL);
frame.setVisible(true);
仍然无法在我的 JFrame
中使用 LinkedList userLL
::::::结束更新::::::
这是我第一次使用 netbeans 和 GUI 构建器。我有一个 TaskManager
类用作我的主类。此类创建一些 LinkedList
并调用我的第一个 JFrame
GUI,如下所示:
public static void main(String[] args) {
LinkedList<dataUser> userLL = new LinkedList<dataUser>(); //creates a LL for userData
LinkedList<task> taskLL = new LinkedList<task>(); //creates a LL for taskData
LinkedList<task> progressLL = new LinkedList<task>(); //creates a LL for in progress tasks
LinkedList<task> completeLL = new LinkedList<task>(); //creates a LL for completed tasks
userLogin frame = new userLogin();
frame.setVisible(true);
但是,在我的 userLogin
中,我无法访问我创建的 userLL
。
这是我的提交按钮中的代码:
private void submitBActionPerformed(java.awt.event.ActionEvent evt) {
String user = jTextField1.getText();
String userPW = jTextField2.getText();
try {
//below userLL is not accessible because it can't be found.
dataUser.userDataSearch(userLL, userPW);
}
catch (Exception e) {
JOptionPane.showMessageDialog(this, "was not found", "error", JOptionPane.ERROR_MESSAGE);
return;
}
}
如代码中的注释所述,我无法运行该函数,因为我无权访问 userLL
(我在主程序中创建的 LinkedList
启动此 JFrame
)。
我是否必须将 LinkedList
作为参数传递到我的 JFrame
中才能使用它?我假设在 main 中声明它会允许访问,但它现在似乎是 main 本地的。
最佳答案
您必须像这样将 userLL
作为参数传递给您的 userLogin
类:
public class userLogin {
LinkedList<dataUser> userLL
public userLogin(List userLL){
this.userLL = userLL;
}
//.......
}
然后在您的主类中像这样实例化它:userLogin frame = new userLogin(userLL);
关于java - 如何从我的 Jframe 按钮调用访问 main 中的 LinkedList,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30368063/