John Pisci

Ranch Hand
+ Follow
since Dec 19, 2008
Merit badge: grant badges
For More
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 John Pisci

Henry Wong wrote:Your classes also seem to have a circular requirement... Your btnSaveListener class requires a connect object in order to instantiate it (with no other option to instantiate it). And your connect class requires a btnSaveListener object in order to instantiate it (with no other option to instantiate it).

In other words, both classes require that you have an instance of the other first, or you won't be able to create it.

Henry



I hadn't really thought about it this way and now you've pointed it out, it just seems badly written.

Looking at the connect class, there is no need for me to have a btnSaveListener object in there if the gList object is there. I think I may have added the btnSaveListener object in because I thought that I would need to refer to it to set the lblInfo text (it made sense at the time!), despite there being a gList object where I can access lblInfo directly.

I'll have a play with the code when I get back from work, but many thanks for your help
14 years ago

Henry Wong wrote:
Your constructor takes two parameters. To construct a connect object you must use...

c = new connect(blah, blah);

Where the first blah is a reference to a btnSaveListener object, and the second blah is a reference to a gList object.

Henry



Ohhh I seee... It's obvious when you point it out! I'd forgotten about this bit of code, and didn't even click when I pasted similar code earlier...D'Oh!
14 years ago

Henry Wong wrote:

I'm not sure how I would add a value to 'c' without typing something like c = "1" or "test", which then gives me an incompatible types error.

Apologies for this being a simple error, but I just can't get my head around it!



The "connect" class type is part of your program. You wrote it (or got it from somewhere). If you can't figure out how to instantiate one, how do you expect us (who don't even know what it is) to tell you?

Henry



Yes I did write it.

I appreciate that what I asked was basic, but we all start somewhere- you were a beginner once too, so please, try not to patronise me.

I have tried adding "connect c = new connect()" to my actionPerformed method, but I got the 'cannot find symbol' error again. I got past this last time by adding the following, so now I am confused!:


My full connect method:
14 years ago

Henry Wong wrote:

I'd create a new btnSaveListener by typing "btnSaveListener bsl = new btnSaveListener()", but that would still be null, right?



If you did this, then you still have compile errors... please don't run you code until you get rid of all of your compile errors.

Henry



How do you know you've got rid of all of the compile errors until you have compiled?
14 years ago

Rob Prime wrote:No, I meant was: how do you create new btnSaveListeners? Because if you pass null to the constructor, then the reference stays null of course.



I'd create a new btnSaveListener by typing "btnSaveListener bsl = new btnSaveListener()", but that would still be null, right?

I'm not sure how I would add a value to 'c' without typing something like c = "1" or "test", which then gives me an incompatible types error.

Apologies for this being a simple error, but I just can't get my head around it!

Thanks!
14 years ago

Rob Prime wrote:

John Pisci wrote:
I thought I had instantiated it with the "this.c = connect;"


And how do you construct your instances? Are you sure you're not passing null to the constructor?



Would I have to add in "c = new connect()" in the actionPerformed method?
14 years ago

I thought I had instantiated it with the "this.c = connect;"

My btnSaveListener class.
14 years ago
I added it, like you said but I'm still getting the same error.

I wasn't sure if I had to pass something into my dbConnect() method or not?
14 years ago
Hi Folks,

My app finally compiled ( ) and I then launched it.

I filled out all of the fields in my GUI and clicked the 'save' button and was very excited until I got the following error

Any help is greatly appreciated!



Looking at that, I'm pretty sure that the error is in the following line of code as it is line 88 in my btnSaveListener class:


My dbConnect method is as follows:
14 years ago

Campbell Ritchie wrote:Maneesh is right, but GridBag is often hard to learn. Google for MigLayout, which I have never used, but is supposed to be much easier to use. Or have a look at the Other GridBag Tutorial

But beware of trying a null Layout. That will give all sorts of problems if the Frame is resized; the lower or right Components may drop off the display altogether.



I can vouch for Miglayout- it is very easy to use and even easier to understand. I think they are trying to get it included in the next java release too.

Despite Miglayout being easy, I am still going to have a go with GridBag because different styles are more suited to different situations with different requirements.
14 years ago

Henry Wong wrote:

Have another problem know though; one that just randomly appeared. I don't know why, but it has been working.



Stuff like this don't randomly appear. If it has been working, then this is caused by something that you changed.

By chance, did you happen to change the constructor of the btnSaveListener class? Maybe added a few parameters?

Henry



Yep It was a bad java day yesterday!

This is the 'before' code which worked:


The 'after' code that doesn't work:


How would I get this to work?

I can't imagine it would be as simple as doing this?!:
14 years ago

Fred Hamilton wrote:exactly. Readability and maintainability. And in addition to considerations about how much work you want your event handler (actionPerformed) to do, also one can think about the degree to which the application is "classified".

Just seeing this one class which is little more than an event handler leads to believe that you might end up with a real proliferation of classes. If you wanted to be able to use this particular listener/event handler with other applications, then your idea is pretty good. If the listener has no use outside of the current application, then maybe it's not so good.

In my programs, I usually have a main GUI class that includes most if not all of my listeners and event handlers, and the event handlers themselves are very minimal, often just a method call, and the method is in another class. This approach serves to separate functionality from presentation.

Again, this sort of stuff is more a question of style, readability, maintainability. You know your program best, so it's for you to decide these things, I'm not saying what is best, just pointing out a few design decisions you need to make. I haven't done much database work with java, so maybe that influences general application design.



That makes a lot of sense, I'd not really thought about doing it that way.
This is my first java app. with a GUI and a database and to be honest, I think I've made quite a few design mistakes. Saying that though, it is the best way to learn.

Have another problem know though; one that just randomly appeared. I don't know why, but it has been working.

When I compile, I get the error:


gList class:


btnSaveListener class:
14 years ago

Fred Hamilton wrote:

Henry Wong wrote:

I get the following error for each and everyone of the variables:



Each and every one of those variables are *local* variables of the actionPerformed() method. They are not in scope outside of the method.

Henry



It seems to me there some questions of programming style here also?

We have separate class for just an action listener and little else. (btnSaveListener) And that class is doing a lot of work with a lot of different variables. It seems that is a scenario that invites trouble. Sure you can make it work, but...

Maybe there are reasons for doing it this way, I don't know. There's always different ways of doing things. But I like to keep my action listeners much cleaner than what is shown here, and rely more on appropriate method calls.



I hadn't thought about just using the action listener to perform method calls.

Will the performance be affected doing it the way I am? Or is it just a personal preference to have clean action listeners?

As you can tell, I am learning, but I appreciate all of the advice I can get!
14 years ago

Henry Wong wrote:

I get the following error for each and everyone of the variables:



Each and every one of those variables are *local* variables of the actionPerformed() method. They are not in scope outside of the method.

Henry



As soon as I read this, I realised what I was doing wrong! Thanks!

I have now declared the variables outside of the actionPerformed() method.

Now on to the next set of errors...
14 years ago
Thought I'd may as well just bump this thread instead of creating a new one as it is a similar problem.

Anyway, I have an action listener for a button that gets all of the info in the fields of the GUI and assigns them to variable. This then calls an SQL method which performs the SQL insert.

I am having trouble with getting the variables from the action listener into the SQL insert method.

Thanks in advance!

I get the following error for each and everyone of the variables:


action listener:


SQL class:
14 years ago