frm1中有txtName,frm2有一個button的值為"dream"
點擊frm2的按鈕,frm1中的txtName的值為“dream”
怎樣實現??请根据这2个代码文件帮帮忙实现功能
frm1代码:
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Button;public class frm1 { private Shell sShell = null;
private Text txtName = null;
private Label label = null;
private Button button = null;
frm1 g=new frm1();
public static void main(String[] args) {
Display display = Display.getDefault();
frm1 thisClass = new frm1();
thisClass.createSShell();
thisClass.sShell.open(); while (!thisClass.sShell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
private void createSShell() {
sShell = new Shell();
sShell.setText("Shell");
sShell.setSize(new Point(300, 200));
sShell.setLayout(null);
txtName = new Text(sShell, SWT.BORDER);
txtName.setBounds(new Rectangle(78, 29, 116, 24));
label = new Label(sShell, SWT.NONE);
label.setBounds(new Rectangle(21, 29, 51, 25));
label.setFont(new Font(Display.getDefault(), "\u5b8b\u4f53", 11, SWT.NORMAL));
label.setText("姓名:");
button = new Button(sShell, SWT.NONE);
button.setBounds(new Rectangle(187, 112, 68, 29));
button.setText("OPEN");
button.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
frm2 a=new frm2();
a.open();
}
});
}}frm2代码:
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;public class frm2 { private Shell sShell = null;
private Button button = null;
private void createSShell() {
sShell = new Shell();
sShell.setText("Shell");
sShell.setSize(new Point(300, 200));
sShell.setLayout(null);
button = new Button(sShell, SWT.NONE);
button.setBounds(new Rectangle(53, 41, 79, 34));
button.setText("dream");
button.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
}
});
} public void open() {
Display display = Display.getDefault();
frm2 thisClass = new frm2();
thisClass.createSShell();
thisClass.sShell.open(); while (!thisClass.sShell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}}
點擊frm2的按鈕,frm1中的txtName的值為“dream”
怎樣實現??请根据这2个代码文件帮帮忙实现功能
frm1代码:
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Button;public class frm1 { private Shell sShell = null;
private Text txtName = null;
private Label label = null;
private Button button = null;
frm1 g=new frm1();
public static void main(String[] args) {
Display display = Display.getDefault();
frm1 thisClass = new frm1();
thisClass.createSShell();
thisClass.sShell.open(); while (!thisClass.sShell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
private void createSShell() {
sShell = new Shell();
sShell.setText("Shell");
sShell.setSize(new Point(300, 200));
sShell.setLayout(null);
txtName = new Text(sShell, SWT.BORDER);
txtName.setBounds(new Rectangle(78, 29, 116, 24));
label = new Label(sShell, SWT.NONE);
label.setBounds(new Rectangle(21, 29, 51, 25));
label.setFont(new Font(Display.getDefault(), "\u5b8b\u4f53", 11, SWT.NORMAL));
label.setText("姓名:");
button = new Button(sShell, SWT.NONE);
button.setBounds(new Rectangle(187, 112, 68, 29));
button.setText("OPEN");
button.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
frm2 a=new frm2();
a.open();
}
});
}}frm2代码:
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;public class frm2 { private Shell sShell = null;
private Button button = null;
private void createSShell() {
sShell = new Shell();
sShell.setText("Shell");
sShell.setSize(new Point(300, 200));
sShell.setLayout(null);
button = new Button(sShell, SWT.NONE);
button.setBounds(new Rectangle(53, 41, 79, 34));
button.setText("dream");
button.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
}
});
} public void open() {
Display display = Display.getDefault();
frm2 thisClass = new frm2();
thisClass.createSShell();
thisClass.sShell.open(); while (!thisClass.sShell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}}
解决方案 »
- 求java记事本源码 非常急 谁快给谁分!
- 360与QQ
- 这段程序怎么运行不了?
- 关于Log4j 的使用 问题!工程引用的包也会往我的日志里写东西
- "restruture".substring(2,3)=?
- MySQL在spring中的一个奇怪的问题
- 请问有汉字得到数字的问题
- 求教高手,JDBC驱动问题:Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);一直报
- 【一个JAVA程序的运行问题!!!】
- 新手求解
- 一个session会占用服务器多大内存? 我是说Tomcat服务器。
- 类型问题short和int的转换!!!!
你先好好看看swt编程基础。
package csdn;import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.widgets.Button;public class frm1 { private Shell sShell = null; private Text txtName = null; private Label label = null; private Button button = null; // frm1 g = new frm1(); public static void main(String[] args) {
Display display = Display.getDefault();
frm1 thisClass = new frm1();
thisClass.createSShell(display);
// thisClass.sShell.open(); while (!thisClass.sShell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
} private void createSShell(Display display) {
sShell = new Shell(display);
sShell.setText("Shell");
sShell.setSize(new Point(300, 200));
sShell.setLayout(null);
txtName = new Text(sShell, SWT.BORDER);
txtName.setBounds(new Rectangle(78, 29, 116, 24));
label = new Label(sShell, SWT.NONE);
label.setBounds(new Rectangle(21, 29, 51, 25));
label.setFont(new Font(Display.getDefault(), "\u5b8b\u4f53", 11,
SWT.NORMAL));
label.setText("姓名:");
button = new Button(sShell, SWT.NONE);
button.setBounds(new Rectangle(187, 112, 68, 29));
button.setText("OPEN");
button
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
frm2 a = new frm2(sShell);
txtName.setText(a.open());
}
});
sShell.pack();
Rectangle rectParent = Display.getDefault().getBounds();
Rectangle rectShell = sShell.getBounds();
sShell.setBounds(rectParent.x + (rectParent.width - rectShell.width)
/ 2, rectParent.y + (rectParent.height - rectShell.height) / 2,
rectShell.width, rectShell.height); sShell.open(); }}
package csdn;import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;public class frm2 extends Dialog { private Shell sShell = null; private Button button = null; private String btnText = null; public frm2(Shell shell) {
super(shell, SWT.DIALOG_TRIM);
} private void createSShell() {
// sShell = new Shell(display);
sShell.setText("Shell");
sShell.setSize(new Point(300, 200));
sShell.setLayout(null);
button = new Button(sShell, SWT.NONE);
button.setBounds(new Rectangle(53, 41, 79, 34));
button.setText("dream");
button
.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
public void widgetSelected(
org.eclipse.swt.events.SelectionEvent e) {
btnText = button.getText();
sShell.dispose();
}
});
} public String open() {
sShell = new Shell(getParent(), SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);
createSShell();
sShell.pack();
sShell.open();
Display display = sShell.getDisplay();
while (!sShell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
return btnText;
}}
稍后给大家打分.