Ich habe zwei public class, wie kann ich miteinander kommunizieren?
Class Grundriss beinhaltet die Oberflaeche und alle Objekte .
Class GuiClient beinhaltet prozess von nachricht verschicken und empfangen (von anderem System).
Ich habe eigentlich vor, ein paar Objekte's eigentschaften zu aendern so bald ich
eine Nachricht von anderem System bekommen habe. In diesem Fall moechte ich setVisible zu true machen, wenn ich die Nachricht von einem Agenten ueber ihre Lokation bekommen habe.
Was ich gerne machen moechte, wenn ich eine Nachricht bekomme, dann werde ich z.B schwBeateOP2.setVisible(true) machen
Ich weiss man koennte effektiver machen, aber im Moment fehlt mir echt die Zeit :-(
vielen Dank fuer Euere Hilfe !!
Class Grundriss beinhaltet die Oberflaeche und alle Objekte .
Class GuiClient beinhaltet prozess von nachricht verschicken und empfangen (von anderem System).
Ich habe eigentlich vor, ein paar Objekte's eigentschaften zu aendern so bald ich
eine Nachricht von anderem System bekommen habe. In diesem Fall moechte ich setVisible zu true machen, wenn ich die Nachricht von einem Agenten ueber ihre Lokation bekommen habe.
Code:
public class Grundriss extends org.eclipse.swt.widgets.Composite {
...
public Label schwBeateWaiting;
public Label schwAnitaWaiting;
public Label drAlbrechtWaiting;
public Label drFrankeWaiting;
public Label patMuellerWaiting;
public Label patMeierWaiting;
...
{
SWTResourceManager.registerResourceUser(this);
}
public Grundriss(Composite parent, int style) {
super(parent, style);
initGUI();
}
/**
* Initializes the GUI.
*/
private void initGUI() {
try {
this.setLocation(0,0);
this.setSize(800, 600);
this.setBackground(SWTResourceManager.getColor(0, 0, 160));
FormLayout thisLayout = new FormLayout();
this.setLayout(thisLayout);
{
klinikLayoutCanvas = new Canvas(this, SWT.NONE);
FormData KlinikLayoutLData = new FormData();
KlinikLayoutLData.width = 511;
KlinikLayoutLData.height = 322;
KlinikLayoutLData.left = new FormAttachment(0, 1000, 14);
KlinikLayoutLData.top = new FormAttachment(0, 1000, 28);
klinikLayoutCanvas.setLayoutData(KlinikLayoutLData);
klinikLayoutCanvas.setBackground(SWTResourceManager.getColor(128, 128, 255));
{
waiting = new Composite(klinikLayoutCanvas, SWT.NONE);
GridLayout OperationRaum2Layout = new GridLayout();
OperationRaum2Layout.makeColumnsEqualWidth = true;
OperationRaum2Layout.marginLeft = 300;
OperationRaum2Layout.marginTop = 300;
waiting.layout();
waiting.setBounds(11, 26, 103, 277);
waiting.setBackground(SWTResourceManager.getColor(255, 255, 128));
{
patMeierWaiting = new Label(waiting, SWT.NONE);
patMeierWaiting.setText("Pat. Meier");
patMeierWaiting.setImage(SWTResourceManager.getImage("images/patMeiersmall.gif"));
patMeierWaiting.setBounds(63, 7, 37, 61);
patMeierWaiting.setBackground(SWTResourceManager.getColor(255, 255, 128));
patMeierWaiting.setVisible(false);
}
{
patMuellerWaiting = new Label(waiting, SWT.NONE);
patMuellerWaiting.setText("Pat. Mueller");
patMuellerWaiting.setImage(SWTResourceManager.getImage("images/patMuellersmall.gif"));
patMuellerWaiting.setBounds(3, 5, 44, 61);
patMuellerWaiting.setBackground(SWTResourceManager.getColor(255, 255, 128));
patMuellerWaiting.setVisible(false);
}
{
drFrankeWaiting = new Label(waiting, SWT.NONE);
drFrankeWaiting.setText("Dr. Franke");
drFrankeWaiting.setImage(SWTResourceManager.getImage("images/DrFrankesmall.gif"));
drFrankeWaiting.setBounds(6, 195, 39, 74);
drFrankeWaiting.setBackground(SWTResourceManager.getColor(255, 255, 128));
drFrankeWaiting.setVisible(false);
}
{
drAlbrechtWaiting = new Label(waiting, SWT.NONE);
drAlbrechtWaiting.setText("Dr. Albrecht");
drAlbrechtWaiting.setImage(SWTResourceManager.getImage("images/DrAlbrechtsmall.gif"));
drAlbrechtWaiting.setBounds(49, 200, 41, 64);
drAlbrechtWaiting.setBackground(SWTResourceManager.getColor(255, 255, 128));
drAlbrechtWaiting.setVisible(false);
}
{
schwAnitaWaiting = new Label(waiting, SWT.NONE);
schwAnitaWaiting.setText("Schw. Anita");
schwAnitaWaiting.setImage(SWTResourceManager.getImage("images/schwAnitasmall.gif"));
schwAnitaWaiting.setBounds(11, 91, 38, 64);
schwAnitaWaiting.setBackground(SWTResourceManager.getColor(255, 255, 128));
schwAnitaWaiting.setVisible(false);
}
{
schwBeateWaiting = new Label(waiting, SWT.NONE);
schwBeateWaiting.setText("Schw. Beate");
schwBeateWaiting.setImage(SWTResourceManager.getImage("images/schwBeatesmall.gif"));
schwBeateWaiting.setBounds(61, 95, 32, 61);
schwBeateWaiting.setBackground(SWTResourceManager.getColor(255, 255, 128));
schwBeateWaiting.setVisible(false);
}
}
{
operation2 = new Composite(klinikLayoutCanvas, SWT.NONE);
operation2.setBounds(134, 26, 180, 155);
operation2.layout();
operation2.setBackground(SWTResourceManager.getColor(255, 255, 128));
{
schwAnitaOP2 = new Label(operation2, SWT.NONE);
schwAnitaOP2.setText("Schw. Anita");
schwAnitaOP2.setImage(SWTResourceManager
.getImage("images/schwAnitasmall.gif"));
schwAnitaOP2.setBounds(56, 84, 28, 63);
schwAnitaOP2.setBackground(SWTResourceManager.getColor(255, 255, 128));
schwAnitaOP2.setVisible(false);
}
{
schwBeateOP2 = new Label(operation2, SWT.NONE);
schwBeateOP2.setText("Schw. Beate");
schwBeateOP2.setImage(SWTResourceManager.getImage("images/schwBeatesmall.gif"));
schwBeateOP2.setBounds(15, 85, 28, 62);
schwBeateOP2.setBackground(SWTResourceManager.getColor(255, 255, 128));
schwBeateOP2.setVisible(false);
}
{
drFrankeOP2 = new Label(operation2, SWT.NONE);
drFrankeOP2.setText("Dr. Franke");
drFrankeOP2.setImage(SWTResourceManager.getImage("images/DrFrankesmall.gif"));
drFrankeOP2.setBounds(50, 6, 44, 62);
drFrankeOP2.setBackground(SWTResourceManager.getColor(255, 255, 128));
drFrankeOP2.setVisible(false);
}
{
drAlbrechtOP2 = new Label(operation2, SWT.NONE);
drAlbrechtOP2.setText("Dr. Albrecht");
drAlbrechtOP2.setImage(SWTResourceManager.getImage("images/DrAlbrechtsmall.gif"));
drAlbrechtOP2.setBounds(3, 4, 45, 64);
drAlbrechtOP2.setBackground(SWTResourceManager.getColor(255, 255, 128));
drAlbrechtOP2.setVisible(false);
}
{
patMeierOP2 = new Label(operation2, SWT.NONE);
patMeierOP2.setText("Pat. Meier");
patMeierOP2.setImage(SWTResourceManager.getImage("images/patOP.gif"));
patMeierOP2.setBounds(108, 49, 60, 30);
patMeierOP2.setBackground(SWTResourceManager.getColor(255, 255, 128));
patMeierOP2.setVisible(false);
}
{
patMuellerOP2 = new Label(operation2, SWT.NONE);
patMuellerOP2.setText("Pat. Mueller ");
patMuellerOP2.setImage(SWTResourceManager.getImage("images/patOP.gif"));
patMuellerOP2.setBounds(109, 84, 60, 28);
patMuellerOP2.setVisible(false);
}
}
}
{
menu1 = new Menu(getShell(), SWT.BAR);
getShell().setMenuBar(menu1);
{
fileMenuItem = new MenuItem(menu1, SWT.CASCADE);
fileMenuItem.setText("File");
{
fileMenu = new Menu(fileMenuItem);
{
exitMenuItem = new MenuItem(fileMenu, SWT.CASCADE);
exitMenuItem.setText("Exit");
exitMenuItem.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent event) {
shell.close();
}
});
}
fileMenuItem.setMenu(fileMenu);
}
}
{
helpMenuItem = new MenuItem(menu1, SWT.CASCADE);
helpMenuItem.setText("Help");
{
helpMenu = new Menu(helpMenuItem);
{
aboutMenuItem = new MenuItem(helpMenu, SWT.CASCADE);
aboutMenuItem.setText("About");
}
helpMenuItem.setMenu(helpMenu);
}
}
}
this.layout();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Auto-generated main method to display this
* org.eclipse.swt.widgets.Composite inside a new Shell.
*/
public static void main(String[] args) {
Display display = Display.getDefault();
Shell shell = new Shell(display);
Grundriss inst = new Grundriss(shell, SWT.NULL);
Point size = inst.getSize();
shell.setLayout(new FillLayout());
shell.layout();
shell.setText("Emika 2.0");
if(size.x == 0 && size.y == 0) {
inst.pack();
shell.pack();
} else {
Rectangle shellBounds = shell.computeTrim(0, 0, size.x, size.y);
shell.setSize(shellBounds.width, shellBounds.height);
}
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}
public Label getPatMeierWaiting() {
return patMeierWaiting;
}
public Label getPatMuellerWaiting() {
return patMuellerWaiting;
}
public Label getDrFrankeWaiting() {
return drFrankeWaiting;
}
public Label getDrAlbrechtWaiting() {
return drAlbrechtWaiting;
}
public Label getSchwAnitaWaiting() {
return schwAnitaWaiting;
}
public Label getSchwBeateWaiting() {
return schwBeateWaiting;
}
}
Was ich gerne machen moechte, wenn ich eine Nachricht bekomme, dann werde ich z.B schwBeateOP2.setVisible(true) machen
Code:
public class GuiClient implements MessageListener {
private final String SUBJ_GUI_CLIENT = "guiClient";
private final String PERF_REQUEST = "request";
private final String PERF_REPLY = "reply";
public static String[] agent ;
public static String[] role ;
private int agentNumber;
protected static ClientCommunication comm;
public GuiClient()
{
// create the LSTS connection
Properties clientProperties = new Properties();
try { clientProperties.load(new FileInputStream("config/client.properties"));
} catch (FileNotFoundException e1)
{ e1.printStackTrace();
} catch (IOException e1)
{ e1.printStackTrace();
}
// set the client identifier for the RFID reader
clientProperties.setProperty("client.identifier", "GuiClient");
comm = ClientCommunicationFactory.create(clientProperties);
try { comm.connect();
comm.addMessageListener(this);
System.out.println("Testclient connected.");
} catch (Exception e)
{ throw new SecurityException("connection to LSTS failed: " + e.getMessage());
}
}
public void onMessage(ClientCommunication arg0, long arg1)
{ // retrieve pending message
IReceivedMessage message = (IReceivedMessage)arg0.getMessage(arg1);
if (message.getPerformative().equals(PERF_REPLY+"-agents"))
{ agentNumber= (message.getFromContent("count").hashCode());
if (agentNumber != 0 )
{
agent = new String[agentNumber];
role = new String[agentNumber];
for (int i=0; i<agentNumber; ++i)
{
agent[i]= (String) message.getFromContent("agent"+i);
role[i] = (String) message.getFromContent("role"+i);
}
}
}
// received a location message
if (message.getPerformative().equals(PERF_REPLY+"-location"))
{ if (message.getFromContent("location") != null )
{ String location = (String) message.getFromContent("location");
String sender = (String)message.getSender().getName();
// HIER moechte ich gerne die Eigentschaften von public label in class Grundriss aendern //----------------------------------------------------------------------------------------------------------------------------
if sender ="Schw. Beate"
case location ="waiting"
{ schwBeateWaiting.setVisible(true);}
case location ="OP2"
{ schwBeateOP2.setVisible(true);}
und so on ....
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
}
}
// received a schedule message
if (message.getPerformative().equals(PERF_REPLY+"-schedule"))
{ if (message.getFromContent("count")!= null)
{ System.out.println("number of schedule:"+ message.getFromContent("count"));
int n= (message.getFromContent("count").hashCode() );
for (int i=0; i<n; ++i)
{ System.out.println("Schedule Reply for: " +
message.getSender().getName() + "'s"
+ "name: " + message.getFromContent("name"+i)
+ " Location: " + message.getFromContent("location"+i)
+ " start: " + message.getFromContent("start"+i)
+ " end: " + message.getFromContent("end"+i)
+ " Resource 1 : " + message.getFromContent
("resources"+i+".0")
+ " Resource 2 : " + message.getFromContent
("resources"+i+".1"));
}
}
}
}
Ich weiss man koennte effektiver machen, aber im Moment fehlt mir echt die Zeit :-(
vielen Dank fuer Euere Hilfe !!