如何在单独的GUI中显示函数的结果?

huangapple 未分类评论44阅读模式
英文:

How to display the results of a function in a seperate GUI?

问题

以下是您要翻译的部分:

所以,使用WindowBuilder和eclipse,我已经实现了一个功能,它可以读取一个文本文件并显示特定数据 - 我想将这个结果链接到我在另一个类中创建的JFrame窗口。

这是我的public类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的结果显示在这个窗口中:

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();
            }
        }
    });
}

/**
 * 创建窗口。
 */
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("从以下管理员用户名中选择:");
    Header.setBounds(10, 11, 321, 14);
    contentPane.add(Header);

    JLabel result = new JLabel();
    result.setBounds(184, 47, 46, 14);
    contentPane.add(result);
}

希望对您有所帮助,如果有任何问题,请随时提出。

英文:

So, using WindowBuilder and eclipse, I have made certain functionality which reads a text file and displays certain data - I want to link this result to a JFrame that I have made in a separate class

These are the codes for each:

This is my public class 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]);
}

And this is my class AdminUsers which currently is a JFrame with a header and I would like to display the results of adminAccounts into the 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);
}

Please help as I am new to this and very confused!

huangapple
  • 本文由 发表于 2020年4月7日 02:55:54
  • 转载请务必保留本文链接:https://java.coder-hub.com/61066986.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定