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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:55:32+00:00 2026-06-07T11:55:32+00:00

I am trying to simulate a production system and now I am having trouble

  • 0

I am trying to simulate a production system and now I am having trouble getting and passing values to a TreeMap located on a different class.

To explain what I intend to do briefly, I will to create a Panel where I will have some textpanels to save values (for the number of parts to be added to the system) and a table where the number and parameters of the work stations on the system will be set. When I run it, those values should be stored for further processing.

On a previous question I was recommended using TreeMaps to store those values, something like:

Station[num][type][avg_time][posx][posy][state]
Part[num][type][state]

This is what I’ve coded so far:

L.java

import java.awt.*;
import javax.swing.*;    

public class L extends JFrame {

    public static void main(String[] args) {


      SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            L l = new L();

            TMap t = new TMap();
            t.Station("num", 127);
            t.Station("type", 3);
            //System.out.println("Entryset: " + t.keySet());
            //System.out.println("Entryset: " + t.Station() + "\n");
         }
      });

    }

 } 

TMap.java

import java.util.*;

public class TMap {
    //public TreeMap <String, Integer>St = new TreeMap<String, Integer>();
    public int num_atrib = 6;
    public static TreeMap<String, Integer> Station(String s,int i) {
        TreeMap <String, Integer>St = new TreeMap<String, Integer>();
        St.put(s,i);
        System.out.println("Now the tree map Keys: " + St.keySet());
        System.out.println("Now the tree map contain: " + St.values());
        return St;
    }
} 

This is outputing:

Now the tree map Keys: [num]
Now the tree map contain: [127]
Now the tree map Keys: [type]
Now the tree map contain: [3]

I have two problems, first, is this the right way to do it, because for what I see the map outputed should be [num, type] and the keys [127, 3] right?

And secondly, how can I later on get parameters from TMap on the L class, since t.keySet() for instance won’t retrieve anything so far!

Hope I made myself clear, thanks in advance for your help.

  • 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-07T11:55:35+00:00Added an answer on June 7, 2026 at 11:55 am

    First off, you’re creating a new TreeMap every time you call TMap.Station. Try putting the TreeMap as a field and initializing it in a constructor instead. That should get you the map with two key/value pairs.

    Answering your second question, is there any reason why you cannot make the TMap a field and just create methods to access and set? If you only instantiate it in a function, it’ll disappear as soon as that function exits (plus its scope would only be in that function).

    EDIT: In response to the comment…what about

    EDIT EDIT: Adding rough outlines for getters. If you wanted something like a put(), it would work in a similar manner.

    import java.awt.*;
    import javax.swing.*;
    import java.util.Set;
    
    public class L extends JFrame {
        private TMap t;
    
        public L() {
            t = new TMap();
        }
    
        public Set<String> getKeySet() {
            return t.getKeySet();
        }
    
        public Integer get(String s) {
            return t.get(s);
        }
    
        // your main method as before
    }
    

    and

    import java.util.*;
    
    public class TMap {
        private TreeMap<String, Integer> St;
        private int num_atrib = 6;
    
        public TMap() {
            St = new TreeMap<String, Integer>();
        }
    
        public Set<String> getKeySet() {
            return St.keySet();
        }
    
        public Integer get(String s) {
            return St.get(s);
        }
    
        public static TreeMap<String, Integer> Station(String s,int i) {
            St.put(s,i);
            System.out.println("Now the tree map Keys: " + St.keySet());
            System.out.println("Now the tree map contain: " + St.values());
            return St;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was trying to use a local class as a way to simulate local
I am trying to simulate HTTP requests in Java with the URL class and
I'm trying to simulate mouse click at window with JNA. public class App {
I'm trying to simulate behavior of os.system with Popen and waitpid on Ubuntu and
I'm trying to simulate a particle system using OpenGl but I can't get it
I'm trying to simulate a substring in Python but I'm getting an error: length_message
I'm trying to simulate a floating modal box type thing but having an issue
I am trying to simulate a distributed algorithm by putting each process (class) to
I have to simulate a process scheduler using SRTN algorithm and im having trouble
I am trying to simulate a keypress in C# and I'm getting these errors:

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.