package comm.x10;
/**
*
* @author hcdevel
*/
import javax.swing.*;
import java.util.Enumeration;
import javax.comm.CommPortIdentifier;
import java.awt.*;
import java.awt.event.*;
public class x10JavaComm extends JFrame{
private Enumeration portList;
private CommPortIdentifier portID;
private String portStr = "Serial Ports Found: \n";
private JComboBox portjcb;
private final JLabel empty = null;
private static String portName = new String();
public x10JavaComm() {
this.setTitle("Select Comm Port");
this.setSize(300,300);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
portjcb = new JComboBox();
JButton selectPortBtn = new JButton("Select Port");
JTextArea portListJTA = new JTextArea();
JPanel mainPanel = new JPanel(new GridLayout(2,2));
add(mainPanel);
portList = CommPortIdentifier.getPortIdentifiers();
while(portList.hasMoreElements()){
portID = (CommPortIdentifier)portList.nextElement();
if(portID.getPortType() == CommPortIdentifier.PORT_SERIAL){
portStr += portID.getName() + "\n";
portjcb.addItem(portID.getName());
}
}
portListJTA.setText(portStr);
selectPortBtn.addActionListener(new PortSelect());
mainPanel.add(portListJTA);
mainPanel.add(portjcb);
mainPanel.add(empty);
mainPanel.add(selectPortBtn);
this.setVisible(true);
}
public class PortSelect implements ActionListener{
public void actionPerformed(ActionEvent e){
Object selectedPort = portjcb.getSelectedItem();
portName = selectedPort.toString();
}
}
public String getPort(){
return portName;
}
}