This is my code so far:
Don't write this sort of thing:-For the GBC class, look here.
Write this sort of thing:-
First one is this. You have an inner class
but if you look at that class, you do not implement an ActionListener at all! You do have a method 'actionPerformed', but that is unrelated to this class.
Another problem is that you have a constructor of your class 'Swing' that is part of your outerclass 'JVactionalRental'.
And I notice an error that occurs quite frequently:
You have a class A that extends B, but in your constructor you define yest another B. For instance:
And finally for now:
if you add a component (a panel or a button) to a frame, then it is added to the center panel of the contentPane. If you add another component to your frame, then it replaces whatever the center of that contentPane contained. So take care of that!
And you need to set a FlowLayout once, not every time. To make the process a little more clear, use:
But I'm still getting an error that says "is not abstract and does not override abstract method" and I got a new one that says "non-static variable this cannot be referenced from a static context". I tried making the first class a static class and it fixed that error but created more in return. Can you please help me with this?
this looks much better!
Still some errors:
1) the method to override is called 'actionPerformed', with a capital P. If you are using an IDE, it will warn you that you are not overriding anything.
2) There is a '}' at the end of your code, that has no counterpart. Your IDE (if you use any) will indicate that for you.
3) And lastly:
With these improvements, your code does rn, but I doubt if you will be very pleased with the way your frame looks! But that for some other time
Maybe all those errors are caused by failure to indent the code consistently, so you can't readily see which class you are in.
Piet Souris wrote:There are more serious errors. . . . . You have an inner class . . . You do have a method 'actionPerformed', but that is unrelated to this class. . . . a constructor of your class 'Swing' that is part of your outerclass . . .
When I tried the code I didn't get any error messages about the actionPerformed method. But having that method in the wrong place would cause an error message about
class XYZ is not abstract and doesn't override method pqr.
But OP is using the @Override annotation, which should highlight that error. In view of the other errors you mentioned, I wonder whether we are seeing exactly the same code; even the tiniest differences if the code is not copied with ctrl‑C—ctrl‑V can cause us to get completely different compiler errors.
Piet Souris wrote:. . . the method to override is called 'actionPerformed', with a capital P. . . .
But I agree: it was a little confusing. But after repairing these small mistakes, the code ran nicely.
I hope OP will let us know if he/she got it running as well.
I got suspicious because I was getting different error messages.
Piet Souris wrote:. . . . I got several errors, the most important one being that you cannot access an instance variable from a static method . . .
1) JVacationFrame is not abstract and does not override abstract method 'actionPerformed' et cetera
2) at the @Override: method does not override or implement a method from a superclass
3) JVacationFrame v = new JVacationFrame; should be 'JVacationFrame v = new JVacationFrame();
3) last line: the '}' is superfluous
No sign anymore of calling an instance member from a static context, I may have dreamt that part...
So that took just a couple of seconds to repeair, after which the code ran fine.
But now I'm trying to get the "price" Jbutton to display whats in the finaltotal textfield when pressed. I tried parsing but it still gave me the error "int cannot be converted to String".
Here is the code I used:
Thanks for the help everyone!