无法刷新jtable一次以上

时间:2016-10-05 12:30:25

标签: java swing jtable jbutton

在我的jFrame中,我创建了一个包含患者的表格。列表和一个允许刷新操作表的按钮。当我点击第一次刷新按钮时,列表将显示在表格中。然而,当我第二次按下它时,它不再工作,表格也无法刷新。 对这个问题有什么想法吗? 这是刷新按钮的代码:

  public class Interface extends javax.swing.JFrame{
         private void RefreshActionPerformed(java.awt.event.ActionEvent evt) {                                        
        DefaultTableModel model = (DefaultTableModel)worklisttable.getModel();

                int rowCount = model.getRowCount();
                for (int i = rowCount - 1; i >= 0; i--) {
                    model.removeRow(i);
                }
               model.fireTableDataChanged();
                GetMwl_3.main(args);
            }   
     public static void main(String args[]) {
    ......
    }
    }

GetMwl_3.java:允许从服务器检索患者列表

 public class GetMwl_3  {
 private String[] args;
    /**
     * @param args
     */
    public static void main(String[] args/*,String aet, String host, Integer port*/) {
        new GetMwl_3(/*aet,host,port*/);
    }

    private static final int[] RETURN_KEYS = {
        Tag.AccessionNumber,
        Tag.ReferringPhysicianName,
        Tag.PatientName,
        Tag.PatientID,
        Tag.PatientBirthDate,
        Tag.PatientSex,
        Tag.PatientWeight,
        Tag.MedicalAlerts,
        Tag.Allergies,
        Tag.PregnancyStatus,
        Tag.StudyInstanceUID,
        Tag.RequestingPhysician,
        Tag.RequestingService,
        Tag.RequestedProcedureDescription,
        Tag.AdmissionID,
        Tag.SpecialNeeds,
        Tag.CurrentPatientLocation,
        Tag.PatientState,
        Tag.RequestedProcedureID,
        Tag.RequestedProcedurePriority,
        Tag.PatientTransportArrangements,
        Tag.PlacerOrderNumberImagingServiceRequest,
        Tag.FillerOrderNumberImagingServiceRequest,
        Tag.ConfidentialityConstraintOnPatientDataDescription,
    };

    private static final int[] SPS_RETURN_KEYS = {
        Tag.Modality,
        Tag.RequestedContrastAgent,
        Tag.ScheduledStationAETitle,
        Tag.ScheduledProcedureStepStartDate,
        Tag.ScheduledProcedureStepStartTime,
        Tag.ScheduledPerformingPhysicianName,
        Tag.ScheduledProcedureStepDescription,
        Tag.ScheduledProcedureStepID,
        Tag.ScheduledStationName,
        Tag.ScheduledProcedureStepLocation,
        Tag.PreMedication,
        Tag.ScheduledProcedureStepStatus
    };

    private static final String[] LE_TS = {
        UID.ExplicitVRLittleEndian, 
        UID.ImplicitVRLittleEndian };

    private static final byte[] EXT_NEG_INFO_FUZZY_MATCHING = { 1, 1, 1 };

    private Device device;
    private final NetworkApplicationEntity remoteAE = new NetworkApplicationEntity();
    private final NetworkConnection remoteConn = new NetworkConnection();
     private final NetworkApplicationEntity ae = new NetworkApplicationEntity();
     private final NetworkConnection conn = new NetworkConnection();
     private final DicomObject keys = new BasicDicomObject();
     private final DicomObject spsKeys = new BasicDicomObject();
     private Association assoc;
     private int priority = 0;
     private int cancelAfter = Integer.MAX_VALUE;//ÐœÐ°ÐºÑ ÐºÐ¾Ð»Ð¸Ñ‡ÐµÑтво Ñтрок

     private boolean fuzzySemanticPersonNameMatching;
    private Component emptyLabel;

    public GetMwl_3(/*String aet, String host, Integer port*/) {
        String name = "DCMMWL";
        device = new Device(name);
        NewThreadExecutor executor = new NewThreadExecutor(name);
        remoteAE.setInstalled(true);
        remoteAE.setAssociationAcceptor(true);
        remoteAE.setNetworkConnection(new NetworkConnection[] { remoteConn });

        device.setNetworkApplicationEntity(ae);
        device.setNetworkConnection(conn);
        ae.setNetworkConnection(conn);
        ae.setAssociationInitiator(true);
        ae.setAETitle(name);
        for (int i = 0; i < RETURN_KEYS.length; i++) {
            keys.putNull(RETURN_KEYS[i], null);
        }        
        keys.putNestedDicomObject(Tag.RequestedProcedureCodeSequence,
                new BasicDicomObject());
        keys.putNestedDicomObject(Tag.ScheduledProcedureStepSequence, spsKeys);
        for (int i = 0; i < SPS_RETURN_KEYS.length; i++) {
            spsKeys.putNull(SPS_RETURN_KEYS[i], null);
        }
        spsKeys.putNestedDicomObject(Tag.ScheduledProtocolCodeSequence,
                new BasicDicomObject());

        /////////
        Properties pacs = new Properties();
    InputStream file = null;
         File thefile = new File("C:\\properties\\save.properties");
            if (thefile.exists()){

    try {

        file = new FileInputStream("C:\\properties\\save.properties");

        // load a properties file
        pacs.load(file);

        // get the property value and print it out
         remoteAE.setAETitle( pacs.getProperty("aethl7"));
                 remoteConn.setHostname(pacs.getProperty("hosthl7"));
                 remoteConn.setPort(Integer.parseInt(pacs.getProperty("porthl7")));



    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        if (file != null) {
            try {
                file.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
addSpsMatchingKey(Tag.ScheduledProcedureStepStartDate,"20131030");

        setTransferSyntax(LE_TS);

        long t1 = System.currentTimeMillis();
        try {
            assoc = ae.connect(remoteAE, executor);

        } catch (Exception e) {
          //  System.err.println("ERROR: Failed to establish association:");
            //e.printStackTrace(System.err);
            //jLabel7.setText("ERROR: Failed to establish association");
             javax.swing.JOptionPane.showMessageDialog(null,"Liste des patients ne peut pas être retirée");      
            //System.exit(2);
        }

        long t2 = System.currentTimeMillis();
        System.out.println("Connected to " + remoteAE + " in "
                + ((t2 - t1) / 1000F) + "s");

         //jLabel6.setText("Connected to " + remoteAE + " in "
           //    + ((t2 - t1) / 1000F) + "s");
        try {
            List<DicomObject> result = query();
            long t3 = System.currentTimeMillis();

            System.out.println("Received " + result.size()
                    + " matching entries in " + ((t3 - t2) / 1000F) + "s");



            for(DicomObject dcm : result) {

               worklist.main(args, 
                       dcm.getString(Tag.PatientID),
                       dcm.getString(Tag.AccessionNumber),
                       dcm.getString(Tag.PatientName),
                       dcm.getString(Tag.PatientBirthDate),
                       dcm.getString(Tag.PatientSex),
                       dcm.getString(Tag.ReferringPhysicianName)
                       );
            }
            javax.swing.JOptionPane.showMessageDialog(null,"Liste des patients retirée avec succée"); 
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            assoc.release(true);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println("Released connection to " + remoteAE);
    }
        }
    public void setTransferSyntax(String[] ts) {
        TransferCapability tc = new TransferCapability(
                UID.ModalityWorklistInformationModelFIND, ts,
                TransferCapability.SCU);
        if (fuzzySemanticPersonNameMatching)
            tc.setExtInfo(EXT_NEG_INFO_FUZZY_MATCHING);
        ae.setTransferCapability(new TransferCapability[]{tc});
    }

        public void addSpsMatchingKey(int tag, String value) {
        spsKeys.putString(tag, null, value);
    }

    public List<DicomObject> query() throws IOException, InterruptedException {
        TransferCapability tc = assoc.getTransferCapabilityAsSCU(
                UID.ModalityWorklistInformationModelFIND);
        if (tc == null) {
            throw new NoPresentationContextException(
                    "Modality Worklist not supported by "
                    + remoteAE.getAETitle());
        }
        DimseRSP rsp = assoc.cfind(UID.ModalityWorklistInformationModelFIND,
                priority, keys, tc.getTransferSyntax()[0], cancelAfter);
        List<DicomObject> result = new ArrayList<DicomObject>();
        while (rsp.next()) {
            DicomObject cmd = rsp.getCommand();
            if (CommandUtils.isPending(cmd)) {
                DicomObject data = rsp.getDataset();
                result.add(data);
            }
        }
        return result;

    }



}

worklist.java:

 public class worklist extends Interface{
     public worklist(){

    }
    public static void main(String[] args,
                            String PatientID,                           
                            String accessingNumber,
                            String PatientName,
                            String BirthDate,
                            String sex,
                            String referringPhysician

    ) {

    DefaultTableModel modelw=(DefaultTableModel)worklisttable.getModel();
        modelw.setColumnIdentifiers(new String[]{"ID Patient"," Nom Patient","Date de Naissance","Sexe"});
        DefaultTableCellRenderer centerRenderer= new DefaultTableCellRenderer();
             centerRenderer.setHorizontalAlignment(JLabel.CENTER);
             worklisttable.getColumnModel().getColumn(0).setCellRenderer(centerRenderer);
             for (int j = 0 ; j< worklisttable.getColumnCount(); j++) 
                {
                 worklisttable.getColumnModel().getColumn(j).setCellRenderer(centerRenderer);
                }
        row=new Object[4];
        row[0]=PatientID;
        row[1]=PatientName;
        row[2]=BirthDate;
        row[3]=sex;
        modelw.addRow(row);

    }

}

0 个答案:

没有答案