This week's giveaway is in the Testing forum.
We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!
See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!

Chris Ramsey

Ranch Hand
+ Follow
since Sep 15, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Chris Ramsey

Originally posted by Jeanne Boyarsky:
You can use the available condition or available task to check for a file/directory's existence.



I don't think the available works on multiple files.
15 years ago
Hello. I am having a problem with my build script. I would like to copy any new property files from the src/properties/* only if the target/properties/* equivalent does not exist. I want do this for all the files. I thought the copy's overwrite attribute would allow me this flexibility but it is not working.

Also, I want to copy src/libs/*.jar to target/libs/*.jar if the target/libs*.jar does not exist or if the src/libs/*.jar is newer than the target/libs/*.jar equivalent.


Thank you.
15 years ago
I found the problem! The orinigal file is created in another method. I did not close the file before trying to rename. Thank you.
16 years ago
Why isn't it renaming the file?
16 years ago
Hello, I have tried everything from past posts to try and resolve a file renaming issue I am having. Files have correct permissions and exist in different directories at the time the rename is attempted.

Can anyone see any issues with my code? Thank you.
16 years ago
Thanks Craig! Will try this approach.
17 years ago
I have an application that should load an image to be set as an icon for a JLabel from JPEG files. The file names are numbers ie. (0.jpg, 1.jpg, ...) so that i can choose the files with a loop and use the loop index as the image name to be retrieved.
Depending on some user action the picture should be set visible for about 5 seconds, set invisible, unload the image, retrieve the next image and then depending on the user action, show it again for another couple of seconds. The way I am doing it it takes the image a long time to be shown. I thought by loading it before I would actually need it that it would speed things up, but thats not what happens. It takes a long time for the image to visible. I have a resource manager class responsible for creating the images from the jpegs. They also have to be resized so that may be why it is taking so long. Here's the resource class makeImage method.


The load and show picture methods are in another class that defines a picture panel



So if the user action is appropriate then the picture panel should be displayed and another one loaded up. I thought using the SwingUtlities would solve any thread issues. Is there some additional thread sequencing that I should do in order for the action to be faster? Thanks for the suggestions.

[ June 23, 2004: Message edited by: Chris Ramsey ]
[ June 23, 2004: Message edited by: Chris Ramsey ]
17 years ago
Thanks Sachya Joshi,

So the FlashCardSet class is a part of the model layer and not the controller. You are saying that I need a class I'll call FlashCardController that will check the answer and move the flash card to its appropriate list depending on if the answer she gave is correct or not and update the view to report whether her answer was correct or not.
This means that it needs to have a reference to the FlashCardSet, to get the flash card solution to compare her answer with and the FlashCardUI display the result. So is the textfield that she enters her answer in actually a part of the controller layer and not the view, like I was thinking?
I am writing a FlashCard application for my daughter. At the same time I want to learn and implement a design pattern that will allow me to add functionality easily and one that I can re-use for future apps. I've looked at MVC, EventManaging, Visitor and I feel I understand what they do, but it falls apart when I try to implement them. Here's a description of the what I think the classes I have so far and what role I think they play within the app:

1. FlashCardGenerator: (MODEL?)
The FlashCardGenerator class creates FlashCards. It's createFlashCard method is called to generator 2 random numbers and make an addition or subtraction flash card. (multiplication and division to be added later).

I'm not sure whether I should have an actual FlashCard class or a member variable of the FlashCardGenerator since its primarily just a string that holds the numerals, operator and the solution.

2. FlashCardSet: (VIEW of FLASHCARDMODEL?)
I am not sure if this class is necessary. It is an array list that holds the FlashCards generated by the FlashCardGenerator. This way the user can determine how many cards they want to solve for each round. I guess an alternative would be just to loop a call to FlashCardGenerator.createFlashCard method. One reason for having this class it that if any flash cards are answered incorrectly 3 times they are marked as incorrect and stored so that at the end of the round the program will inform her of how many were answered incorrectly and if she would like to try them again. So this class would have two ArrayLists (active and error) The active set holds the flashcard she is currently working on and the error set would house the incorrectly answered cards.

3. FlashCardUI (CONTOLLER TO FLASHCARDSET AND FLASHCARD)
This class has the flashcard panel, the progress panel and the skip and reset buttons. This is where I really want to know which pattern would best fit this scenario.

The basic program flow is this:
a. flash card is displayed
b. flash card is answered
c. answer checked against solution
d. progress panel updated
e. next flash card in set displayed

The skip button allows her to move to the next flash card in the set. The reset button clears the set and asks her if she would like to create a new set of cards. The progress panel has 2 labels (correctLabel and incorrectLabel) that are updated each time she answers the equation based on whether the answer is correct or not. My road block is here. Which class should be responsible for checking her answer against the solution and updating the UI based on the outcome? I have explored creating an AnswerEvent object that would hold her answer and go to some class to be checked against the solution. But again, should there be a separate class that does this? Should the UI class create the answerEvent? Maybe a CheckAnswer class that listens for answers and then returns a status of right or wrong? My thinking is that a design pattern will answer the questions and help me sort out who and where to do what, but which one. Thanks for your patience.

[ June 02, 2004: Message edited by: Chris Ramsey ]
[ June 02, 2004: Message edited by: Chris Ramsey ]
Thanks Ken when I am going to try to work it out this way too.
17 years ago
Thanks Ken. The purpose of my FlashCardApplication class is to connect the UI components to the model. I guess I am thinking incorrectly about how this implements MVC. For example I have a skipButton in the FlashCardUI class. This button should skip the current flashcard show on the screen and retrieve the next card from the FlashCardSet (and arraylist of flashcards) Are you saying that the skipButton is the controller, the FlashCardSet is the model and the screen would be the view in this interaction? Is MVC implemented with each interaction or within the application as a whole. Another interaction is when she answers the flashcard equation. She enters the answer in a textfield. The textfield should pass the value entered to a method that checks her answer against the flash card answer. The view should reflect whether the answer is correct or not. In this interaction would the textfield be the controller?

Allow me to give you more details about my design. Maybe you could help me start thinking and coding in the right direction.

The FlashCard(model) knows how to do the flashcard stuff.
Some of its fields are numeral1, numeral2, equation and solution
Some methods are...
getNumeral1(), getNumeral2(), createEquation(), solveEquation()
Each card has its answer stored in solution.

The FlashCardSet(controller to FlashCard) which extends ArrayList...is a set of FlashCard objects. It holds and manages which FlashCard is presented. Some of its methods are ...
loadFlashCardSet(), getEquation(), skipEquation(), clearEquation()

The FlashCardUI is all the gui components. The buttons, the answerfield, flashCardPanel where the equation is displayed

I want to FlashCardApplication to be where all the pieces fit together. The FlashCardUI class will interact with the FlashCardSet class. When the skipButton from the FlashCardUI class is clicked I want the FlashCardSet class skipEquation() method to be invoked. So would the FlashCardUI.skipButton be a controller to the FlashCardSet.skipEquation() method? Seems like MVC is implemented on a per interaction basis and not by the classes as a whole or is it? The problem is I want the connection between the button and the method to take place in the FlashCardApplication class. Bringing me back to my first question. I'm thinking the FlashCardApplication would have an inner class called FlashCardActionListener that would be an ActionListener. It would be responsible for listening and calling the appropriate FlashCardSet functions when the FlashCardUI buttons are clicked. How would I go about doing this? How can I connect the FlashCardActionListener class with the FlsahCardUI class reference created in the FlashCardApplication class? Should the whole FlashCardUI be an ActionEvent that passes an actionCommand to the FlashCardActionListener class? Am I confusing you, because I think I have just confused myself. Help!

What I want is a connection from FlashCardUI and the FlashCardSet
17 years ago
Thanks Aaron. I would love to check it out and see the source! Thanks alot! I am really interested in how you connected the two. I wanted the actionListener class to be generic enough to handle all events that would occur in the application so I would know exactly where to debug and add functionality. Would that be a good approach or should I just add actionListeners to every gui component on the app? That seems to be the most popular way but it seems like there should be a more efficient approach.

[ May 26, 2004: Message edited by: Chris Ramsey ]
[ May 26, 2004: Message edited by: Chris Ramsey ]
17 years ago
Hello,

I learning the MVC model by building my daughter a flash card application so she can practice when I am not home to practice with her. So far I have 4 classes. FlashCard(model) FlashCardSet(view), FlashCardUI(view) and FlashCardApplication(controller). I'm not sure if these are classified correctly but I am still learning. Since the MVC goal is to keep the UI separated from the model and create the links in the controller, I the controller to know how to update the FlashCard(model) when something on the FlashCardUI(view) is clicked, checked or etc. A class that manages all the user actions of the application where I could connect the model to the views. I guess that describes what the controller's job but I am having a hard time figuring out how to implement it and keep the MVC separation.

Should the UI class expose the swing components to the controller like...


Or can I create some sort of FlashCardAction class that can be passed to the UI? If this is the best way, could you provide some examples? Thanks for helping me impress my daughter and learn a little bit more at the same time.
17 years ago
Is there a way to create an empty border on the JFrame's contentpane, so that when I add components to it the will not be placed flushed with the sides? I would like to do this without having to add a JPanel to the contentpane first. Thank you.
18 years ago
Can someone explain what this does and on what it does it? Does it call the return the main class's class loader to get the resource? Thanks.
18 years ago