Results 1 to 6 of 6
Thread: Swing boolean/String problem
- 10-22-2012, 12:07 AM #1
Member
- Join Date
- Oct 2012
- Posts
- 37
- Rep Power
- 0
Swing boolean/String problem
in this code, I am having trouble with booleans and strings. I set name variable as a String and newname as a boolean. The problem with this is that I need to print newname and cannot print a boolean. When I change it to a string it says it found boolean and gives me an error. Any ideas?
private void CheckNameButtonActionPerformed(java.awt.event.Acti onEvent evt) {
String name;
name= OriginalNameInput.getText();
Boolean newname = convertName(name);
OutputLabel2.setText(newname);
}
public static boolean hasComma(String name){
boolean oName;
int x= name.indexOf(',');
if (x == -1) {
oName= false;
}else{
oName= (true);
}
return (oName);
}
public static boolean convertName(String name) {
boolean convert = false;
hasComma(name);
if (hasComma(name)== true) {
System.out.println (name);
}else{
String s = name;
String[] arr = s.split(" ");
System.out.println (arr[1]+ ", "+ arr[0]);
}
return (convert);
}
- 10-22-2012, 12:26 AM #2
Member
- Join Date
- Oct 2012
- Posts
- 37
- Rep Power
- 0
Re: Swing boolean/String problem
Anyone??
- 10-22-2012, 02:19 AM #3
Re: Swing boolean/String problem
A print method that takes a boolean value exists. But looking at your code it seems you want to set the text of a label which indeed needs a String. So why not convert the boolean value to a String. Check out the String class or Boolean class. Both have a method to do this.
- 10-22-2012, 04:10 AM #4
Re: Swing boolean/String problem
Guide For New Members
BB Code List - Java Programming Forum
Code Conventions for the Java Programming Language: Contents
Also, bumping a thread after waiting just 19 minutes is extremely rude.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 10-23-2012, 04:45 AM #5
Member
- Join Date
- Oct 2012
- Posts
- 37
- Rep Power
- 0
Re: Swing boolean/String problem
So is replying with no helpful comments
-
Re: Swing boolean/String problem
Similar Threads
-
Input String to boolean equation
By rru96 in forum New To JavaReplies: 10Last Post: 09-23-2012, 10:21 AM -
convert boolean to string
By newbiejava in forum New To JavaReplies: 3Last Post: 07-22-2010, 03:32 PM -
How do I load characters from a String into an arraylist with a boolean value?
By Grendel0 in forum New To JavaReplies: 0Last Post: 03-16-2010, 11:08 AM -
Limiting loop in boolean string
By jimmy-lin in forum New To JavaReplies: 7Last Post: 10-10-2009, 06:31 AM -
boolean to string
By otoro_java in forum New To JavaReplies: 2Last Post: 01-30-2008, 05:31 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks