Please note that I haven't done Java in like 5 years, so it's a bit rusty.
By default you can't. that is, a static method belongs to the class itself. One workaround is to simply define an argument for your static method.
public static doThing(Object caller) {
//Print name of class...
I'll be honest Billy, I've took up a bit more time then usual on your little problem. But Eureka!
My answer finally came to me when I read this little tidbit
Well, there you go. Hope it's clear what you have to do!
Cheers,
Simon.
Actually, the problem is with the api itself. The method you are calling has been "sorta" deprecated.
That is, what you are using is, AWT tech. Where as your JFrame is Swing tech.
In other words, everything about the JFrame relating to it being a container has been rendered void of use...
Call me old fashon, but if I were you, I'd simply check to see if there are parameters.
if (request.getParameter("firstInteger") != null || request.getParameter("secondInteger") != null) {
//Since I know that there is at least one "thing" entered in the texfields, I can try and add them...
The simple answer is that the last item you inserted in the array "items" was at index "used" as per this line:
items[used] = new GroceryItem();
Now, right below this you call:
used++;
So, when finally you get to line 67, you ask for the "GroceryItem" from "items"...
Well, here's my input on the choices you have.
Save as a text file; Not a horrible idea. You could implement the RTF (Rich Text Format) format and have a pretty descent text editor.
Save the Object itself ie; Serialization: This would be the easiest method to store your file. If would...
Class: The blue print of an Object, it's definition. You code what the Object should be able to do, what it should be, it's very EXISTENCE!!!111. Example, you have the blue print of a Police car. This plan, is in no way a Police car. It's just a few pieces of paper with pictures, designs and...
Your single problem is in your inner class "RedButtonHandler".
public void actionPerformed(ActionEvent evt)
{ Object source = evt.getSource();
Color color = getBackground();
if (source == yellowButton) color = Color.yellow;
else if (source == blueButton) color =...
Unless I am mistaken, Canvas is a heavyweight components? If that's the case, you will be almost unable to mix and match ligthweight (Swing) with heavyweights (AWT).
Your best bet is to remake your class so that it extends JLabel instead.
Cheers!
Without going indepth into your code, the reason you have a little runtime problem isn't related to the getCheckDigit () method as far as I'm aware. It's simply that at that peticular point in time, your argument "zipCodeStr" is null. Thus crashing the app.
Were you to replace "zipCodeStr"...
A plain way to do it is to create a context class for your application. That is, an Object that is accessible to both JFrames.
Let's create a class called "MyContext". He will have two variables; "username" and "password". With the proper getters and setters method of course. Now simply add a...
Well, you can start by giving us a bit more code. From what you posted, everything should be working. But, like I said, you haven't posted much.
Simon.
Well, I am always interested in helping people out.
At first glance, you simply need to use the javax.swing.Timer class. Simply create a Thread that will invoke your GUI's paint method on a timed basis, (every 60 millis) and there's no more to it then that.
If you have a more specific...
In response to your edit.
You need two variables for that. First you need to know the Dimentions of your Frame;
javax.swing.JFrame.getSize();
and then you need to know the resolution of the clients computer;
java.awt.Toolkit.getScreenSize();
Afterwards, a little magic like;
x =...
Well alright, we'll try and get it working so let's try this then:
Put things as they were, meaning that Login extends JFrame.
Now, replace your Main.main method to this:
public static void main(String[] args)
{
Login test1 = new Login()...
Well, that's probably because you have no imports at the start of the file ;)
Wether add;
import javax.swing.*;
or simply extend;
class Login extends javax.swing.JPanel implements java.awt.event.ActionListener {
Cheers!
Simon.
Well there you go,
class Login extends javax.swing.JFrame
You cannot add a JFrame to a panel. You just need to make Login extends JPanel or some other low-level container and you'll be good to go!
Cheers,
Simon.
Off the top of my head, I can't figure out the problem. I'm pretty sure the problem lies in the code that you didn't give us :p
If you could provide us with the code of the Login class, then we could be able to recreate the problem on our own machines. Which would help us greatly in helping...
Well to simply answer your question. When you wish to place a background image centered, the easiest way that I know of using AWT, is to simply draw it at the right place!
Such as;
g.drawImage(image, 0, 0, this);
Instead of drawing it at the top left of the screen, simply make this...
For all intents and purposes, you can easily fix this problem by changing one line of code.Instead of having one line to declare your variables, simply put in this code.
int grade1 = 0;
int grade2 = 0;
int sum = 0;
int average = 0;
Or if you want to keep your code as condense as...
To asnwer the original poster, the preffered way to handle such a situation is to go all the way by changing your InputStream into a BufferedReader. Simply use the readLine function and you can be assured nothing wicked will ever happen.
Well... Just before I leave, I will tell one quick and dirty hack that will allow you to make your program work as inteneded. Note that as far as I'm aware, the trouble isn't in you teachers Keyboard class.
If you are in a windows machine, as soon as you call readChar make a couple of empty...
I was able to find the symtom of your problem, but I am yet unsure of why things are going the way they are.
Here's what happens,
You ask the first question, the user then enters the letter 'y' and presses the enter key.
In the System.in buffer, you have now these chars {'n', '\13'...
How about putting the entire method into a try/finally statement?
actionPerformed {
// change cursor at the start of the method.
try {
//Do your code that could very well go beserk.
finally {
//Revert to the old cursor
}
}
Would this help?
Well yes, what I meant to say is that the code works fine for me. I copy pasted it and when i run it I can see the Thread working. Thus your trouble is something else that is not in the code you gave us.
Well I copy pasted your code and the good news is that it runs fine. So the problem lies elsewhere. If you need more help just post up more code.
Cheers!
No, you never write .java in your imports.
The thing is, if your two classes are in the default package then there is no reason to import them. If your compiler is unable to find the NetMyThread class, it's either that the NetMyThread class is in a different package (check at the start of the...
Glad to hear you got rid of that nasty warning.
So to answer your first problem, you simply have to add an import at the start of your main class.
import NetMyThread;
That is if your NetMyThread class is the same folder and is in your current workspace.
Not easy questions to answer.
1) Well I have three sugestions
-"Are you sure your class name is spelled correctly :p "
-It might probably be a problem with of namespace. Is your other class in the same package as this one?
-Or it could be a problem that you have never successfully...
Being a non-native english speaker, I am entitled to certain perks :cool:
Knowing that forums such as these are viewable all around the world, colloquialism is bound to arise. That cannot be helped. Best hope is to try and read the meaning, not the words. IMHO of course.