Java Programming My Data cannot show when I click the Row [closed] - java

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
Hi friends I've been difficult to get my row in SQL. When I use mouse event in Java just 4 field in my row data appear.
private void jtb_dataasetMouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
// Mouse Pilih
int bar = jtb_dataaset.getSelectedRow();
String a = jtb_dataaset.getValueAt(bar, 0).toString();
jid_aset1.setText(a);
String b = tabmode.getValueAt(bar, 1).toString();
jnm_aset.setText(b);
String c = tabmode.getValueAt(bar, 2).toString();
jmrk.setText(c);
String d = tabmode.getValueAt(bar, 3).toString();
jsernum.setText(d);
String e = tabmode.getValueAt(bar, 5).toString();
jkondisi.setSelectedItem(e);
}
This is look like when I choose the data
I still difficult, please correct me if I made a mistake. I use the enum string in string.

From the javadoc for method setSelectedItem(Object anObject)
If anObject is not in the list and the combo box is uneditable, it will not change the current selection
Looks like the value in your JTable does not match a value in your JComboBox.
I suggest printing out the JTable value.
After this line of the code you posted...
String e = tabmode.getValueAt(bar, 5).toString();
add this line...
System.out.println("^" + e + "^");
Then compare that with the value that you think should be matched in your JComboBox.
A good programmer must know how to debug code. Have you read this Web page?
How to debug small programs
And regarding posting questions, in general, I recommend that you read this Web page.
How do I ask a good question?

Related

Is there a way to do many similar tasks in Java? [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 5 days ago.
Improve this question
Say for instance I want to repeat the line of code
Integer int1 = new Integer(value1);
for many variables, such as int1 to int100. I am not asking about this exact task in particular - I am asking about any such situation where the code would be identical save for replacing small details like int1 and value1 with int2, value2. Is there a way to have the JVM complete this for me?
I am not even sure what approach to take on this or what term to search for more information. The only thing I can think to try is instead of typing "int1", having a loop that changes a string containing the name and attempting to pass the string as a symbol to the JVM but this of course does not work.
It was a little strange question and I don't know if I understood your meaning correctly or not.
But in this particular case, instead of repeating the code, you can use a data structure like an array. See Oracle tutorial.
int[] numvar = new int[arr.length];
for (int i = 0; i < args.length; i++) {
int someNumber = Integer.parseInt(args[i]);
numvar[i] = someNumber;
}

Fetch value from Map<Object, Object> for a particular key in java [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have a Map<Object, Object> in Java, and I want to fetch value for a particular key.
sampleMap = { id = customerName , year = 2020, month = March }
I want to do something like
String name = sampleMap.get("month").toString();
But this is not working for me. How do I fetch values for a particular key in this case.
Note: I don't want to run a loop and check for each key as the Map is quite big in this case.
According to the data given in the question and comments, below code will fix your issue.
String name = sampleMap.containsKey("month") ? (
(sampleMap.get("month") != null) ? sampleMap.get("month").toString() : "N/A")
: "N/A";
You will get java.lang.NullPointerException when the key is not available or the value is null. So you should perform key check and null check before acquire data using the key.

My if statement with a negation does not work [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
My code executes properly only when it is not placed within the if statement. Why is that happening? I think there has to be something wrong with the condition which is supposed to check if Strings which are coming from JTextFields aren't empty.
Here is my code which is working without using the if statement:
user1.name = name1;
user1.password = pass1;
user1.ip = i1;
save(user1);
And here is the badly implemented if statement:
if(!name1.equals("") && !pass1.equals("") && !i1.equals("")) {
user1.name = name1;
user1.password = pass1;
user1.ip = i1;
save(user1);
}
Note: name1, pass1 and i1 are all Strings of pretty basic values. name1 can be Bob, pass1 can be Bob123 and i1 can be 192.168.32.1
Since you are trying to
check if Strings which are coming from JTextFields aren't empty
check the doc for the isEmpty() method and use something like:
if((name1 != null && !name1.isEmpty()) &&
(pass1 != null && !pass1.isEmpty()) &&
(i1 != null && !i1.isEmpty()) ) {
//....
}
A distinct non-answer: you are doing the validation in the wrong place!
Your UI elements should only allow you to trigger that save action when the required values are present. Create a user experience that prevents the user from making mistakes. Instead of investing times to discover "oh, the user made a mistake"!
In other words: you should listen to status changes on your text fields, and only when all three textfields have an non empty content, only then, you enable your Save button/menu item! And when one of field turns empty again, you better disable that button/menu item.

String.equal() funtion not working with value from `R.string` [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I want to compare my result(string) and I'm using following code to check it.
result = "password";
if (result.equals(R.string.myResponse)) {
//do something
}
R.string file
<string name="myResponse">password</string>
Above function is not working and doesn't get into if part.
However, If I replace R.string.myResponse with its actual value by if(result.equals("password")) then it is working fine.
What's the problem using string value from R.string
R.string.myResponse is not a string it is an ID for a string.
You need to get the string using that ID.
Something like context.getString(R.string.myResponse) or if you are in an activity or fragment then just getString(R.string.myResponse).
Replace
R.string.myResponse
with
getResources().getString(R.string.myResponse);
R.string.myResponse will return an integer value that is the ID of the particular string resource. You can use getString(R.string.myResponse) to get the String stored for that ID. To be on safe side use getResources().getString(R.string.myResponse) as getString() sometimes return null.

I want to Solve Below equation in java for button click event [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 9 years ago.
Improve this question
When I click on button the result display as Nan. And if I provide value of T directly for Example T=15 than 15 will be print out.
This is Formula.
T = (P*R)/ ((S*E)-(0.6)*P)
Where P , R , S is variable from Text Box.
And E is variable from Drop Down Box.
From my perspective, T is going to be a decimal, so the first thing you should look into is how to cast from a Java String to a double, using the Double.parseDouble() method, which you can read about here.
If you don't know how to grab the value from the text box itself, then you should read about JTextField, and its methods here. Finally, if you don't know how to get a value from a JComboBox, then you can read this tutorial.
Once you've worked out how to get the value from the text box or drop down list and parse it into the correct data type, you can get onto performing the calculation.
double t = (p * r)/((s * e) - (0.6) * p);
You'll also notice I've given you very little code. This is because you've given me nothing to work with. Happy reading!
Check your input for S & E, if it is 0 (zero) then your output always show NaN what stands for 'Not A Number'

Categories

Resources