public void actionPerformed(ActionEvent e) {
    JButton b = (JButton) e.getSource();
    if (b == bu) {
      j14 = new JLabel("NEW IMAGE");
      j14.setBounds(840, 200, 300, 300);
      q.add(j14);

      JFileChooser filechooser = new JFileChooser();
      int result = filechooser.showOpenDialog(this);
      f = filechooser.getSelectedFile();
      try {
        String dir1 = f.getAbsolutePath();
        // setText(dir);
        str = dir1;
        // ResizeImage.resize(dir);
        f = new File(dir1);
      } catch (Exception e1) {
      }
      repaint();
      // b=(JButton)e.getSource();

    }
    if (b == ba) {
      try {
        read();
        patient.add(tadd.getText(), tsym.getText(), f, str);
        JOptionPane.showMessageDialog(null, "Patient ID: " + patient.pid + " Record Added");
      } catch (Exception e4) {
        System.out.println("" + e4);
      }
    }
    if (b == bm) {
      try {
        setVisible(false);
      } catch (Exception e4) {
        System.out.println("" + e4);
      }
    }
  }
  @Override
  public void actionPerformed(ActionEvent actionEvent) {
    Object obj = actionEvent.getSource();

    if (obj == btFindPat) {

      testpanel.removeAll();
      validate();
      repaint();
      if (taDictionary.getText().isEmpty()) {
        JOptionPane.showMessageDialog(
            frame, "Please load words so they appear in Text Area before Finding Path. ");

      } else if ((tfSourc.getText().isEmpty()) || (tfSourc_6.getText().isEmpty())) {
        JOptionPane.showMessageDialog(
            frame, "Please enter Source and Destination words before Finding Path. ");
      } else if (testpanel.getComponents().length != 0) {
        JOptionPane.showMessageDialog(frame, "Please clear results before continuing.");
      } else {
        wordLadder.findPath(
            tfSourc.getText(), tfSourc_6.getText(), Integer.parseInt(tfWordSize.getText()));
        lblFindPat.setText(
            "Time to find Path: " + String.valueOf(wordLadder.getTimeForPath()) + " milliseconds");
        lblCos.setText("Cost of Path: " + String.valueOf(wordLadder.g.getCost()));
        results = wordLadder.getResults();
        Collections.reverse(results);
        int x = 10;
        int y = 20;

        for (String s : results) {
          x += 20;
          y += 20;
          JLabel _lbl = new JLabel(s);
          _lbl.setLocation(x, y);
          _lbl.setSize(100, 26);

          if (results.indexOf(s) == 0) {
            _lbl.setForeground(new Color(-14646771));
          } else if (results.indexOf(s) == (results.size() - 1)) {
            _lbl.setForeground(new Color(-8254711));
          } else {
            _lbl.setForeground(new Color(-16777216));
          }
          testpanel.add(_lbl);
          testpanel.repaint();
        }
        if (wordLadder.g.getCost() == 0) {
          // if (wordLadder.g.getGraphError() != null){
          JLabel _lbl = new JLabel(wordLadder.g.getGraphError());
          _lbl.setLocation(x, y);
          _lbl.setSize(100, 26);
          testpanel.add(_lbl);
          testpanel.repaint();
          // }

        }
      }
      /*if (taDictionary.getText().isEmpty()){
      wordLadder = new WordLadder(tfFilePat.getText(), tfSourc.getText(), tfSourc_6.getText());
       }else if (!taDictionary.getText().isEmpty()){
          ArrayList<String> taList = new ArrayList<String>();
          StringTokenizer stringTokenizer = new StringTokenizer(taDump, "\t\n\r\f,\"");
          while (stringTokenizer.hasMoreTokens()) {
              String token = stringTokenizer.nextToken();
              taList.add(token);
          }
        */
      // }
    }

    if (obj == btLoadFil) {
      clearData();
      // wordLadder.setWords_size(Integer.parseInt(tfWordSize.getText()));
      // String size = tfWordSize.getText();
      // int intSize = Integer.parseInt(size);
      // WordLadderGUI.showMessage("Loading words of" + tfWordSize.getText() + " characters from
      // file: " + tfFilePat.getText(), Color.GREEN, Color.GREEN);
      lblIndexing1.setText("Indexing...");
      System.out.println(
          "Loading words of "
              + tfWordSize.getText()
              + " characters from file: "
              + tfFilePat.getText());
      wordLadder = new WordLadder(tfFilePat.getText(), Integer.parseInt(tfWordSize.getText()));
      // wordLadder.
      guiDictionary = new WordCollection(wordLadder.getWordList());
      WordLadderGUI.showMessage(
          "Displaying "
              + wordLadder.getWordList().size()
              + " words from file with length of "
              + tfWordSize.getText(),
          Color.GREEN,
          Color.GREEN);
      System.out.println(
          "Displaying "
              + wordLadder.getWordList().size()
              + " words from file with length of "
              + tfWordSize.getText());
      taDictionary.setText(guiDictionary.toString());
      lblIndexing1.setText("Indexing... done.");
      lblDictCoun.setText("Words in Dictionary = " + wordLadder.getWordList().size() + " words");
      wordLadder.buildGraph();
      System.out.println("Graph Built");
      lblProgres.setText("Time to Build Graph: " + wordLadder.getTimeForGraph() + " milliseconds");
    }

    if (obj == btLoadTextFiel) {
      wordLadder.setWords_size(Integer.parseInt(tfWordSize.getText()));
      String taDump = taDictionary.getText();
      System.out.println("Loading Words from Text Area");
      lblIndexing1.setText("Indexing...");
      ArrayList<String> taList = new ArrayList<String>();
      StringTokenizer stringTokenizer = new StringTokenizer(taDump, "\t\n\r\f,\"");
      while (stringTokenizer.hasMoreTokens()) {
        String token = stringTokenizer.nextToken();
        taList.add(token);
      }
      guiDictionary = new WordCollection();
      guiDictionary.setWords(taList);
      wordLadder = new WordLadder(taList);
      WordLadderGUI.showMessage(
          "Loading " + wordLadder.getWordList().size() + " words from Text Field",
          Color.GREEN,
          Color.GREEN);
      lblIndexing1.setText("Indexing... done.");
      lblDictCoun.setText("Words in Dictionary = " + wordLadder.getWordList().size() + " words");
      wordLadder.buildGraph();
      System.out.println("Graph Built");
      lblProgres.setText("Time to Build Graph: " + wordLadder.getTimeForGraph() + " milliseconds");
    }
    if (obj == btClear) {
      testpanel.removeAll();
      testpanel.validate();
      testpanel.repaint();
      wordLadder = null;
      lblCos.setText("Cost of Path: 0.0");
      lblCos.repaint();
      lblDictCoun.setText("Words in Dictionary = 0 words");
      lblFindPat.setText("Time to find Path: 0 milliseconds");
      tfSourc.setText("");
      tfSourc_6.setText("");
      taDictionary.setText("");
      results = null;
      lblProgres.setText("Time to Build Graph: 0 milliseconds");
    }
  }
  public void read() {
    try {
      // patient.dt=""+tdt.getText();
      patient.pid = Integer.parseInt(tpid.getText());
      patient.pfnm = tpfnm.getText();
      patient.pmnm = tpmnm.getText();
      patient.plnm = tplnm.getText();
      patient.gen = cbg.getSelectedCheckbox().getLabel();

      try {
        patient.age = Integer.parseInt(tage.getText());
        tage.setText("" + patient.age);

      } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Invalid age inputed.");
        patient.age = Integer.parseInt(JOptionPane.showInputDialog("Please enter valid age:"));
        tage.setText("" + patient.age);
      }

      try {
        int wet = Integer.parseInt(twt.getText());
        twt.setText("" + wet);
      } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Invalid weight inputed.");
        int wet = Integer.parseInt(JOptionPane.showInputDialog("Please enter valid weight:"));
        twt.setText("" + wet);
      }
      patient.wt = twt.getText();
      patient.addr = tadd.getText();
      this.ad = tadd.getText();
      System.out.println(tadd.getText());

      while (true) {
        patient.cno = tcno.getText();
        if (patient.cno.length() == 10) break;
        else {
          JOptionPane.showMessageDialog(null, "Invalid Phone No.");
          patient.cno = JOptionPane.showInputDialog("Please enter valid 10-digit Phone No.:");
          tcno.setText(patient.cno);
        }
      }
      patient.dnm = tdnm.getText();
      patient.sym = tsym.getText();
      System.out.println(tsym.getText());

      patient.dig = tdig.getText();
      try {
        patient.fee = Integer.parseInt(tfee.getText());
        tfee.setText("" + patient.fee);

      } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Invalid Fee inputed.");
        patient.fee = Integer.parseInt(JOptionPane.showInputDialog("Please enter valid Fee:"));
        tfee.setText("" + patient.fee);
      }

      patient.bg = tbg.getText();
      patient.path = str;
    } catch (Exception e) {
    }
  }
  public patientAdd(String s) {
    super(s);
    image =
        new JLabel() {
          public void paint(Graphics g) {
            ImageIcon ic = new ImageIcon(str);
            Image img = ic.getImage();
            g.drawImage(img, 0, 0, 150, 150, this);
          }
        };

    image.setBounds(670, 270, 300, 300);
    bu = new JButton("UPLOAD");
    bu.setBounds(700, 230, 100, 20);
    bu.addActionListener(this);
    //	q.add(bu);

    ldt = new JLabel("Date");
    lpid = new JLabel("Patient ID");
    lpnm = new JLabel("Patient Name");
    lgen = new JLabel("Gender");
    lbg = new JLabel("Blood Group");
    lage = new JLabel("Age");
    lwt = new JLabel("Weight                                          Kg");
    ladd = new JLabel("Address");
    lcno = new JLabel("Cont. no.");
    ldnm = new JLabel("Doctor Name            Dr.");
    lsym = new JLabel("Symptoms");
    ldig = new JLabel("Diagnosis");
    lfee = new JLabel("Fee                            Rs.");
    cbg = new CheckboxGroup();
    cm = new Checkbox("Male", cbg, false);
    cm.addItemListener(this);
    cf = new Checkbox("Female", cbg, false);
    cf.setState(true);
    cf.addItemListener(this);
    tdt = new JTextField(15);
    tpid = new JTextField(6);
    tpid.addFocusListener(this);
    tpfnm = new JTextField("first");
    tpmnm = new JTextField("middle");
    tplnm = new JTextField("last");
    tage = new JTextField(4);
    tage.addFocusListener(this);
    tbg = new JTextField(6);
    twt = new JTextField(5);
    tadd = new TextArea(patient.addr);
    tcno = new JTextField(20);
    tdnm = new JTextField(20);
    tsym = new TextArea();

    tdig = new JTextField(20);
    tfee = new JTextField(6);
    tfee.addFocusListener(this);
    ba = new JButton("ADD");
    ba.addActionListener(this);
    bm = new JButton("CANCEL");
    bm.addActionListener(this);
    bd = new JButton("DELETE");
    bd.addActionListener(this);
    bl = new JButton("DISPLAY");
    bl.addActionListener(this);
    bs = new JButton("SEARCH");
    bs.addActionListener(this);
    JPanel p = new JPanel();
    p.add(ba);
    p.add(bm);
    //	p.add(bd);
    //	p.add(bl);
    //	p.add(bs);
    add(p, BorderLayout.SOUTH);
    q = new JPanel();
    q.setLayout(null);
    ldt.setBounds(1015, 20, 60, 20);
    q.add(ldt);
    tdt.setBounds(1060, 20, 170, 20);
    q.add(tdt);
    lpid.setBounds(70, 60, 80, 20);
    q.add(lpid);
    tpid.setBounds(200, 60, 60, 20);
    q.add(tpid);
    lpnm.setBounds(70, 100, 80, 20);
    q.add(lpnm);
    tpfnm.setBounds(200, 100, 100, 20);
    q.add(tpfnm);
    tpmnm.setBounds(320, 100, 100, 20);
    q.add(tpmnm);
    tplnm.setBounds(440, 100, 100, 20);
    q.add(tplnm);
    lgen.setBounds(70, 140, 60, 20);
    q.add(lgen);
    lbg.setBounds(370, 140, 80, 20);
    q.add(lbg);
    tbg.setBounds(470, 140, 60, 20);
    q.add(tbg);
    cm.setBounds(200, 140, 60, 20);
    cf.setBounds(280, 140, 60, 20);
    lage.setBounds(70, 180, 40, 20);
    q.add(lage);
    tage.setBounds(200, 180, 50, 20);
    q.add(tage);
    lwt.setBounds(370, 180, 200, 20);
    q.add(lwt);
    twt.setBounds(470, 180, 60, 20);
    q.add(twt);
    ladd.setBounds(70, 220, 60, 20);
    q.add(ladd);
    tadd.setBounds(200, 220, 350, 50);
    q.add(tadd);
    lcno.setBounds(70, 310, 60, 20);
    q.add(lcno);
    tcno.setBounds(200, 310, 120, 20);
    q.add(tcno);
    ldnm.setBounds(70, 350, 200, 20);
    q.add(ldnm);
    tdnm.setBounds(200, 350, 150, 20);
    q.add(tdnm);
    lsym.setBounds(70, 390, 100, 20);
    q.add(lsym);
    tsym.setBounds(200, 390, 300, 70);
    q.add(tsym);
    ldig.setBounds(70, 480, 60, 20);
    q.add(ldig);
    tdig.setBounds(200, 480, 100, 20);
    q.add(tdig);
    lfee.setBounds(70, 520, 200, 20);
    q.add(lfee);
    tfee.setBounds(200, 520, 40, 20);
    q.add(tfee);
    q.add(cm);
    q.add(cf);
    q.add(image);
    q.add(bu);
    add(q, BorderLayout.CENTER);
    addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            try {
              patient.con.close();
              System.exit(0);
            } catch (Exception e8) {
            }
          }
        });
    System.out.println(tadd.getText());
    setSize(1330, 740);
    setVisible(true);
  }