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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:28:54+00:00 2026-06-14T20:28:54+00:00

I have the HangGame program I wont write this code when I Press any

  • 0

I have the HangGame program I wont write this code when I Press any Latter Button like (A,B,….. ) the latter that I Pressed it will be appear in the right place of the label part of the word that I read it in the text file for example I read word in Text file like (Stake) and on the screen will appear five label (_ _ _ _ _ ) , when I hold S button the character S will appear on the first label part (S _ _ _ _ ) and so on… . I don’t know how I write the code for the Action listener inside Button. finally I add Labels with out problem but I don’t know how to put right character in the right place.
I hope you understand my problem.

    public void ButtonComponent () {
    for (int i = 65; i < 78; i++) {
        JButton temp = new JButton("" + (char) i);
        temp.addActionListener(new BtnListener());
        temp.setBounds((i - 64) * 55, 110, 50, 30);
        add(temp);
    }
    for (int i = 78; i < 91; i++) {
        JButton temp = new JButton("" + (char) i);
        temp.addActionListener(new BtnListener());
        temp.setBounds((i - 77) * 55, 150, 50, 30);
        add(temp);
    }
}
class BtnListener implements ActionListener {
public void actionPerformed(ActionEvent e) {

    for (int s=0;s<splitword.length;s++) {
    String btnText = ((JButton)e.getSource()).getText().toLowerCase();
    if (splitword[s].contains(btnText)) {
        System.out.println("This letter is contained in the word:" + btnText);
    }
  • 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-14T20:28:56+00:00Added an answer on June 14, 2026 at 8:28 pm

    As this is Hangman, you will have to keep track of all correct letters used. Here is a template for a solution:

    String guessWord = "STAKE";
    StringBuilder builder = new StringBuilder();
    builder.append("S"); // hint: btnText...
    builder.append("T");
    String displayWord = guessWord.replaceAll("[^" + builder.toString() + "]", "_");
    

    I won’t solve the problem outright but this should give you enough to work with.

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

Sidebar

Related Questions

have a php code like this,going to convert it in to C#. function isValid($n){
Have data that has this kind of structure. Will be in ascending order by
Have you guys had any experiences (positive or negative) by placing your source code/solution
Have data that has this kind of structure: $input = [ { animal: 'cat',
Have a look at this code: #include <iostream> using namespace std; int main() {
have this code import threading def Thread(f): def decorator(*args,**kargs): print(args) thread = threading.Thread(target=f, args=args)
Have a look to this code snippet:- -(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { [webData setLength:
Have a fun issue with sharepoint calendar view filtering. That code works fine: SPSecurity.RunWithElevatedPrivileges(delegate()
Have a xml data like <Items><Item><name>test1</name></Item><Item><name>test2</name></Item></Items> Looks like jaxb cannot unmashall this when defining
have a look at this code order_service = client.GetService('OrderService', version='v201208') creative_service = client.GetService('CreativeService', version='v201208')

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.