Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8770761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:37:19+00:00 2026-06-13T17:37:19+00:00

I’m writing a Text Analysis Program for college that requires you to add a

  • 0

I’m writing a Text Analysis Program for college that requires you to add a word to a dictionary as well as other actions. I’m having a problem with this section of the code as I need an error message to come up if the user hits ok while the JTextField is empty. I can get it going but have created an infinite loop somehow with the error message. Please help, I’ve looked all over the internet but can’t find an answer for such a simple bug. Here is my code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.lang.Character;

public class TAPtest implements ActionListener
{
 private JFrame tap = new JFrame("Text Analysis"); 
 private JMenuBar tapMenu = new JMenuBar();
 private JMenu dictionary = new JMenu("Dictionary");
 private JMenuItem addWord = new JMenuItem("Add Word");
 private JFrame frameAdd = new JFrame("Add Word");
 private JLabel add = new JLabel("Enter word to add:");
 private JButton okNewWord = new JButton("Ok");
 private JButton cancelNewWord = new JButton("Cancel");
 private JTextField inputNewWord = new JTextField(28);
 private JPanel westAdd = new JPanel();
 private JPanel eastAdd = new JPanel();
 private JPanel southAdd = new JPanel();
 private Vector <String> dictionaryVector = new Vector<String>();

 public TAPtest() //Constructor. Contains TAP GUI.
 {  
   tap.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   tap.setSize(350, 100);
   tap.setLocation(700, 500);
   tap.setResizable(false); 
   tap.setJMenuBar(tapMenu);
   tapMenu.add(dictionary);
   dictionary.add(addWord);

   addWord.addActionListener(this);

   tap.setVisible(true);
 }

 public void actionPerformed(ActionEvent event) //All actions performed.
 {
   if (event.getActionCommand() == "Add Word") addNewDicWordGUI();

   if (event.getSource() == okNewWord) addNewDicWord();
   if (event.getSource() == cancelNewWord) frameAdd.dispose();
 }

 public void addNewDicWordGUI()
 {
   frameAdd.setSize(350, 150);
   frameAdd.setLocation(700, 500);
   frameAdd.setResizable(false); 

   okNewWord.setSize(5,20);
   cancelNewWord.setSize(5,20);

   westAdd.add(add);
   eastAdd.setLayout(new GridLayout(2,1));
   eastAdd.add(okNewWord);
   eastAdd.add(cancelNewWord);
   southAdd.add(inputNewWord);

   frameAdd.add(westAdd, BorderLayout.WEST);
   frameAdd.add(eastAdd, BorderLayout.EAST);
   frameAdd.add(southAdd, BorderLayout.SOUTH);

   okNewWord.addActionListener(this);
   cancelNewWord.addActionListener(this);
   inputNewWord.addActionListener(this);

   frameAdd.setVisible(true);
 }

 public void addNewDicWord() 
 {
   String inputNew = inputNewWord.getText(); //Get JTextField value.
   inputNew = inputNew.toLowerCase();
   frameAdd.dispose();
   if (inputNew.equals("")) 
    JOptionPane.showMessageDialog(null, "You must enter a word", "Notice", 1);
   else {
    boolean addItemFound = dictionaryVector.contains(inputNew); //True if contains.
   if(addItemFound) //If true.
JOptionPane.showMessageDialog(null, inputNew + " already exists in the dictionary.", "Word Already Exists", 1);
   else { //If not true.
    dictionaryVector.addElement(inputNew); //Add the word to the dictionary Vector.
Collections.sort(dictionaryVector); //Sort the vector in ascending order.
JOptionPane.showMessageDialog(null, inputNew + " was added to the dictionary.", "Word Added", 1);
   }
   inputNewWord.setText(null);
 }
}

public static void main(String [] args)
{
  TAPtest program = new TAPtest();
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T17:37:20+00:00Added an answer on June 13, 2026 at 5:37 pm

    Declare frameAdd like this –

    private JFrame frameAdd = null;
    

    The addNewDicWordGUI() method should be like this –

    public void addNewDicWordGUI()
    {
    
               if(frameAdd==null)
                   {
    
    //Initialized only for the first time
    
                frameAdd = new JFrame("Add Word");
    
    
           frameAdd.setSize(350, 150);
           frameAdd.setLocation(100, 200);
           frameAdd.setResizable(false); 
    
           okNewWord.setSize(5,20);
           cancelNewWord.setSize(5,20);
    
           westAdd.add(add);
           eastAdd.setLayout(new GridLayout(2,1));
           eastAdd.add(okNewWord);
           eastAdd.add(cancelNewWord);
           southAdd.add(inputNewWord);
    
           frameAdd.add(westAdd, BorderLayout.WEST);
           frameAdd.add(eastAdd, BorderLayout.EAST);
           frameAdd.add(southAdd, BorderLayout.SOUTH);
    
           okNewWord.addActionListener(this);
           cancelNewWord.addActionListener(this);
           inputNewWord.addActionListener(this);
         }
          frameAdd.setVisible(true);
     }
    

    Make the above changes and it will work fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.