Timothy Hoyle

Greenhorn
+ Follow
since Oct 12, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
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 Timothy Hoyle

So, once again I am pulling my hair out trying to figure this out. I have a budget GUI that enters expenses into a JTextField where it is compared against other values and calculated.

The point is though, I have an array of JTextFields which I can currently navigate via the tab shift/tab keys. However, I want to be able to also navigate the textFields in the array via the up/down arrow keys. Should I use keyListeners of KeyBindings and what is the difference?
14 years ago
Stanislav,

Works great, thanks for the help.

Regards,

Tim Hoyle
14 years ago
Hi,

Once again, I have been pulling my hair out searching the web for the solution to this, all to no avail.

So I ask youguys, how do I resize my JFrame during printing so that it prints the whole JFrame? I am asking because I have a JFrame that when printed using graphics2d and a printerJob(), prints only the top left corner of the JFrame, while I want it to print the whole thing without cutting it off.

If someone could at least point me in the right direction I would be very grateful. Thanks in advance.

Below should be all of the relevant code.

14 years ago
Pete,

Thanks for the remarks. Though this project is for an app. to handle my personal budget, I am going to school online for software engineering, and as a result I do not get much of a chance to interact with other programmers to talk about problems and programming rules.

In fact, I do not know any programmers personally, other than the ones I chat with online.

Regards,

Tim Hoyle
14 years ago
Pete Stein,

I wasn't sure if you were initially just being a smartass or what. My suspicion was that you were in fact not being a smartass, but it just seem to come off that way. I am not a person that is really interested in throwing insults back and forth, so I apologize.
Back to the problem at hand. Why is it a bad idea to reference a static variable in the testing class?

Also, what are some ways to reference the the active JFrame itself? Are there any good links you could recommend? Thanks in advance.

-Tim Hoyle
14 years ago
Rob,

Here is the stack trace when the program does not work:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Budget.budgetFrame2$printHandler.print(budgetFrame2.java:635)
at sun.print.RasterPrinterJob.printPage(RasterPrinterJob.java:1786)
at sun.print.RasterPrinterJob.print(RasterPrinterJob.java:1335)
at sun.print.RasterPrinterJob.print(RasterPrinterJob.java:1197)
at Budget.budgetFrame2$printHandler.actionPerformed(budgetFrame2.java:648)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:5517)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3135)
at java.awt.Component.processEvent(Component.java:5282)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3984)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3819)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1791)
at java.awt.Component.dispatchEvent(Component.java:3819)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
BUILD SUCCESSFUL (total time: 1 minute 16 seconds)

Here is the code in the MAIN class when it produces the stack trace above:




Here is the code in the MAIN class when it does work. Notice the variable assignment line (BudgetFrameA = BudgetFrame - the last line) that is not present in the error producing code:



Here is the code in the "content" class that will not work: (notice the lines budgetFrameTest2.BudgetFrame.printAll(g);)




Here is the code in the "content" class that will work: (notice the lines budgetFrameTest2.BudgetFrameA.printAll(g);)




Why the heck does it matter if I plug the object instance BudgetFrame into a variable named BudgetFrameA and reference the variable? Why can I not just reference the object instance directly instead of plugging it into a variable? This seems like alot of busy work to me.
14 years ago
Pete and Rob,

Okay, so I fixed the problem, but I fixed it in a way that still leaves me with questions.

Basically, I have two classes, a MAIN class to run everything, and a class that holds all of the contents. In the MAIN class I create an instance of the content class called BudgetFrame. When referencing the BudgetFrame from the print() method directly, it gave me a NullPointerException. However, when I create a static variable in the MAIN class and then make the staticVariable = BudgetFrame, and reference the staticVariable from the print method, it works fine. Any ideas on why this works?
14 years ago
I am self-admittedly not a great programmer due to my inexperience, but I never cease to be amazed with my fellow programmers' abilities in pointing out the obvious.
What I know of people, is that when they ask a question, they are asking for possible ideas of what could be wrong, or to be at least pointed in the right direction so that they may find the answer themselves.

Like I said Pete, I am not by any means a good programmer, but a reiteration of the problem is definitely not going to help in the least. Do you have any ideas why my object may be returning "null"?
14 years ago
Hi,

I am having trouble printing my JFrame with a printerJob. I have been trying to figure this our for awhile on my own, so this is my last resort. If someone could at least point me in the right direction to get answers, that would be great.
Thanks in advance.

P.S. This slice of code keeps giving me a NullPointerException on the call to budgetFrameTest2.BudgetFrame.printAll(g)

14 years ago
Rob,

Thanks for the tip, I am using a MatteBorder and it is working like a charm.

Regards,

Tim Hoyle
14 years ago
Hi,

I have been creating a border for my JLabels from the LineBorder class. Right now I have my JLabels using and instance of createGrayLineBorder(). However, I would like my borders to only show up on the top and bottom of my JLabels, not on the right or left. (so an empty JLabel would look like two horizontal, parallel lines over a box)

I have searched on the internet for awhile, but my search has been in vain. Anyone know of a good link that explains how to accomplish this?
14 years ago
Okay, so this is my predicament, I have two columns in a text file that I want to read. They are for a budget program, so they go like this:

Col 1 Col 2

Savings $100.00
Groceries $100.00
Gas $150
etc. etc.

I want to read these values back into my budget program using a Scanner. However, I only want to read the second column, I want the scanner to skip the first column, always, because I want the numeric values read back into my budget application. Is there some way I can use nextLine() or next() then skip, then nextLine(), then skip, and so on?

Maybe a link explaining the process would work.

Thanks in advance.

Tim Hoyle
14 years ago
On related note, I noticed that java's Formatter class has a Flush() method. What does a Flush() method do?

I am just learning streams and my best guess is that flush somehow cleans out the stream you just used? But what does it clean out?
14 years ago
Campbell,

Well, if you must insist, the reason that I am testing the location of the source by if (e.getSource == saveButton) is simply out of habit. You see, I have arrays of JButtons that are connected to 1 or 2 other handlers further up in the code so I have to test for which particular JButton within an array of JButtons.

So really, as you pointed out, I do not need to test for the source in this save handler, and I will probably end up taking it out.

While we are on the subject, you mention that by testing for the source I am tying the class to a particular implementation. (which I am assuming you mean that I am creating a whole class for one button)
What other reasons make testing for the source a bad idea? I am curious because I am a beginner.

Fred,

I did use the <code> tags for my code, or at least I thought I did. Either way, the code appears indented now. Was it not before? Additionally, you are probably right about tying the code to the vista operating system. Doing so would deny cross OS compatibility, which Java was created for, to my knowledge.
However, I posted this question before I found that the JFileChooser class existed. What a pleasant surprise it was to find that class! Even if I did not find it on my own, you annd everyone else pointed me in the right direction anyway, so "thank you" to you all.

Now, I have another question. I know that we can wrap a FileWriter in a BufferedWriter, but I want to control the way that my strings are written to the .txt file. Is there any way I can wrap a formatter in a bufferedwriter? or is that not possible? I would love to be able to do this:

<code>
BufferedWriter bw = new BufferedWriter(new Formatter(file));

for (int i = 0; i < someNumber; i++)
{
bw.format("%-20.25s",labels[i].getText());
}
</code>
14 years ago
Hi,

I have my budget application that saves my current budget information in a pre-specified file in a pre-specified location. However, when I click my save button I want it to open the windows vista save dialog so that I can choose the name and location from there instead of have the name and location pre-specified in the source code. Any idea where to start on getting this accomplished and any good links that will explain the process? I am using java SE, if that makes a difference.

Here is the code with the pre-specified file name and location: (just for informational purposes)

14 years ago