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 7718335
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:08:35+00:00 2026-06-01T03:08:35+00:00

The class below is my delete class, i want to delete the users from

  • 0

The class below is my delete class, i want to delete the users from the database, i have a Add class and Search class, their share the same database private Database db;.

package TakeMeOut;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;


public class Delete extends JFrame implements ActionListener


{

    /** {@link JTextField} where the user number is entered */
    private  JTextField userID = new JTextField(7);

    /** {@link JTextArea} for the client information */
    private  JTextArea information = new JTextArea(5, 39);

    /**{@link JButton} Search button */
    private  JButton Deleteuser = new JButton("Delete");

    /**
     * Default constructor. Create a new search panel with a {@link JTextField} for client ID and a {@link JTextArea} for detailed
     * information on the client..
     */
    private Database db; 

    public Delete(Database db) 
        { this.db = db; 

        setLayout(new BorderLayout());
        setSize(450, 250);
        setTitle("Delete Client");

        /** dispose of the window when the close button is clicked*/
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

        JPanel top = new JPanel();

        /** add the veritable of JButton to the top panel*/
        top.add(Deleteuser);
        /**add the bottom panel to the bottom of the screen*/
        add("North", top);

        top.add(new JLabel("Enter Client Number:"));
        top.add(userID);
        add("North", top);

        JPanel middle = new JPanel();
        middle.setLayout(new FlowLayout());
        middle.add(information);
        add("South", middle);

        /** do not allow enduser to set the size of the screen*/
        //setResizable(false);
        setResizable(false);
        setVisible(true);


        // listen to the button
        Deleteuser.addActionListener(this);
    }

    /**
     * delete user from database when the delete button is clicked
     */
    @Override
    public void actionPerformed(ActionEvent e) {

        User u = (userID.getText());
        db.removeUser(u); 

        information.setText(u.toString() + " has been deleted");    
    }

the class below is my database class, which has the remove method and i am trying to pass it through to the Delete class above.

import java.util.*;
public class Database 
{/**             
    *   
    * Map of users keyed on userId              
    */
    Map <String, User> users; 


    /**    @Database          
    * the empty map  which would be used to  collect the users.                     
    */
    public Database() 
{      
        users = new HashMap<String, User>();

}



    /**
    * Type for checking users
    */
  public  static void main(String [] args){
             new Database();
            }     

    /** check if the UserID is already in use if so return false, else
     *   add key pair to the Map. 
     *   USERID will be key of map 
     *     @
    */
    public boolean addUser(User userIn) 
    {

        String keyIn = userIn.getUSERID(); 
        if (users.containsKey(keyIn)) 
        { 
            return false; 
        } 
        else 

        { 
            users.put(keyIn, userIn); 
            return true; 
        } 
    }



    /** 
     * @param remove the user with the given useridIn, from the Map
     * check if user was removed and does not equal to no null 
     * @return If the user is not  removed return false
     *  
     *  */
    public boolean removeUser(String useridln) 
    { 
        if (users.remove(useridln)!= null) 
        { 
            return true; 
        } 
        else 
        { 
            return false; 
        } 
    }

    /** 
     * return the number of users in the Map collection  
     * 
     * 
     * */
    public int getTotalNumberOfUsers()
    {
        return users.size();
    }


    /** return the user with the given userid or null if no such user
     * */
    public User getUser (String useridIn)
    {
        return users.get(useridIn);
    }



    /** return the set of users in the collection
     * set is used to store the set of users  and to get the set of keys.
     * iterate through the keys and put each value in the userSetn and return the set of users
     * 
     * 
     * */
    public Set<User> getAllUsers ()
    {  

        Set<User> userSet = new HashSet<User>(); 
        Set<String> theKeys = users.keySet(); 

        for (String userid : theKeys)
        {
            User theUser = users.get(userid);
            userSet.add(theUser);
        }
        return userSet; 


        }   

    public String toString(){

        return users.toString();
    }
}

the class below is my User class, with the return methods

public  class User  {

    /**declared attributes */
    private String username;  
    private String gender;
    private String age;
    public  String userid;

     /** User constructor with four  types of string objects and the declared methods */
      public User(String usernameIn, String genderIn, String ageIn, String useridIn) {

    /* declared methods*/
      username = usernameIn; 
      gender = genderIn;
      age = ageIn;
      userid = useridIn;
    }

      /**
       * 
       * @return
       */
    public String getUsername() {
      return username;
    }

/**
 * 
 * @return
 */
    public String getGender() {
      return gender;
    }

    /**
     * 
     * @return
     */
    public String getAge() {
      return age;
    }

    /**
     * 
     * @return
     */
    public String getUSERID() {
        return userid;
      }


    /**
     * ToString return the customized values
     */
    public String toString()
    {
        return"       "+ username +"     " + gender + "     " + age + " \n";
    }
  }

In the Add class i can add users.

User u = new User(Inputusername.getText(),  selection , age.getText(), inputuserid.getText());
db.addUser(u);

I would like to delete the added user from the database but, i do not know why its not taking it as i have pass the string to the delete class.

  • 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-01T03:08:37+00:00Added an answer on June 1, 2026 at 3:08 am

    Please try to follow the Java Code Conventions, especially the rules about how fields and methods start with a lowercase letter. It would make your code a lot easier to read.

    Also, try to formulate your question clearer. What exactly is not working? What are the error messages or what is the expected behaviour vs the actual behaviour?

        User u = User db.getUser(userID.getText());             
        db.removeUser(u);     
    

    The first line seams wrong in general (what does “= User” mean?)
    But more importantly:

        public boolean removeUser(String useridln) 
    

    The mothod expects a String, not a User Object, so it should work if you pass userID.getText() instead.

    Was this your problem? I am unsure as you also mention “deleting searched value”, but I cannot see a search field.

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

Sidebar

Related Questions

I have a table model. I want to delete a row from a table.
i have a context class like below,i want to log all db operation where
I have posted my class below and with sample data. I need to pass
as you can see the class below declares 2 private instance variables and 2
I only want to parse an interested element of xml (e.g. see below: class
I want to have a simple class i can call to get a unique
My table is being populated using ajax from a mysql database. I have a
The script I have below is for users to upload a profile picture to
I'am having the following situation. We have a private method where I want to
I have many-to-many for tag <-> software , when i delete tag i want

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.