public void init(){
  subPanel.setLayout(new BorderLayout());
  topic=new JComboBox();
  topic.setEditable(true);
  topic.setMaximumSize(MQTTFrame.TEXT_FIELD_DIMENSION);
  topic.setMaximumRowCount(5);
  receivedTopic=new JTextField(15);
  receivedTopic.setMaximumSize(MQTTFrame.TEXT_FIELD_DIMENSION);
  receivedTopic.setEditable(false);
  receivedTopic.setBackground(Color.lightGray);
  receivedTopic.setMargin(MQTTFrame.TEXT_MARGINS);
  receivedQoS=new JTextField(3);
  receivedQoS.setMaximumSize(MQTTFrame.DROP_DOWN_DIMENSION);
  receivedQoS.setEditable(false);
  receivedQoS.setBackground(Color.lightGray);
  receivedQoS.setMargin(MQTTFrame.TEXT_MARGINS);
  receivedRetain=new JCheckBox();
  receivedRetain.setMaximumSize(MQTTFrame.DROP_DOWN_DIMENSION);
  receivedRetain.setEnabled(false);
  receivedRetain.setMargin(MQTTFrame.TEXT_MARGINS);
  receivedRetain.setSelected(false);
  receivedData=new JTextArea(3,30);
  receivedData.setBorder(new BevelBorder(BevelBorder.LOWERED));
  receivedData.setEditable(false);
  receivedData.setBackground(Color.lightGray);
  receivedData.setMargin(MQTTFrame.TEXT_MARGINS);
  qosList=new JComboBox(qos);
  qosList.setSelectedIndex(0);
  qosList.setMaximumSize(MQTTFrame.DROP_DOWN_DIMENSION);
  qosList.setToolTipText("The QoS at which publications will be delivered");
  JPanel sendTopicPanel=new JPanel();
  sendTopicPanel.setLayout(new BoxLayout(sendTopicPanel,BoxLayout.X_AXIS));
  sendTopicPanel.add(new JLabel(" Subscribe Topic:"));
  sendTopicPanel.add(topic);
  sendTopicPanel.add(new JLabel(" Request QoS:"));
  sendTopicPanel.add(qosList);
  sendTopicPanel.add(new JLabel("  "));
  JPanel rcvdTopicPanel=new JPanel();
  rcvdTopicPanel.setLayout(new BoxLayout(rcvdTopicPanel,BoxLayout.X_AXIS));
  rcvdTopicPanel.add(new JLabel(" Received Topic:"));
  rcvdTopicPanel.add(receivedTopic);
  rcvdTopicPanel.add(new JLabel(" QoS:"));
  rcvdTopicPanel.add(receivedQoS);
  rcvdTopicPanel.add(new JLabel(" Retained:"));
  rcvdTopicPanel.add(receivedRetain);
  JPanel titleAndTopics=new JPanel();
  titleAndTopics.setLayout(new GridLayout(3,1));
  subLabel=new JLabel(PANEL_TITLE + " - text display");
  Font f=subLabel.getFont();
  subLabel.setFont(new Font(f.getName(),Font.BOLD,f.getSize() + 1));
  titleAndTopics.add(subLabel);
  titleAndTopics.add(sendTopicPanel);
  titleAndTopics.add(rcvdTopicPanel);
  JPanel subButtonsLayout=new JPanel();
  JPanel buttons=new JPanel();
  buttons.setLayout(new GridLayout(4,1));
  hexDisplay=false;
  hexButton=new JButton("Hex");
  hexButton.addActionListener(this);
  fileButton=new JButton("Save...");
  fileButton.setEnabled(true);
  fileButton.addActionListener(this);
  subButton=new JButton("Subscribe");
  subButton.setEnabled(false);
  subButton.addActionListener(this);
  unsubButton=new JButton("Unsubscribe");
  unsubButton.setEnabled(false);
  unsubButton.addActionListener(this);
  buttons.add(subButton);
  buttons.add(unsubButton);
  buttons.add(fileButton);
  buttons.add(hexButton);
  subButtonsLayout.add(buttons);
  subPanel.add(titleAndTopics,BorderLayout.NORTH);
  subPanel.add(new JScrollPane(receivedData),BorderLayout.CENTER);
  subPanel.add(subButtonsLayout,BorderLayout.EAST);
}

public void init ( ) { subPanel . setLayout ( new BorderLayout ( ) ) ; topic = new JComboBox ( ) ; topic . setEditable ( true ) ; topic . setMaximumSize ( MQTTFrame . TEXT_FIELD_DIMENSION ) ; topic . setMaximumRowCount ( 5 ) ; receivedTopic = new JTextField ( 15 ) ; receivedTopic . setMaximumSize ( MQTTFrame . TEXT_FIELD_DIMENSION ) ; receivedTopic . setEditable ( false ) ; receivedTopic . setBackground ( Color . lightGray ) ; receivedTopic . setMargin ( MQTTFrame . TEXT_MARGINS ) ; receivedQoS = new JTextField ( 3 ) ; receivedQoS . setMaximumSize ( MQTTFrame . DROP_DOWN_DIMENSION ) ; receivedQoS . setEditable ( false ) ; receivedQoS . setBackground ( Color . lightGray ) ; receivedQoS . setMargin ( MQTTFrame . TEXT_MARGINS ) ; receivedRetain = new JCheckBox ( ) ; receivedRetain . setMaximumSize ( MQTTFrame . DROP_DOWN_DIMENSION ) ; receivedRetain . setEnabled ( false ) ; receivedRetain . setMargin ( MQTTFrame . TEXT_MARGINS ) ; receivedRetain . setSelected ( false ) ; receivedData = new JTextArea ( 3 , 30 ) ; receivedData . setBorder ( new BevelBorder ( BevelBorder . LOWERED ) ) ; receivedData . setEditable ( false ) ; receivedData . setBackground ( Color . lightGray ) ; receivedData . setMargin ( MQTTFrame . TEXT_MARGINS ) ; qosList = new JComboBox ( qos ) ; qosList . setSelectedIndex ( 0 ) ; qosList . setMaximumSize ( MQTTFrame . DROP_DOWN_DIMENSION ) ; qosList . setToolTipText ( "The QoS at which publications will be delivered" ) ; JPanel sendTopicPanel = new JPanel ( ) ; sendTopicPanel . setLayout ( new BoxLayout ( sendTopicPanel , BoxLayout . X_AXIS ) ) ; sendTopicPanel . add ( new JLabel ( " Subscribe Topic:" ) ) ; sendTopicPanel . add ( topic ) ; sendTopicPanel . add ( new JLabel ( " Request QoS:" ) ) ; sendTopicPanel . add ( qosList ) ; sendTopicPanel . add ( new JLabel ( "  " ) ) ; JPanel rcvdTopicPanel = new JPanel ( ) ; rcvdTopicPanel . setLayout ( new BoxLayout ( rcvdTopicPanel , BoxLayout . X_AXIS ) ) ; rcvdTopicPanel . add ( new JLabel ( " Received Topic:" ) ) ; rcvdTopicPanel . add ( receivedTopic ) ; rcvdTopicPanel . add ( new JLabel ( " QoS:" ) ) ; rcvdTopicPanel . add ( receivedQoS ) ; rcvdTopicPanel . add ( new JLabel ( " Retained:" ) ) ; rcvdTopicPanel . add ( receivedRetain ) ; JPanel titleAndTopics = new JPanel ( ) ; titleAndTopics . setLayout ( new GridLayout ( 3 , 1 ) ) ; subLabel = new JLabel ( PANEL_TITLE + " - text display" ) ; Font f = subLabel . getFont ( ) ; subLabel . setFont ( new Font ( f . getName ( ) , Font . BOLD , f . getSize ( ) + 1 ) ) ; titleAndTopics . add ( subLabel ) ; titleAndTopics . add ( sendTopicPanel ) ; titleAndTopics . add ( rcvdTopicPanel ) ; JPanel subButtonsLayout = new JPanel ( ) ; JPanel buttons = new JPanel ( ) ; buttons . setLayout ( new GridLayout ( 4 , 1 ) ) ; hexDisplay = false ; hexButton = new JButton ( "Hex" ) ; hexButton . addActionListener ( this ) ; fileButton = new JButton ( "Save..." ) ; fileButton . setEnabled ( true ) ; fileButton . addActionListener ( this ) ; subButton = new JButton ( "Subscribe" ) ; subButton . setEnabled ( false ) ; subButton . addActionListener ( this ) ; unsubButton = new JButton ( "Unsubscribe" ) ; unsubButton . setEnabled ( false ) ; unsubButton . addActionListener ( this ) ; buttons . add ( subButton ) ; buttons . add ( unsubButton ) ; buttons . add ( fileButton ) ; buttons . add ( hexButton ) ; subButtonsLayout . add ( buttons ) ; subPanel . add ( titleAndTopics , BorderLayout . NORTH ) ; subPanel . add ( new JScrollPane ( receivedData ) , BorderLayout . CENTER ) ; subPanel . add ( subButtonsLayout , BorderLayout . EAST ) ; }
the init method builds all the required components and adds them to the subscription panel . different layout managers are used throughout to ensure that the components resize correctly as the window resizes .
