TurboST2's Profile
Reputation: 0
Apprentice
- Group:
- Members
- Active Posts:
- 28 (0.05 per day)
- Joined:
- 11-November 11
- Profile Views:
- 188
- Last Active:
Mar 19 2012 04:07 PM- Currently:
- Offline
Previous Fields
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: Disable/Enable textfield with radio buttons
Posted 19 Mar 2012
Ugh, I that I ask for help after looking for a solution for quite some time, only to find that after 5 minutes after I ask for help, while waiting for an answer, I answer my own question...
I needed to add this snippet
amountOfLodging.setEnabled(false);
-
In Topic: Disable/Enable textfield with radio buttons
Posted 19 Mar 2012
ok here is my code
import javax.swing.*; import java.awt.GridLayout; import java.awt.event.*; import java.text.DecimalFormat; public class lodgingCharges extends JPanel { JPanel lodgingPanel; JRadioButton yes; JRadioButton no; JLabel lodging; static JTextField amountOfLodging; //constructor public lodgingCharges() { setLayout(new GridLayout(2,2)); //create radio buttons yes=new JRadioButton("Yes"); no=new JRadioButton("No", true); //group radio buttons ButtonGroup bg = new ButtonGroup(); bg.add(yes); bg.add(no); //create components lodging = new JLabel("Enter Lodging Cost: $"); amountOfLodging = new JTextField(5); //create Panel lodgingPanel=new JPanel(); //add components to panel add(yes); add(no); add(lodging); add(amountOfLodging); //add listener yes.addActionListener(new EnableListener()); //create border around panel lodgingPanel.setBorder(BorderFactory.createTitledBorder("Lodging")); } private class EnableListener implements ActionListener { public void actionPerformed(ActionEvent e) { if(no.isSelected()) amountOfLodging.setEnabled(false); else amountOfLodging.setEnabled(true); } } public static String getCharges() { return amountOfLodging.getText(); } }
I'm using this snippet for making my text field "grayed out"
private class EnableListener implements ActionListener { public void actionPerformed(ActionEvent e) { if(no.isSelected()) amountOfLodging.setEnabled(false); else amountOfLodging.setEnabled(true); } }
It isn't working. The text field is still open for user input. What am I doing wrong? -
In Topic: Disable/Enable textfield with radio buttons
Posted 19 Mar 2012
thanks thats the nudge I needed. I knew I needed actionl listeners for this project but I wasn't sure if I was going to put them all in the main method or if I needed some in each class. -
In Topic: Palindrome assignment
Posted 6 Feb 2012
karabasf, on 06 February 2012 - 02:39 PM, said:The character b should not be str1.length()-1, but rather str1.length()-i.
Why? Let's evaluate your words:
mom, is a palindrome according your version, because:
Iteration 1:
char a = m
char b = m
Iteration 2: (final iteration)
char a = o
char b = o
Now, considering the word civic, your version will give:
Iteration 1:
char a = c
char b = c
Iteration 2:
char a = i
char b = c
Which results in your current result. This is caused because char b is a fixed value due to str1.charAt(str1.length()-1);
Hope this helps you out
I literally just came to this conclusion and then I heard my phone ding that I have an email which was a reply to this thread! The only thing is that str1.length()-i will give an error, it needs to be (str1.length()-1)-i
Changing that little piece is making every word I test give the proper results.
Thank you very much for everyone that helped me with this!! -
In Topic: Palindrome assignment
Posted 6 Feb 2012
I figured out the 2nd question after a few trial and errors, I wasn't getting any error and I see now that its only testing the first half of the word because if the first have is the same then the 2nd half is the same.
The pseudo code helped me quite a bit and I produced the following code:
//test for palindrome boolean palindrome = true; for(int i = 0; i<str1.length()/2; i++) { char a = str1.charAt(i); char b = str1.charAt(str1.length()-1); if(a!=B)/> palindrome = false; } if (palindrome == false) System.out.println("This word is NOT a palindrome"); else System.out.println("This word is a palindrome.");
This is working when I test the words "mom" and "dog", i get is and isn't a palindrome respectively. Now I tried this with a few larger words, "civic" and "peeweep" and am getting the incorrect output. For both "civic" and "peeweep" it is telling me they are not palindromes.
My Information
- Member Title:
- New D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
Contact Information
- E-mail:
- Click here to e-mail me
Friends
|
|


Find Topics
Find Posts
View Reputation Given

|
Comments
TurboST2 has no profile comments yet. Why not say hello?