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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:45:11+00:00 2026-05-23T09:45:11+00:00

K, so unlike with my last question, I’ve been proactive about trying to deal

  • 0

K, so unlike with my last question, I’ve been proactive about trying to deal with this problem a number of times, and it’s still not working.

Basically I’m trying implement a JTextField. I’ve added the action listener to it and the getters and setters for the text are working, but text that I’m enter isn’t showing up in the textfield. I tried setting the text color to black and that didn’t help. Honestly, I’m not sure what the issue is.

K here’s the code.

import acm.program.*;
import java.awt.event.*;
import javax.swing.*;

public class NameSurfer extends Program implements NameSurferConstants {
//Change back to program after this
/* Method: init() */
/**
 * This method has the responsibility for reading in the data base
 * and initializing the interactors at the bottom of the window.
 */
public void init() {
    // You fill this in, along with any helper methods //
    createUI();
    addActionListeners();
}

/* Method: actionPerformed(e) */
/**
 * This class is responsible for detecting when the buttons are
 * clicked, so you will have to define a method to respond to
 * button actions.
 */
public void actionPerformed(ActionEvent e) {
    // You fill this in //
    if(e.getSource() == nameField || e.getSource() == graphName) {
        drawNameGraph(nameField.getText());
    } else if(e.getSource() == clearGraph) {
        clearNameGraph();
    }
}

 /* Method: createUI() */
 /**
  * This method sets up and adds the interactors at the bottom of the window*/
private void createUI() {
    nameField = new JTextField(25); 
    nameField.setColumns(25);
    nameField.addActionListener(this);
    graphName = new JButton("Graph");
    clearGraph = new JButton("Clear");
    graph=new NameSurferGraph();
    add(new JLabel("Name"), SOUTH);
    add(nameField, SOUTH);
    add(graphName, SOUTH);
    add(clearGraph, SOUTH);
    add(graph);
    //println(db.fileEntries.size());
}

/* Method: drawNameGraph(str) */
/** Draws the graph of the name entered in nameField
 * */
private void drawNameGraph(String str) {
    //println(str);


    NameSurferEntry entered = db.findEntry(str);
    if(entered != null) {
        //println("Graph: " + entered.toString());
        graph.addEntry(entered);
        nameField.setText("str");

    } else {
        graph.badEntry(str);
    }
    //nameField.setText("");
}

/* Method: clearNameGraph() */
private void clearNameGraph() {
    graph.clear();
}

private NameSurferDataBase db = new NameSurferDataBase(NAMES_DATA_FILE);

/**TextField where the names get entered*/
private JTextField nameField;

/**button to graph name popularity*/
private JButton graphName;

/**Clears graph*/
private JButton clearGraph;

private NameSurferGraph graph;

}

Also I’m going to try to explain my question better using images. Sorry if this don’t work on your OS. Their .tiffs but I’ll try to run them through image conversion later on. For some reason, stackoverflow isn’t letting me post the images in question, so I’m going to try to do some links to them instead through some other site. Sorry for the inconvenience.

When I run the code, this is displayed.
See the image for that here.
Basically so far it works as expected.

The problem arises
here.
The getters and setters are working, but I’ld like to have the JTextField updated when the user enters the text, as opposed to not displaying anything that I’ve got entered in it.

  • 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-05-23T09:45:12+00:00Added an answer on May 23, 2026 at 9:45 am

    Are you trying to do this?!?

    JTextField text = new JTextField();
    
    text.setText("ttttttttttttexxxt");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Unlike the other posts about the task delete all tables, this question is specifically
I realize that this question is not unlike asking someone for the name of
Unlike this question: Linker Error while building application using Boost Asio in Visual Studio
What I mean by this question is unlike other programming languages where I could
Please Note: This question is about the difference in terminology between the words destructor
Unlike in java why c# does not have a supertype of Number for Floats,
This question is for those of you who, unlike myself, truely understand multi-threading in
This question is a result of what i noticed while trying to answer another
Unlike std::map and std::hash_map, corresponding versions in Qt do not bother to return a
Unlike a lot of the other 'x' does not name a type errors on

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.