public void preInit() throws IOException, JSONException {
   if (new File(Constants.FILE_PATH).exists()) {
     String[] arr = CommonUtil.readConfigFile();
     if (arr.length > 0) {
       if (arr[0].equals("1")) {
         boolean deletedDevice = WSInvokes.isDeletedDevice(getMacAddress());
         if (deletedDevice) CommonUtil.DeleteDevice();
       }
     }
   }
 }
  public AddDeviceView() throws IOException, JSONException {
    super("Find My Device | Add  Device");

    preInit();
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    this.setResizable(false);
    setBounds(250, 115, 800, 550);
    JPanel panel = new JPanel();
    add(panel);

    URL url = getClass().getResource("/resources/logo.png");
    ImageIcon icon = new ImageIcon(url);
    setIconImage(icon.getImage());

    try {
      if (CommonUtil.isAddedDevice()) {
        placeMessage(panel);
      } else {
        placeComponents(panel);
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
    setVisible(true);

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);
    // Define and add two drop down menu to the menubar
    JMenu web = new JMenu("Web");
    JMenu helpMenu = new JMenu("Help");
    JMenu aboutMenu = new JMenu("about");
    JMenu dataMenu = new JMenu("Data");
    JMenu serverMenu = new JMenu("Server");
    JMenu logoutMenu = new JMenu("logout");

    menuBar.add(web);
    menuBar.add(helpMenu);
    menuBar.add(aboutMenu);
    menuBar.add(dataMenu);
    menuBar.add(serverMenu);
    menuBar.add(logoutMenu);

    // Create and add simple menu item to one of the drop down menu
    JMenuItem openAction = new JMenuItem("Open");
    JMenuItem exitAction = new JMenuItem("Exit");
    JMenuItem logoutAction = new JMenuItem("logout");
    JMenuItem logsAction = new JMenuItem("show logs");
    JMenuItem connectAction = new JMenuItem("connect");

    web.add(openAction);
    web.addSeparator();
    web.add(exitAction);
    logoutMenu.add(logoutAction);
    dataMenu.add(logsAction);
    serverMenu.add(connectAction);

    exitAction.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            System.exit(0);
          }
        });
    connectAction.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            dispose();
            new ConnectToServerView().setVisible(true);
          }
        });
    logsAction.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            try {
              if ((new File(Constants.LOG_FILE)).exists()) {

                Process p =
                    Runtime.getRuntime()
                        .exec("rundll32 url.dll,FileProtocolHandler " + Constants.LOG_FILE);
                p.waitFor();
              }
            } catch (Exception ex) {
              ex.printStackTrace();
            }
          }
        });
    logoutAction.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            try {
              SuperUtil.logout();
              new LoginView();
              dispose();
            } catch (IOException e) {
              e.printStackTrace();
            }
          }
        });
    openAction.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            try {
              String url = "http://" + hostname + ":8080/fmd/";
              java.awt.Desktop.getDesktop().browse(java.net.URI.create(url));
            } catch (MalformedURLException e) {

              e.printStackTrace();
            } catch (IOException e) {
              e.printStackTrace();
            }
          }
        });

    try {
      hostname = CommonUtil.getHostName();
    } catch (IOException e) {
      e.printStackTrace();
    }

    new Thread(
            new Runnable() {
              @Override
              public void run() {
                try {
                  if (CommonUtil.isAddedDevice()) {
                    CommonUtil.doWork();
                  }
                } catch (IOException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
                }
              }
            })
        .start();
  }