客户端SocketOpreation类从服务器接到数据,这里假设接到的数据是字符串aa,在SocketOpreation里怎么样显示在用户界面类managerclient的控件table_1上?managerclient类:import org.eclipse.swt.*;
import com.swtdesigner.SWTResourceManager;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.widgets.*;public class managerclient
{
protected Shell shell;
public Text t;
public Table table_1;
public managerclient(){
shell = new Shell();
}
public static void main(String[] args) {
try {
managerclient window = new managerclient();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()){
if (!display.readAndDispatch()) {
display.sleep();
}
}
} protected void createContents(){
shell.setSize(695, 468);
shell.setText("欢迎使用");
Menu menu = new Menu(shell, SWT.BAR);
shell.setMenuBar(menu); MenuItem menuItem_s3 = new MenuItem(menu, SWT.SEPARATOR);
MenuItem check = new MenuItem(menu, SWT.CASCADE);
check.setText("审核");
Menu menu_4 = new Menu(check);
check.setMenu(menu_4);
MenuItem menuItem_4 = new MenuItem(menu_4, SWT.NONE);
menuItem_4.setText("证书审核");
MenuItem menuItem_s4 = new MenuItem(menu, SWT.SEPARATOR);
final Composite composite_2 = new Composite(shell, SWT.NONE);
composite_2.setBackground(SWTResourceManager.getColor(SWT.COLOR_GRAY));
composite_2.setBounds(0, 0, 687, 414); CCombo combo_2 = new CCombo(composite_2, SWT.BORDER);
combo_2.setItems(new String[] {"按录入日期检索:"});
combo_2.setBounds(43, 26, 119, 21);
Button button_2_1 = new Button(composite_2, SWT.NONE);
button_2_1.setBounds(522, 26, 119, 23);
button_2_1.setText("查询待审核证书");
t = new Text(composite_2,SWT.NONE);
t.setBounds(300, 26, 119, 23);
table_1 = new Table(composite_2, SWT.BORDER |SWT.MULTI| SWT.FULL_SELECTION);
table_1.setBounds(0, 69, 687, 283);
table_1.setHeaderVisible(true);
table_1.setLinesVisible(false);
TableItem item = new TableItem(table_1,SWT.NONE);
String[] tableHeader = {"证书序列号","申请者信息","国家","省份","城市","组织","单元","Email","角色","证书录入日期"};
for(int i=0;i<tableHeader.length;i++)
{
TableColumn tableColumn = new TableColumn(table_1, SWT.CENTER);
tableColumn.setWidth(110);
tableColumn.setText(tableHeader[i]);
}
composite_2.setVisible(true);
}
}
SocketOpreation类:import org.eclipse.swt.widgets.Display;public class SocketOperation extends Thread
{
public enum backtypes{bapp,bcheck};
public managerclient ml = new managerclient();
public SocketOperation()
{
start();
}
public void run()
{
System.out.println("客户端开始接收服务器的返回数据:");
String aa = "0,张国荣,中国,香港,香港,演艺圈,TVB,[email protected],一号牛人,2009-1-1";
String appstr = backtypes.bcheck + ";" + aa + ";";
String[] backmessage = appstr.split(";");
//根据返回数据的标示信息做不同的处理
if(backmessage[0].equals(backtypes.bapp.toString()))
{
backappmessage(backmessage[1]);
}else if(backmessage[0].equals(backtypes.bcheck.toString()))
{
backcheckmessage(backmessage[1]);
}else
{
}
} public void backappmessage(String str)
{
System.out.println("这里有也信息要显示在managerclient的控件上");
}
public void backcheckmessage(String str)
{
//怎么样才能把str的值显示在managerclient的控件table_1上
System.out.println("得到了审核的信息,准备显示!");
System.out.println(str);
final String _str = str;
Display.getDefault().asyncExec((Runnable) ml);
ml.t.setText(_str);
}
public static void main(String[] args)
{
SocketOperation so = new SocketOperation();
}
}
import com.swtdesigner.SWTResourceManager;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.widgets.*;public class managerclient
{
protected Shell shell;
public Text t;
public Table table_1;
public managerclient(){
shell = new Shell();
}
public static void main(String[] args) {
try {
managerclient window = new managerclient();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}
public void open() {
Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()){
if (!display.readAndDispatch()) {
display.sleep();
}
}
} protected void createContents(){
shell.setSize(695, 468);
shell.setText("欢迎使用");
Menu menu = new Menu(shell, SWT.BAR);
shell.setMenuBar(menu); MenuItem menuItem_s3 = new MenuItem(menu, SWT.SEPARATOR);
MenuItem check = new MenuItem(menu, SWT.CASCADE);
check.setText("审核");
Menu menu_4 = new Menu(check);
check.setMenu(menu_4);
MenuItem menuItem_4 = new MenuItem(menu_4, SWT.NONE);
menuItem_4.setText("证书审核");
MenuItem menuItem_s4 = new MenuItem(menu, SWT.SEPARATOR);
final Composite composite_2 = new Composite(shell, SWT.NONE);
composite_2.setBackground(SWTResourceManager.getColor(SWT.COLOR_GRAY));
composite_2.setBounds(0, 0, 687, 414); CCombo combo_2 = new CCombo(composite_2, SWT.BORDER);
combo_2.setItems(new String[] {"按录入日期检索:"});
combo_2.setBounds(43, 26, 119, 21);
Button button_2_1 = new Button(composite_2, SWT.NONE);
button_2_1.setBounds(522, 26, 119, 23);
button_2_1.setText("查询待审核证书");
t = new Text(composite_2,SWT.NONE);
t.setBounds(300, 26, 119, 23);
table_1 = new Table(composite_2, SWT.BORDER |SWT.MULTI| SWT.FULL_SELECTION);
table_1.setBounds(0, 69, 687, 283);
table_1.setHeaderVisible(true);
table_1.setLinesVisible(false);
TableItem item = new TableItem(table_1,SWT.NONE);
String[] tableHeader = {"证书序列号","申请者信息","国家","省份","城市","组织","单元","Email","角色","证书录入日期"};
for(int i=0;i<tableHeader.length;i++)
{
TableColumn tableColumn = new TableColumn(table_1, SWT.CENTER);
tableColumn.setWidth(110);
tableColumn.setText(tableHeader[i]);
}
composite_2.setVisible(true);
}
}
SocketOpreation类:import org.eclipse.swt.widgets.Display;public class SocketOperation extends Thread
{
public enum backtypes{bapp,bcheck};
public managerclient ml = new managerclient();
public SocketOperation()
{
start();
}
public void run()
{
System.out.println("客户端开始接收服务器的返回数据:");
String aa = "0,张国荣,中国,香港,香港,演艺圈,TVB,[email protected],一号牛人,2009-1-1";
String appstr = backtypes.bcheck + ";" + aa + ";";
String[] backmessage = appstr.split(";");
//根据返回数据的标示信息做不同的处理
if(backmessage[0].equals(backtypes.bapp.toString()))
{
backappmessage(backmessage[1]);
}else if(backmessage[0].equals(backtypes.bcheck.toString()))
{
backcheckmessage(backmessage[1]);
}else
{
}
} public void backappmessage(String str)
{
System.out.println("这里有也信息要显示在managerclient的控件上");
}
public void backcheckmessage(String str)
{
//怎么样才能把str的值显示在managerclient的控件table_1上
System.out.println("得到了审核的信息,准备显示!");
System.out.println(str);
final String _str = str;
Display.getDefault().asyncExec((Runnable) ml);
ml.t.setText(_str);
}
public static void main(String[] args)
{
SocketOperation so = new SocketOperation();
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货