从另一个类访问Java JFrame [英] Access Java JFrame from another class

查看:111
本文介绍了从另一个类访问Java JFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个创建JFrame的类.创建JFrame时,它具有一个开始按钮.单击开始"按钮时,它将运行两个线程,直到单击停止"按钮为止.这两个线程在另一个类文件中.从包含线程的类中,如何访问JFrame实例以更改显示的值?

I have a class that creates a JFrame. When the JFrame is created it has a start button. When the start button is clicked, it runs two threads until the stop button is clicked. The two threads are in another class file. From the class that contains the threads, how can I access the JFrame instance in order to change value that are displayed?

推荐答案

要访问另一个类中的私有实例,我认为您应该使用agetter. 示例:

To have access to a private instance within another class, I think you should use agetter. Example:

//JFrame declaration
private JFrame frame;
//Getter
public JFrame getFrame() {
    return frame;
}

这篇关于从另一个类访问Java JFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆