如何从另一个框架调用组件
嗨,我有两个以相同方式创建的框架:
public class DateFilter extends JFrame {
private final JDateChooser dateChooser = new JDateChooser();
private final JDateChooser dateChooser_1 = new JDateChooser();
private final JComboBox comboBox = new JComboBox();
private final JButton filtruotiButton = new JButton();
public DateFilter() {
super();
setBounds(100, 100, 277, 167);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
try {
jbInit();
} catch (Throwable e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(null);
setTitle("Priemimo datos filtras");
setResizable(false);
getContentPane().add(dateChooser);
dateChooser.setBounds(70, 40, 117, 20);
getContentPane().add(dateChooser_1);
dateChooser_1.setBounds(70, 65, 117, 20);
dateChooser_1.setEnabled(false);
...
请告诉我如何将数据从一个框架获取到另一个框架 例如,如果我想使用按钮将日期从该框架的 dateChooser 放置到另一个框架的 textField
hi i have two frames created in the same way:
public class DateFilter extends JFrame {
private final JDateChooser dateChooser = new JDateChooser();
private final JDateChooser dateChooser_1 = new JDateChooser();
private final JComboBox comboBox = new JComboBox();
private final JButton filtruotiButton = new JButton();
public DateFilter() {
super();
setBounds(100, 100, 277, 167);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
try {
jbInit();
} catch (Throwable e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(null);
setTitle("Priemimo datos filtras");
setResizable(false);
getContentPane().add(dateChooser);
dateChooser.setBounds(70, 40, 117, 20);
getContentPane().add(dateChooser_1);
dateChooser_1.setBounds(70, 65, 117, 20);
dateChooser_1.setEnabled(false);
...
tell me plz someone how to get data from one to another frame
for example if i want to place date from this frame's dateChooser to another frame's textField using button
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将第一帧的实例传递给第二帧,然后在此实例上调用方法。
小示例代码:
因为我猜你是初学者,所以我用这个非常简单和基本的示例来回答。当然,更复杂的方法是使用 MVC 模式!
You will need to pass the instance of the first frame to the second and than call a method on this instance.
Little sample code:
Since I guessed that you are a beginner, I answered with this pretty simple and basic example. A more sophisticated way would be using the MVC pattern, of course!