java SWT 如何实现两个窗体之间的数据传递?

没有呢称了 2014-03-29 03:05:02
我用eclipse创建了两个窗体,想将窗体1里的text输入的帐号获取,然后在第二个窗口可以text_1可以调用到这个帐号,应该怎么做?小白第一次接触eclipse,希望大神来帮帮忙。谢谢


ackage 1;


import org.eclipse.swt.graphics.Rectangle;


public class huuh {


protected Shell shell;
private Text text;


/**
* Launch the application.
* @param args
*/
public static void main(String[] args) {
try {
huuh window = new huuh();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}


/**
* Open the window.
*/
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}


/**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
shell.setSize(450, 300);
shell.setText("SWT Application");

Label lblNewLabel = new Label(shell, SWT.NONE);
lblNewLabel.setBounds(36, 42, 102, 26);
lblNewLabel.setText("\u767B\u5F55");

text = new Text(shell, SWT.BORDER);
text.setBounds(180, 45, 181, 33);

}


}




第二个:
package 2;




import org.eclipse.swt.widgets.Display;


public class you {


protected Shell shell;
private Text text;



/**
* Launch the application.
* @param args
*/
public static void main(String[] args) {
try {
you window = new you();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}


/**
* Open the window.
*/
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}


/**
* Create contents of the window.
*/
protected void createContents() {
shell = new Shell();
shell.setSize(450, 300);
shell.setText("SWT Application");

text = new Text(shell, SWT.BORDER);
text.setBounds(117, 34, 200, 47);




}


}




怎么实现第一个text填写的内容成功获取传递给第二个里面的text,,
...全文
4054 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
霜之哀伤 2014-04-02
  • 打赏
  • 举报
回复
两个main函数,就是两个独立的程序,两个进程。 Java中进程间通信通常只有几种方案,socket,文件,数据库等
soyestrellafortuna 2014-03-29
  • 打赏
  • 举报
回复
2楼怎么了? 你的怎么会有两个main方法?独立的两个程序?一个应用只有一个入口的才对呀
没有呢称了 2014-03-29
  • 打赏
  • 举报
回复
引用 1 楼 soyestrellafortuna 的回复:
1.窗体增加属性字段,然后get获取 2.直接传参数过去
具体怎么实现啊,,怎么增加属性字段,,第一次做,真不知道,,,
soyestrellafortuna 2014-03-29
  • 打赏
  • 举报
回复
1.窗体增加属性字段,然后get获取 2.直接传参数过去

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧