BestJewSinceJC 700 Posting Maven

It can do a lot more if you use the web development forums.

BestJewSinceJC 700 Posting Maven

You managed to make the try catch block. Now all you have to do is System.out.println(variable nexocentric told you to output). Debugging is a very important part of programming, so you need to learn to do it. Debugging tools are very helpful, but I personally prefer print statements. If you put them in appropriate places, such as when you read a value into a variable, after a calculation is done on a variable, etc, then you will find your problem. Basically find the key points, logically determine what the value of the variables should be at those points, and use the print statements to see if they actually are.

nexocentric commented: Yeah, debugging is pretty important. Nice catch on the listener problem. +1
BestJewSinceJC 700 Posting Maven

For testing whether or not a Character is a digit, you can use the Character class's method isDigit(). So, for example,

String s = stdin.readLine();
for(int i = 0; i < s.length(); i++){
    if (s.charAt(i).isDigit()){
       System.out.println("It's a digit!");
    }
}

But for your purposes, if you don't want any "weird" characters in your String, you should check to see if each character is anything other than a-z, A-Z, or ' and any other character that are allowed. This will obviously mean less code and more efficient code. Java uses the Unicode character set, so look into that to figure out how to code something that will basically say

if (myCharacter < a || myCharacter > z)

BestJewSinceJC 700 Posting Maven

I don't really understand you, no. But if you're trying to do different chats then you need to use separate threads....

BestJewSinceJC 700 Posting Maven

Well, I decided to take the easy way out and just re-set the editor using the same code that I originally used to do it. But it would be nice to have a listener that just updates the editor whenever it changes instead.

BestJewSinceJC 700 Posting Maven

It took me very little effort to put a JComboBox in a JTable so that when the cells in a certain column are clicked, it lets the user choose from a drop down list of items. However, my program requires that the underlying combo box can change, since the list that the combo box relies on can change. How can I make this happen? I tried some various things, such as the following, but with no luck. Didn't really expect it to work anyway, considering the return type of getCellEditor. .

javax.swing.table.TableColumn doctorColumn = jTable1.getColumnModel().getColumn(1);
        javax.swing.JComboBox box = (javax.swing.JComboBox)doctorColumn.getCellEditor();
        box.removeAllItems();
        java.util.Vector<Doctor> docs = Application.readDoctors();
        for (Doctor d: docs){
            box.addItem(d.readName().toString());
        }
BestJewSinceJC 700 Posting Maven

What are you having trouble with? You said you're having trouble storing things in a list, but I see from your diploma code where you add the thing to the TreeSet that you are doing this fine. An ArrayList works the same way. Going off of JavaAddict's earlier example,

ArrayList<People> list = new ArrayList<People>();
list.add(new People());

Maybe you should give an example of what you're talking about or a more specific section of code you can't do or something.

BestJewSinceJC 700 Posting Maven

No. You could find the correct indexes of what was before and after Topic: by searching for the substring Topic: within the String. Then the first half starts at index 0, and the index where Topic: starts is the end index. And the ending index of Topic: will tell you where the beginning index of the second part is.

BestJewSinceJC 700 Posting Maven

Just increment an int until it is less than a certain value or something if you don't want to take Vernon's advice.

int i = 0;
do{
i++;
} while(i<10000000)

BestJewSinceJC 700 Posting Maven

By any chance do you go to umbc . . ? This just looks somewhat similar to a program they typically have students do (although the one they do is a lot more complicated, but that could be because you just started or omitted code, etc). Could also just be a common programming project.

Anyway,

CD mycd[]; declares a new array, but does not initialize it. Basically, what that means is that you declared an array, but did not set aside any memory for it to use. Had you initialized it properly, it would look like this:

CD mycd[] = new CD[NUMBER_OF_CDS]; where NUMBER_OF_CDS is an integer or a variable (of type int) that you declared. This declares an array of CD's. Lets say you had said CD mycd[] = new CD[3], then the compiler would set aside enough memory for you to hold 3 CD's. Think of it as looking like this:

[CD Number 1][CD Number 2][CD Number 3]. And the way you would put a CD into CD Number 1's space is by saying mycd[0] = *name of a CD Object goes here*.

In the first class that you posted, you created a new CD Object by saying CD myCd = new CD(whatever). But then you kept saying myCd = new CD(whatever), which basically overwrites the CD that you previously created. What you probably should be doing looks like this:

CD[] allMyCDs = new CD[NUMBER_OF_CDS_GOES_HERE];
CD aliceInChains = new CD(whatever);

VernonDozier commented: Good explanation. +14
BestJewSinceJC 700 Posting Maven

I remember a discussion about this on Daniweb before. You might want to do a search for it. But I'm pretty sure the only way to do what you want is to read the file, delete it, and write what you want the file to be back to the same filename. http://www.java-tips.org/java-se-tips/java.io/how-to-use-random-access-file.html An example, but they are not trying to delete things, just append.

BestJewSinceJC 700 Posting Maven

You are reading from and writing to the same file. After you are finished reading everything from it, delete the file, then write to the file. Then tell me if you are still having problems. Without reading the PrintWriter documentation, it seems like it is just appending the new text to the beginning of the file. Why it would do this, I don't know, but like I said, try deleting the file first.

BestJewSinceJC 700 Posting Maven

I'm sure there is a better way to do this, but for lack of any other responses right now, why don't you use the substring method and the equals method to determine whether something matches the pattern?

BestJewSinceJC 700 Posting Maven

I'm using netbeans and I have a problem. I'm using a card layout to flip between multiple windows. Two of these windows are wider than the others, and this cannot really be helped. Ideally, it would be best to design each window so that they are all the same size, but it is impossible in this case, due to the types of information. Anyway, I can't figure out how to make them resize themselves at runtime based on which window is selected. I have the following hierarchy:

JFrame
JTabbedPane
JPanel 1 (as one of the tabs, this JPanel contains the card layout)
JPanel 2 (this is inside JPanel 1, and contains the combo box which decides what window to flip to)
JPanel (this is inside JPanel 1, and contains the windows that are flipped between)


I've tried explicitly setting the size, starting with the topmost component (the JFrame), then resizing each of the things underneath. No luck, it just ignores me and does not change the size of anything except the JFrame.

Edit:

Yeah, I don't know what I'm going to do. Since the top level container is the only thing stopping the lower ones from resizing, resizing from the top down should be working. So I guess it's the layout manager which is stopping things from being resized. Hm.

BestJewSinceJC 700 Posting Maven

I think he wants to do something more like
int total = 0;
//where array is an array of strings
for (int i = 0; i < array.length; i++){
total+=Integer.parseInt(array);
}

Ezzaral commented: Yeah, I think you're right. +21
BestJewSinceJC 700 Posting Maven

Well, what are the user's options as far as deleting things? How would they specify what lines they want deleted? Does the "pe158nb" distinguish what "kind" of data is on the line? Or does the "nb"? This is information I need to know in order to help you. Basically -- how can the user delete stuff, and how does your program know what stuff to delete (i.e., the program will delete anything that says ub. . etc)?

BestJewSinceJC 700 Posting Maven

*Being sympathetic to OP may be nice, but it solves nothing
*It doesn't really mater to OP how hard we fight, he will always win ;)

Actually I disagree. I don't know any C++ but I was attempting to learn the answer to the OP's question, and it was practically impossible to wade through all of the crap in this thread. Your attitude is despicable and you should be ashamed. Also, FYI, I did not learn anything from this thread. The egos blocked any possible gain of knowledge or understanding.

edit: Thanks to William, maybe I did learn something.

BestJewSinceJC 700 Posting Maven

You need two methods because there are two independent patterns in that picture. The first pattern is the one that looks like:

*
**
*

And the second pattern is the one that switches between printing 4 stars and 8 stars. All you need for the first method is something that prints the first pattern I showed you above. All you need for the second method (the one that switches between printing 4 stars and eight stars) is a counter. If the counter is a multiple of 2, you print eight stars. Otherwise, you print 4 stars.

Oh, and the recursion comes into play because after the first method prints its stars, it needs to call the second method to print its stars. The second method can then call the first method again. You need to also remember that you'll need some way to decide when to stop printing stars.

BestJewSinceJC 700 Posting Maven

1)What is the difference between an instance data field and a static data field??

You need to look things up on your own.

:)

BestJewSinceJC 700 Posting Maven

To "delete" stuff from the text file, you have to read in the entire file, while deciding what you do and don't want in it, then write the output (the stuff you do want in the text file) back to the same file. You can do this one of two ways:

1. While you're reading it in, only add the stuff you do want to a list. Write the contents of that list out to the file.
2. Read everything into a list, then go through the list and delete the elements you don't want. Write out the list.

And it seems like your "delete" code is in (i==2) part of the code, right? You'll need to post an example text file also. We need to know what the format of the text file is in order to help you.

BestJewSinceJC 700 Posting Maven

Is there any reason you extended Applet and not JApplet? Just curious; I have no idea if it matters or not.

BestJewSinceJC 700 Posting Maven

Yeah, I think the clever code is called a runtime error. I'm no expert though.

BestJewSinceJC 700 Posting Maven

What you want to do is cause the item in the JComboBox to appear. So you will need to use nameOfYourJComboBox.setSelectedIndex(indexYouWantToShowUp);

Also, get rid of all those comments that say "//end whatever method", they are not useful and make it harder to read your code.

BestJewSinceJC 700 Posting Maven

http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Graphics.html

This class^ pretty much has all the methods you need. drawRect and drawOval or fillRect and fillOval are probably the ones you will use. What you need to do is shown here: http://java.sun.com/docs/books/tutorial/2d/geometry/primitives.html . I can never remember when you're supposed to override the paintComponent method instead of the paint method (anyone?), but it says to override the paint method so do that. Their example class extends JApplet but you can extend JFrame and it should work the same way. And you can basically have variables in your class that are the parameters of fillRect etc, and update those variables while calling repaint in a loop. (Inside the paint method, you'll need to follow the example, and also pass your variables into the fillRect method or whatever you use)

BestJewSinceJC 700 Posting Maven

The programming
assignment is to implement a class Purse. A purse contains a collection of coins. Each coin object must contain its
name. You should not put a limit on the number of coins that a purse can hold. This program should provide the user with the ability to display the contents of the purse, add coins, count coins, calculate the amount of money in purse and for extra credit, spend coins. You will need 2 Java Object Classes: one to define the Coin objects, and one for the Purse object.

1. Decide what the "things"/Objects in your project assignment are. In this case, a purse and coins.
2. Decide what the relationships between the things in your project are. In this case, the main relationship is that a Purse holds coins.
3. Decide how to implement the relationships between your Objects, and decide what kind of data each class (Purse and Coin) needs. Well, since a purse holds coins, the Purse class needs to have a List of coins. But it also must impose no limit on the number of coins, i.e. it has to be able to grow. You can use the ArrayList class to do this. Since a coin must contain its name, according to the assignment, the Coin class must have a String for the name.
4. Determine what methods you need. The "this program must provide the user with the ability to. . . " is a dead giveaway. Pretty …

BestJewSinceJC 700 Posting Maven

I don't know if this is relevant or not, since looking at your code, I see nothing really. But to switch the item in the combo box you'd just use jComboBox.setSelectedItem(index). And your method would obviously have to check the array to make sure you're in bounds, then flip to the end of it if you're at the first or last item.

BestJewSinceJC 700 Posting Maven

If you're still asking for help with your question, "Ok I tried a couple of stuff but I'm at a loss here, I'm not sure how to check if the node data is less than 10 so I can add "00" to the string without forcing it, any tips would be appreciated", you're going to need to post the DLList class. Your InfiniteInt class extends DLList, but how am I going to tell you how to check the data without knowing what type of Object the data is, which requires seeing the DLList class? If the "data" Object that you keep referring to is simply a String, then use what I told you above.

BestJewSinceJC 700 Posting Maven

It's hard to say because I don't know what your class looks like for Infinite Int

BestJewSinceJC 700 Posting Maven

Nevermind. All of them should be user generated, that's the whole point. I got confused because I thought something was happening that was not happening. Or something. Either way it's been working for a while now.

BestJewSinceJC 700 Posting Maven

You can use Integer.parseInt(yourString) to convert a String to an Integer. But I'd recommend you think about my advice earlier. . I don't think there is an easier way to accomplish your goal.

BestJewSinceJC 700 Posting Maven

So that should tell you something. A node and an Integer are not the same data type so you shouldn't be trying to force them to be.

BestJewSinceJC 700 Posting Maven

And the unofficial way would be to put the code in a method, then call the method in the appropriate places.

BestJewSinceJC 700 Posting Maven

How can I check if an event is user generated? When the user clicks on a combo box and changes the displayed/selected content, I want the code in the itemStateChanged method to be executed. But I only want this code to be executed if the method call was due to a user generated event, not a programmatically generated one. How can I differentiate?

itemStateChanged(ItemEvent e){
if (user_generated){
//do stuff here
}
}

actually it'd be actionPerformed in this case, but the question remains the same

BestJewSinceJC 700 Posting Maven

It seems like you would have to do a few things to compare two Infinite Integers.

1. Does one have more nodes than the other? If so, the one with more nodes is greater, since each node holds 3 numbers.
2. Do they have the same number of nodes? If so, start at the top node for each, and compare the numbers. If one node's integers are greater than the other's, the greater one is your answer. Otherwise, move on to the second node (for each Infinite Integer)

It doesn't seem to me that your code is doing these things.

BestJewSinceJC 700 Posting Maven

Someone else coded what i was referring to above, but since either

a) it doesn't work or
b) I am using it incorrectly

I'm recoding it entirely. It also makes no sense to me that an inner class is necessary in this case, so I'm getting rid of it. If anyone has any ideas on how the error I got could have happened, please let me know.

BestJewSinceJC 700 Posting Maven
java.util.Vector<EmergencyContacts.ContactInfo> contacts = Application.getPatient().readEmergencyContacts().readContactInfos();
for (int i = 0; i < contacts.size(); i++){
            EmergencyContacts.ContactInfo info = contacts.get(i);
}

public Vector<ContactInfo> readContactInfos(){
		return contacts;
	}

	private Vector<ContactInfo> contacts = new Vector<ContactInfo>();

As you can see, it returns a Vector of ContactInfo. Why would I be getting an error saying, "Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to repository.EmergencyContacts$ContactInfo" for the line where it says . . . contacts.get(i)?

Also, if it matters, ContactInfo is an inner class of EmergencyContacts. Hence above where you can see it say readEmergencyContacts.readContactInfos. There is only one Object of type EmergencyContacts, which has the Vector of ContactInfo (which I posted in the code). And everything is Serializable.

BestJewSinceJC 700 Posting Maven

We don't do problems for you, we help you do them. Ask a more specific question. If you just want the code I'm sure you will find it all over the internet anyway. This isn't exactly an original problem.

BestJewSinceJC 700 Posting Maven

Good observation Vernon. Man, I'm slacking lately. It's those exams coming up.

:(

BestJewSinceJC 700 Posting Maven

Yes, but that still isn't a question, it is a project description. In order to help you without doing your project for you, we need to know specifics about what you're having trouble with, where in the code, what you've attempted, what isn't working, etc. "What isn't working" is usually one pat of your pseudocode, not the entire thing.

BestJewSinceJC 700 Posting Maven

You can do all of this in one class if you really want to, but there is no need to do so - you can just as easily do it the way you have things set up. The way to make a button do something when it is clicked is to have your class implement ActionListener. Then in the actionPerformed method, you would do textFieldName.setText("text or variable name in here");

See this for more information and examples. If you don't know about ActionListener, or Listeners in general (which it appears you don't by looking at your classes) read the link they provide to ActionListener.

BestJewSinceJC 700 Posting Maven

To do it with netbeans, you add one JTabbedPane to a JPanel or JFrame. Then I think you add JPanels to that JTabbedPane, and it automatically makes these JPanels into tabs. To flip between the tabs, you click them on the side where it has the listing of all your components. If this doesn't work for you or doesn't make sense, I'll open netbeans when I get back to my machine and I'll give you a step by step breakdown.

Oh, and to do it just using Swing w/o netbeans doing it for you, you'd instantiate a new JTabbedPane, then use the addTab method. You can look this up in the docs.

BestJewSinceJC 700 Posting Maven

You cannot compare Strings using '==' you must use the String class's equals method.

if(titlelisting.getSelectedValue()=="OxbridgeBaby")

BestJewSinceJC 700 Posting Maven

Yeah, if you want a hello world program, I'll do it for $5

BestJewSinceJC 700 Posting Maven

Well, in our case, for the three tier architecture, we have:

GUI -- Application Layer (interacts between GUI & Model) -- Model (Patient classes & methods)

Which seems to be somewhat different than what you are saying. Of course, we do not have anything significant for data storage, since we are just using serializable.

BestJewSinceJC 700 Posting Maven

....

BestJewSinceJC 700 Posting Maven

In response to the specific Q about lots of windows and selective updating: I think you should not try to split the Observable interface into sub-interfaces to meet a GUI requirement; that's just another way to entangle the two layers. Provide an Observable interface that's designed around the model and what can happen within it. Windows, or whatever, can register with the model if they want to know what's happening, but are perfectly free to have empty methods for the events they don't care about (we've ll done this with MouseListener for example)

Good point about further entangling the two layers. The thing is, there is one Object that all of the GUI windows (that ever need to be changed) show information about. The Object is a Patient, and the Patient has these categories in the model: Medical Information, General Information, Emergency Contact Information, etc. The GUI has one window for displaying each of these categories. So I don't see why there couldn't be a list of Listeners (in the model), one per category. Or would it be better to just set it up like Ezzaral said, with only one list of Listeners, and in the GUI, the stuffChanged method would decide which windows needed to be updated?

Thanks

Also, my project technically has to use a three tiered architecture. That's why I was interested in doing it with MVC. Although the two are different, they are much more similar than (MV)-C. Technically, communicating using listeners between the …

BestJewSinceJC 700 Posting Maven

Part 2: thoughts on push vs pull.
I think it's a false dichotomy; you have both.
The model will have various public getter methods that a UI can call to get valid current data from the model any time it wants. That's what may probably happen when the window is first opened, for example.

Me: So if I understand this correctly, you're saying that this is the pull part, but any MVC uses both.

The problem is that the UI won't know if its data becomes out of date, and that's where the Observer pattern kicks in. The listener interface should not attempt to transmit every detail of what's changed; it should give enough info for an Observer to decide if it's interested.

Me: So basically, you're saying that the model should only tell the view that something it wants to know about has changed, but the view is responsible for calling the model's methods in order to retrieve the information it is interested in. (i.e. this would not only mean less work/code for the model, but it would mean more logic separation between the model and the view). Right?

Trivial example:
Model is a Customer class. Public methods getName, getAddress etc etc.
Listener interface could look like this:

interface CustomerListener {
   public void customerChanged(Customer c);
   public void customerAdded(Customer c);
}

Typical code in the UI could look like this:

public void customerChanged(Customer c) {
   if (c != theCustomerImCurrentlyDisplaying) return;
   nameField.setText(c.getName);
   ... 
}

Your code example that …

BestJewSinceJC 700 Posting Maven

@ James: I'm not worried about memory consistency errors. I have a pretty good understanding of that, but I'll keep it in mind. I

edit: I don't really understand your example though, James. you mind explaining further/ providing a short outline of the rest of the classes?

BestJewSinceJC 700 Posting Maven

I would try to be helpful if you asked a specific question. "I don't know how to do this, please help" is fine, but people have already given step by step explanations of what you need to do to accomplish your goal. At this point, you need to explain what you are having trouble with and (preferably) post code of what you've attempted in order for us to help you. Also, keep in mind that insulting the people on this site isn't a good way to get help, whether it is justified or not. Especially over a minor jab that was said in jest. Anyway, peace, good luck on your program, and if you still need help, I will help you as much as you need. Also - to me, it doesn't matter what the program is for as long as the person writing it is learning something (so I don't care whether this is for your job, your school, your friend, etc). Just throwing that out there.

BestJewSinceJC 700 Posting Maven

Ezzaral - thanks for your help. I'd still appreciate if you answered or if someone answered the questions I posed above, but I feel like I understand this diagram (the first one) fully now. Hopefully I will still feel that way tomorrow. I'm going to use a pull model for my project (the example you posted was push, I believe).