java - 如何在单独的 GUI 中显示函数的结果?
问题描述
因此,使用 WindowBuilder 和 eclipse,我制作了某些功能,可以读取文本文件并显示某些数据 - 我想将此结果链接到我在单独的类中制作的 JFrame
这些是每个的代码:
这是我的公开课adminAccounts:
File inputFile = new File("UserAccounts.txt");
Scanner fileScanner = new Scanner(inputFile);
String s="admin";
int i;
while (fileScanner.hasNextLine())
{
String line = fileScanner.nextLine();
String[] arr = line.split(",");
if(arr[6].contains(s))
{
//System.out.println(arr[1]);
}
这是我的 AdminUsers 类,它目前是一个带有标题的 JFrame,我想将 adminAccounts 的结果显示到 JFrame
private JPanel contentPane;
public static void AdminFrame() {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
AdminUsers frame = new AdminUsers();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public AdminUsers() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBackground(new Color(255, 255, 204));
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JLabel Header = new JLabel("Choose from the following Admin usernames:");
Header.setBounds(10, 11, 321, 14);
contentPane.add(Header);
JLabel result = new JLabel();
result.setBounds(184, 47, 46, 14);
contentPane.add(result);
}
请帮助,因为我是新手并且非常困惑!