Dave Johnson

Ranch Hand
+ Follow
since May 25, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Dave Johnson

Sorry I am so late but thankyou very much Brian!!!
21 years ago
Got this app that is clock. I want to put the clock into my program as part of the exsisting layout. The clock is currently a JFrame I want to the clock as a JPanel instead.
Here is the code:

Could anyone show me what alterations are necessary to the code? Also what code is needed to add it to the JFrame on the main program i.e. will I need to setSize() or anything?
Thanks, Dave.
[ January 07, 2004: Message edited by: Dave Johnson ]
21 years ago
Hi everyone, I am playing around with sound files (wav) in my code. I have managed to get audio files to work in an Applet but not an Application yet.
Could you please be so kind as to show a small application that plays an audio file.
Ideally I will write it as applet/app later. But for now could help get me started please.
Thanks, Dave.
21 years ago
Thankyou Ernest, I had not heard of that method() before.
I'll have to read up on it.
Thanks for sorting this out. As to be honest I have sorted lots of the problems on my own, but that one had me stumped.
I love this place.
Thanks again, Dave.
21 years ago
Hi I am experimenting with my code, learning quite a bit about Layout managers, one way or another.
I have a BorderLayout for my main manager. This puts a JToolBar in the north zone. A Gridlayout JPanel in the west zone. A GridLayout JPanel in the center zone. A GridBagLayout JPanel in the east zone. A FlowLayout JPanel in the south zone.
When the program compiles and runs, it looks fine, room for improvement but okay for now. The problem is that there is a cancel JButton on the JPanel in the east zone. When this is pressed it resets the program to the state it started in.
The program does this, with one minor problem. When the program resets the JPanel in the south zone now sits lower than it did originally. Once one of the buttons in the JPanel in the west zone is pressed it aligns correctly again. It's just for the first stage of reinitialization of the application.
To be honest, I would imagine it would be easier for you to just run the code & see the error for yourself.
There are 5 classes, however I am quite sure it is the first class BarTill that needs altering.
BarTill

ChoicePanel

SubChoicesPanel

TillPanel

Details

I would be extremely grateful if some could run this and tell me why I have got this problem.
Many thanks, Dave.
21 years ago
Is there anyway of aligning text in JTextArea? Looking through the API it doesn't seem as though the class has anyway of doing so.
If I show you a example of output it might demonstrate the problem:
line8 count8 cost8
line9 count9 cost9
line10 count10 cost10
What I would prefer is this:
line8 count8 cost8
line9 count9 cost9
line10 count10 cost10
Is this sort of allignment possible?
21 years ago
The answer I was looking for was:
NumberFormat formatter = new DecimalFormat("0.00");
Thanks to Tanja again
21 years ago
Thanks again Tanja, your a real help.
One other question. Using this code that Tanja kindly supplied, I noticed that if you add 3 + 1.5 you get 4.5. I want it to display 4.50 instead. Any ideas?
21 years ago
Thanks Tanja & welcome to JavaRanch.
Is there anyway of actually formatting the actual double ddd instead of creating a string version number and formatting that?
[ January 04, 2004: Message edited by: Dave Johnson ]
21 years ago
Here is some code:

The result of this is: 7.1499999999999995
Where as I would have wanted the output: 7.15
I have that NumberFormat or DecimalFormat offer help with this. What I want is an example showing how these classes would work in something like the above code. So if you could add the missing code to the above or know a good link apart from the API please tell.
Thanks, Dave.
21 years ago
I'm not sure why you can't get running.
I wrote them in this order: 1. BarTill, 2. ChoicePanel, 3. SubChoicesPanel 4. TillPanel.
But as Bartill has the main method(), that will have to be run.
Hope that helps, Dave.
21 years ago
Here is the class which I am struggling with: SubChoicesPanel

There are other classes used which I'll put at the end. The class generates a CardLayout of JPanels. There are plus & minus buttons, as these are pressed the JLabel increments & decrements accordlingly. So far so good. The problem is that this panel then redraws another panel TillPanel and updates the tally accordingly. i.e. if the user selects bitter the JLabel incements 1 and the tally in BillPanel increases, the output isn't quite right. I think that my next step would be to make the arrays plus, minus etc into multiple arrays, this would help accesing them.
I am aware that this is a long piece of code & understand people not wanting to get involved in it. It might be easier to just run it to see what I mean.
Here are the other classes:
BillTill

ChoicePanel:

TillPanel:

Any constructive advice would be gratefully received.
Thanks, Dave.
21 years ago
I could have used monospace font aswell (damn I'm slow!).
21 years ago
Got it, isCellEditable(int row, int col). Seems to stop any altering. Right I'm off to bed, so I can be up nice & early & drive myself mad with GUI's. Thanks again, Dave.
21 years ago
JTable sounds like a good idea Ken. Only problem I can see with JTable is that the fields can be edited & it doesn't inherit setEditable(). Maybe there is an equivalent in JTable, I'll keep reading the API.
21 years ago