Set Variable as Name of JLabel [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I'm trying to create JLabels in a loop and remove them at the End. So I need to give every Label its own name (Like Label[1], Label[2],...). I'm very new to Java so I can't imagine how to solve this problem. I already tried different ways but they all didn't work.

I am not sure but you can add a number of anonymous objects(in this case they will be JLabel or Label) to the Array List without naming them.(You need to use for loops). If you want to delete them, you need to use the same logic.
Let me know this works or not. If you stuck again, I can help you by writing the code. However, writing yourself will be more beneficial for you.
Have a nice day !!

Related

browsing through big amount of images with slider approach [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have 1000 images, each of them signifies a state at the time step. I would like to create an application that allows us to use a slider move through time steps, eventually being able also to see some information about what is going on in the image (like region size ect). I created the algorithm which creates generates and analyzes images in Python and I guess I will try to create UI in Java. Any recommendations on how to approach it? ( I am not very proficient in Java but I understand the basics). I attached the general view of what I want it to be below:
Try Tkinter, it is a very easy to use UI creator in python.
https://docs.python.org/3/library/tkinter.html

Multiple Swing Applet actionlisteners java [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Is there a way to make all of these actionlisteners into one statement?
jbtn0.addActionListener(this);
jbtn1.addActionListener(this);
jbtn2.addActionListener(this);
jbtn3.addActionListener(this);
jbtn4.addActionListener(this);
jbtn5.addActionListener(this);
jbtn6.addActionListener(this);
jbtn7.addActionListener(this);
jbtn8.addActionListener(this);
jbtn9.addActionListener(this);
jbtnAdd.addActionListener(this);
jfrm.add(jbtn0);
jfrm.add(jbtn1);
jfrm.add(jbtn2);
jfrm.add(jbtn3);
jfrm.add(jbtn4);
jfrm.add(jbtn5);
jfrm.add(jbtn6);
jfrm.add(jbtn7);
jfrm.add(jbtn8);
jfrm.add(jbtn9);
I am rather new to java, and I am using eclipse.
Yes, in a way. I do this sometimes:
for(JButton btn : new JButton[] {
jbtn0, jbtn1, jbtn2, ... , jbtn9
}) {
jbtn.addActionListener(this);
jfrm.add(jbtn);
}
I do that even when my components do not start out in an array, for example if I am filling a JToolBar and need to refer to the components by name somewhere else.
Judging by your naming scheme, it may also be advantageous for you to use an array from the beginning.
As pzaenger said in his comment, you could add all your buttons into an ArrayList or an array, and then just iterate through all the entries and add an actionlistener to each one.

Java newbie. Using the Math class [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am writing a piece of code that allows users to enter test scores. I then need to use the Math.max and Math.min to keep track of max and min and display the answer. I am not sure where I type that code or how I type that code.
Please let me know what pieces of the code would be helpful to post!
Thanks in advance!
Start by breaking down the problem into steps and figure out what you need to know. In your case you need to know four things:
How to get input from the console
How to compare values
How to conditionally change values
How to display things to the console
One and four you can search up pretty easy. Look into "Hello world" and other such starter programs for Java. Two and three you should look up "if" statements for Java. Hope this sets you on the right track.

How can I make two files interact (new) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Ok so hello all, this has really been bugging me, how can I call like other code in a different file? (All I know is simple scripting where you can call a function, is it the same?) Because say I want my user to input "north" than have it do a action like if (input.equals("north") { //blah etc, this has been bugging me forever not knowing how to do this so thanks for any help.
To clear and questions up
Basically all I want is to be able to call other code in a different class.
If they are in the same package as a given class (by making sure they have the same package packageName; line at the top of the java source files), you can simply instantiate objects that belong those classes which are defined in different files as you would any other object:
ClassFromAnotherFile obj = new ClassFromAnotherFile();

How to construct a JTextArea [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I am a very new programmer, it is part of my degree requirements and I am having a hard time with it. I am working on basically a three part GUI and I am wondering how I would create a JTextArea that will display each item that is entered.
Start by taking a look at Creating a GUI With JFC/Swing, this will give you a basic grounding in how to use Swing.
Take a closer look at How to Use Text Areas for specific details about how to use JTextArea

Categories

Resources