@Override public void actionPerformed(ActionEvent event) { Object source = event.getSource(); if (source.equals(connectBtn)) { String port = (String) comPortCombobox.getSelectedItem(); try { comPortUtil.openCOMPort(port); if (comPortUtil.isPortOpened()) { connectBtn.setEnabled(false); } } catch (ComPortException e) { e.printStackTrace(); } } }
/** Add the dropdown to select which comport to use. */ private void addComPortDropdown() { String[] ports = new String[ComPortUtil.getComPorts().size()]; ComPortUtil.getComPorts().toArray(ports); comPortCombobox = new JComboBox<>(ports); topMenu.add(comPortCombobox); }