testclient.java
来自「关于 RFID 读写器的相关内容」· Java 代码 · 共 456 行 · 第 1/2 页
JAVA
456 行
cmdCreatorPanel.add(targetField, cc.xywh(3,5,2,1));
cmdCreatorPanel.add(parameterPanel, cc.xywh(1,7,6,1));
return cmdCreatorPanel;
}
/**
* Creates the panel with the "Send" and "Close" button
* @return
*/
private JPanel getCommandPanel() {
JPanel cmdPane = new JPanel();
sendButton = new JButton();
sendButton.setAction(new SendAction(this));
closeButton = new JButton();
closeButton.setAction(new DisconnectAction(this));
cmdPane.add(sendButton);
cmdPane.add(closeButton);
return cmdPane;
}
public void setMainPanelEnabled(boolean status) {
inText.setEnabled(status);
outText.setEnabled(status);
sendButton.setEnabled(status);
closeButton.setEnabled(status);
}
/**
* Sets the enabled status of all UI components within the
* "connect panel".
*
* @param status Status wheter to enable the components or not.
*/
public void setConnectPanelEnabled(boolean status) {
connectButton.setEnabled(status);
transportLabel.setEnabled(status);
tcpConnectionButton.setEnabled(status);
httpConnectionButton.setEnabled(status);
formatLabel.setEnabled(status);
xmlFormatButton.setEnabled(status);
textFormatButton.setEnabled(status);
hostField.setEnabled(status);
portField.setEnabled(status);
hostLabel.setEnabled(status);
portLabel.setEnabled(status);
}
/**
* Creates the top-most panel with all the connection related
* suff.
*
* @return
*/
private JPanel getConnectPanel() {
JPanel connectPanel = new JPanel();
connectPanel.setBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder("Connection"),
BorderFactory.createEmptyBorder(5,5,5,5)),
connectPanel.getBorder()));
FormLayout layout = new FormLayout(
"pref, 4dlu, pref , left:pref:grow, 4dlu,pref,4dlu, pref, 4dlu, pref", // columns
"pref, 2dlu, pref, 1dlu, pref"); // rows
connectPanel.setLayout(layout);
hostField = new JTextField("localhost");
portField = new JTextField("8000");
hostLabel = new JLabel("Host: ");
portLabel = new JLabel("Port: ");
formatLabel = new JLabel("Format:");
transportLabel = new JLabel("Transport:");
connectButton = new JButton();
connectButton.setAction(new ConnectAction(this));
ButtonGroup connectionGroup = new ButtonGroup();
tcpConnectionButton = new JRadioButton();
tcpConnectionButton.setAction(new SetTransportProtocolTcp(this));
httpConnectionButton = new JRadioButton();
httpConnectionButton.setAction(new SetTransportProtocolHttp(this));
httpConnectionButton.setSelected(true);
handshake.setTransportProtocol(Handshake.HTTP);
ButtonGroup formatGroup = new ButtonGroup();
xmlFormatButton = new JRadioButton();;
xmlFormatButton.setAction(new SetMessageFormatXML(this));
textFormatButton = new JRadioButton();
textFormatButton.setAction(new SetMessageFormatText(this));
xmlFormatButton.setSelected(true);
handshake.setMessageFormat(Handshake.FORMAT_XML);
/*//Shows the EPC logo
ImageIcon epcLogo = createImageIcon("resources/epc_logo.gif");
JLabel logoLabel = new JLabel();
logoLabel.setIcon(epcLogo);
*/
CellConstraints cc = new CellConstraints();
connectionGroup.add(tcpConnectionButton);
connectionGroup.add(httpConnectionButton);
formatGroup.add(xmlFormatButton);
formatGroup.add(textFormatButton);
connectPanel.add(hostLabel,cc.xy(1,1));
connectPanel.add(hostField,cc.xywh(3,1,3,1));
connectPanel.add(portLabel,cc.xy(6,1));
connectPanel.add(portField,cc.xy(8,1));
connectPanel.add(transportLabel,cc.xy(1,3));
connectPanel.add(tcpConnectionButton,cc.xy(3,3));
connectPanel.add(httpConnectionButton,cc.xy(4,3));
connectPanel.add(formatLabel,cc.xy(1,5));
connectPanel.add(xmlFormatButton,cc.xy(3,5));
connectPanel.add(textFormatButton,cc.xy(4,5));
connectPanel.add(connectButton,cc.xy(10,1));
// connectPanel.add(logoLabel, cc.xywh(5,3,6,3));
return connectPanel;
}
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);
//Create and set up the window.
TestClient client = new TestClient();
client.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
client.initialize();
//Display the window.
client.pack();
client.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
public Handshake getHandshake() {
return handshake;
}
/**
* Prints the input into the client and shows it in
* the input text field.
* @param line
*/
public void printInput(String line) {
inText.append(line);
inText.setCaretPosition(inText.getText().length());
}
/**
* @return Returns the conn.
*/
public ClientConnection getConn() {
return conn;
}
/**
* @param conn The conn to set.
*/
public void setConn(ClientConnection conn) {
this.conn = conn;
}
public String getMessage() {
return outText.getText();
}
public int getPort() {
return Integer.parseInt(portField.getText());
}
public String getHost() {
return hostField.getText();
}
public void setCommandModel(DefaultComboBoxModel model) {
cmdComboBox.setModel(model);
}
public Parameter[] getParameters() {
return parameterPanel.getParameterListModel().getParameters();
}
public String getRpObject() {
return (String)objComboBox.getSelectedItem();
}
public String getRpTarget() {
return targetField.getText();
}
public String getRpCommand() {
return (String)cmdComboBox.getSelectedItem();
}
public void setOutText(String txt) {
outText.setText(txt);
}
/**
* Returns an ImageIcon, or null if the path was invalid.
* @param path
* @return
*/
protected static ImageIcon createImageIcon(String path) {
java.net.URL imgURL = TestClient.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?