Daten zuweisen an JFrame in KlasseA, aus der KlasseB
-
Hallo, ich habe ein kleines Problemchen.
Ich habe meinen Frame in der Klasse deviceInformationFrame, jetzt möchte ich Daten aus der Klasse GUIManager dem Frame in der Klasse deviceInformationFrame zuweisen. Was mir Schwierigkeiten bereitet ist die if Bedingung in der RefreshDeviceInfo_2 funktion der Klasse GUIManager.class deviceInformationFrame...{ . . . private void diReadButton_2ActionPerformed(java.awt.event.ActionEvent evt) { int deviceID = 0; DataType.Rd4DeviceInfoWindow = true; // dressup Firmware value for display try { deviceID = Integer.parseInt( diDevIdSpinner_2.getModel().getValue().toString() ); GUIManager.RefreshDeviceInfo_2( deviceID, devInformationFrame ); /* new MessageBoxOK( "Read OK", "Device ID " + deviceID + " @ " + serialMaster.params.getPortName(), MessageBox.IconType.INFO, this.getFrame() ); */ // ReadCompleteMsgBox.setVisible(true); // ReadCompleteMsgBox.ReadSuccessfulFrame bx = new ReadCompleteMsgBox.ReadSuccessfulFrame(); // bx.setVisible(true); // ReadSuccessfulFrame.setVisible(true); CstMsgBox box = new CstMsgBox(devInformationFrame,true); box.displayCstMsgBox("Read successful, device ID" + deviceID); } catch (ModbusException ex) { /* new MessageBoxOK( "Read Failed", "Device ID " + deviceID + " @ " + serialMaster.params.getPortName() //+ "\n" + ex.getMessage() + "\nPlease try again.", MessageBox.IconType.EXCLAMATION, null );*/ CstMsgBox box = new CstMsgBox(devInformationFrame,true); box.displayCstMsgBox("Read failed, device ID" + deviceID); } catch (NullPointerException ex) { /*new MessageBoxOK( "Read Failed", "No device is detected", MessageBox.IconType.CRITICAL, null );*/ CstMsgBox box = new CstMsgBox(devInformationFrame,true); box.displayCstMsgBox("Read failed, no device is detected !"); } . . . } }
hier die Klasse GUIManager,
class GUIManager ...{ . . static void RefreshDeviceInfo_2( int deviceID, JFrame frame ) throws ModbusException, NullPointerException { AddrTbl.DeviceInfo deviceInfo; DataType.Type type; int highword = 0; //GUI is object of calss OsensaVieView and serialMaster is OsensaViewViews variable Register[] deviceInfoRegs = GUI.serialMaster.getDeviceInfo( deviceID ); if ( DEBUG.Modbus ) FTXModbus.printRegs( deviceInfoRegs ); // traverse through enum values in sequence for ( int i = AddrTbl.DeviceInfo._START.getCode() - AddrTbl.StartBase, regIdx = 0; i <= AddrTbl.DeviceInfo._END.getCode() - AddrTbl.EndBase; i++, regIdx++ ) { deviceInfo = AddrTbl.DeviceInfo.get( i ); type = deviceInfo.getType(); if ( type == DataType.Type.UNDEFINED ) { // this register has no association, skip it } else if ( type == DataType.Type.HIGHWORD ) { // buffer current register to be combine with the next one, the low word // make this the high word by shifting it to high word position highword = deviceInfoRegs[regIdx].toUnsignedShort() << 16; //highword = 0x0282 << 16; // test - passed } else if ( type == DataType.Type.SERIALNUM ) { // current word is the low word counterpart of previous high word // combine the current word with the high word int value = highword | deviceInfoRegs[regIdx].toUnsignedShort(); //int value = highword | 0x65DC; // test - passed if ( frame == devInfFrObject_2.devInformationFrame ) { RefreshComponent( ComponentRegistry.DeviceInfo4Rd_diFrame.get( deviceInfo ), type.toGUI( value ) ); } else { RefreshComponent( ComponentRegistry.DeviceInfo4Rd.get( deviceInfo ), type.toGUI( value ) ); } } else if ( type == DataType.Type.CHANCONFIG ) { if ( frame == devInfFrObject_2.devInformationFrame ) { RefreshComponent( ComponentRegistry.DeviceInfo4Rd_diFrame.get( deviceInfo ), type.toGUI( deviceInfoRegs[regIdx].toUnsignedShort() ) ); } else { RefreshComponent( ComponentRegistry.DeviceInfo4Rd.get( deviceInfo ), type.toGUI( deviceInfoRegs[regIdx].toUnsignedShort() ) ); } } else { // retrieve value according to DataType.Type and refresh associated component if ( frame == devInfFrObject_2.devInformationFrame ) { RefreshComponent( ComponentRegistry.DeviceInfo4Rd_diFrame.get( deviceInfo ), type.toGUI( deviceInfoRegs[regIdx].toUnsignedShort() ) ); } else { RefreshComponent( ComponentRegistry.DeviceInfo4Rd.get( deviceInfo ), type.toGUI( deviceInfoRegs[regIdx].toUnsignedShort() ) ); } } } } . . }
mit der if Bedingung meine ich, in der RefreshDeviceInfo_2 Funktion die Zeile
else if ( type == DataType.Type.SERIALNUM )[b] wird noch ausgeführt, aber die darauf folgende,
[b]if ( frame == devInfFrObject_2.devInformationFrame ), Bedingung nicht mehr, diese ist niemals wahr.Meine if Bedingung if( frame == devInfFrObject_2.devInformationFrame ) befindet sich in der GUIManager Klasse, und dafür muss ich doch ein Object der Klasse deviceInformationFrame kreieren um auf die Parameter und Funktionen der deviceInformationFrame Klasse zuzugreifen!?
Danke
-
printf sind,
frame,
javax.swing.JFrame[devInformationFrame,473,301,420x165,invalid,layout=java.awt.BorderLayout,title=OSENSAView FTX | Device Info,resizable,normal,defaultCloseOperation=HIDE_ON_CLOSE,rootPane=javax.swing.JRootPane[,8,30,404x127,invalid,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=, flags=16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
devInfFrObject_2.devInformationFrame,
javax.swing.JFrame[devInformationFrame,473,301,420x165,invalid,hidden,layout=java.awt.BorderLayout,title=OSENSAView FTX | Device Info,resizable,normal,defaultCloseOperation=HIDE_ON_CLOSE,rootPane=javax.swing.JRootPane[,0,0,0x0,invalid,layout=javax.swing.JRootPane$RootLayout,alignmentX=0.0,alignmentY=0.0,border=,flags =16777673,maximumSize=,minimumSize=,preferredSize=],rootPaneCheckingEnabled=true]
,
wieso sind die jetzt unterschiedlich!?