File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Problem in jdbc with swing (old wine in new bottle) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Problem in jdbc with swing (old wine in new bottle)" Watch "Problem in jdbc with swing (old wine in new bottle)" New topic
Author

Problem in jdbc with swing (old wine in new bottle)

Mandar Khire
Ranch Hand

Joined: Sep 11, 2007
Posts: 492

i asked already question in 3 questions regarding JPanel.
I stuck in position where i need to stick with mysql but do some thing in mouse released event.
i (always ask) & Michael Dunn(always give answer) try to solve it, but at point where db is unavoidable then he get step back.

here i want to note that this topic is not duplicate...i just try to ask same question where jdbc experts...might again moderator block this question like few days before...

here i post my question again if anyone not want to go different thread
here is code for 2 small jpanels within jpanel,with functionality of

1.we can drag & drop any where those small jpanel within big jpanel.
2. We can store their x,y values in mysql database table.
3.We can not drag jpanels beyond jpanel.(we can not do x<0 or y<0)
4.If we not drag jpanel anywhere after running program just run mouse pressed & released event, panel not goes at default x,y. So user can press & release as much as time want without dragging.
5.by just changing integer withing [] at 2-3 positions we can create as many jpanels we want. & all are getting all fuctionality we added in this program.

just save Addp.java & create manually mysql table 'panel_location' in database name 'manadardatabase'






now problem description...
there are 2 problems, might be there will be more but i identified 2.
problem 1. If you remove following code(in above code,code line number 271 to 286) from above code then 'avoiding of overlapping jpanels' active other wise i dont know how it not work due to somewhere i done mistake in following code.
so for this final problem is it necessary to work both functionality combined.,how?




problem 2
step 1. If you run complete code then if you drag any jpanel & released it, it stay where you released it(its good)(old position != new position )
step 2. but again you press & released without moving jpanel from its position(just click & released) then it goes to original position(old position)!(its bad)

This 2 problems are there...i tried after it,in mouse released event as follows


Now my one problem solve by my own efforts (problem of mouse press & release without moving jpanel it went to default location or x,y became 0)
Now if i get small help regarding jdbc then my problem solve...
i think if result set or table get refresh then when i try to retrive values of x,y from table , they are not updated one...(anArray_newx[],anArray_newy[])
means when i run program, both values came from table...then i drag & drop jpanel, x,y values update( manually i can see mysql table) but these two (anArray_newx[],anArray_newy[]) containing old values only...
how i can refresh those two?


Millions saw the apple fall, but Newton asked why.
Bill Johnston
Ranch Hand

Joined: Nov 17, 2005
Posts: 201
Is this about storing the location of JPanels in a MySQL DB table? I think that is a very bad idea. If that's not what this is about, can you explain your main problem again?


~Bill
Mandar Khire
Ranch Hand

Joined: Sep 11, 2007
Posts: 492

Is this about storing the location of JPanels in a MySQL DB table? I think that is a very bad idea.

I know its true...but
explanation:-
I wanted actually
1. I have to create 1 frame which contain JTabbedPane which tabs should create by array
2. In each tab i have to create small jpanels (those also an array) Now my screen contain almost 99 jpanel at a time with some free space (1280 x1024 resolution) but i will create 50 so i can get more free space.
3. small jpanels x,y axis should store in mysql db(old (before drag)& new(afterdrag)).
4. If i have to create 100 small jpanel...then i will create array of tabs 2, & each contain 50 jpanels
5.Each small jpanel have to drag & drop facility with fuctions:-
a. It should drag & drop any where in screen but not beyond its container
b. When ever as much time if program restart jpanels should placed same position as they kept on before restart.
c.They should not overlap with each other as any condition.
d.when system resolution changes program should grab that resolution & adjust it self.
e. If i manually change db & set values equal to or less than 0(x,y) then at time of program start, it should check & set default location (say eg. 10,25).

Now current situation
I am not full knowledge of swing & jdbc with mysql
so i try first 1 frame with big jpanel which contain 9 small jpanel & try to full fill 3rd & 5th requirement.

Again i come to today's situation
Yesterday i write following
problem 2
step 1. If you run complete code then if you drag any jpanel & released it, it stay where you released it(its good)(old position != new position )
step 2. but again you press & released without moving jpanel from its position(just click & released) then it goes to original position(old position)!(its bad)

&
Now my one problem solve by my own efforts (problem of mouse press & release without moving jpanel it went to default location or x,y became 0)
Now if i get small help regarding jdbc then my problem solve...
i think if result set or table get refresh then when i try to retrive values of x,y from table , they are not updated one...(anArray_newx[],anArray_newy[])
means when i run program, both values came from table...then i drag & drop jpanel, x,y values update( manually i can see mysql table) but these two (anArray_newx[],anArray_newy[]) containing old values only...
how i can refresh those two?

After posting that till now i try & solve that problem my self by creating function which contain 1 reultset(now program contain 2 reultset[1'st for fetching values to set jpanels at start of program & 2nd for fetch values which changes at time of running program] & it call after function(parameters stores in db) call.
So if i mouse press & release without moving jpanel at any time,it not goes to x,y=0.
if i mouse press & released on any panel without moving it after drag & drop any panel, it not goes to different location(yesterday it goes to 1'st resultset values).
Now only overlapping of jpanels are problem...
i try to write code but by that only last jpanel (last array (array[9] then 9th)) implement that code & if i drag any jpanel over it then that jpanel placed near to it not overlap it.
but for others that code does not work.(means i try to overlap panel 1 on 2,3,4,5,6,7 then it overlap not try to avoid it same for others also)
I am posting what i done in mouse released event (in which i done changes from yesterday)

same time i post new fuction which i write yesterday

in 'panel_parameters' function after executeUpdate i call this 'temp_resultset()' function So
by doing this my one problem solve no just overlapping problem remains.

If i success doing all this with 9 small jpanels within big jpanel then i will shift to what i want actually which i explain above.
Now i think total scenario i explain in my words...in this post you can read all reference how i reach till now, i posted that also...
i asked already question in 3 questions regarding JPanel.
Bill Johnston
Ranch Hand

Joined: Nov 17, 2005
Posts: 201
Mandar Khire wrote:
Is this about storing the location of JPanels in a MySQL DB table? I think that is a very bad idea.

I know its true...but
explanation:-


Mandar, I hope you won't take this the wrong way, but I think you are posting way too much information for people to wade through. Can you describe in a sentence or two or maybe three why you want to put coordinates of GUI Components into a database table? If it's really needed to save the state of the Graphics - something that is not at all unreasonable to do - you probably should be using Preferences:
http://docs.oracle.com/javase/6/docs/api/
... or Properties:
http://docs.oracle.com/javase/6/docs/api/
But I don't think this either of these would be good options for some 99 Component coordinates really. Have you looked into Object Serialization?
http://www.java2s.com/Tutorial/Java/0180__File/Savingandrestoringthestateofclasses.htm

Regards,
Mandar Khire
Ranch Hand

Joined: Sep 11, 2007
Posts: 492

Thanks Bill Johnston,
As you said...
I think you are posting way too much information for people to wade through.

I join this forum from 2007 when i was in collage...people answer questions correctly which helpful.So i try to become same as that people. & same time i learn also...now after 2-3 years gap i got chance to do a small swing program...so i need to do properly & thoroughly.
Now
Can you describe in a sentence or two or maybe three why you want to put coordinates of GUI Components into a database table?

Actually my jpanel's program has to attach to big program which contain threads/struts/socket & internet protocols etc heavy topics included. So in that program all things goes to mysql db. So i thought its easy to add 1 table in lots of table in that db!

I never read about Object Serialization...or i forgot...now 1 or 2 days i read & try it.

something that is not at all unreasonable to do

When in big project security comes in picture then, as per my knowledge SQL provide better security than others...may be i wrong...But no special reason to store db...Is that wrong?
Bill Johnston
Ranch Hand

Joined: Nov 17, 2005
Posts: 201
Mandar Khire wrote:When in big project security comes in picture then, as per my knowledge SQL provide better security than others...may be i wrong...But no special reason to store db...Is that wrong?


I admit to you that I did not read most of what you posted because it was just to much for me to wade through. But since you agreed with my summation earlier, I thought I had a basic understanding of why you wanted to save the state of your GUI in a database. I still think this is a bad idea.

And unless I misunderstand you now, I can't see any reason why security enters into it. You DO want to secure your data. Why do you need to secure the state of a GUI? Obviously you don't want the state sitting just anyplace so that an end user can mess with it. But it's not particularly sensitive data is it?
Mandar Khire
Ranch Hand

Joined: Sep 11, 2007
Posts: 492

Why do you need to secure the state of a GUI?
But it's not particularly sensitive data is it?


Explanation:-
You are partially right...but program which i posted is just demo program to ensure that concept which comes in the mind, is really works or not...so i done 1 small program...
when it will be attach that small jpanels has to work as some important task,
for eg.(this example is purely example which not relate with my project) when we attach pendrive to pc then 1 jpanels should come in to the screen & when we copying file in to the pendrive then that small jpanel should set background yellow...we can drag it to anywhere in screen etc etc....

Now if in project all data(any variable) stores in db then how i can avoid it.
I agree with following statement
I still think this is a bad idea.

If i understand & can prove Object Serialization is better than db of gui then....might be change the scene.
Bill Johnston
Ranch Hand

Joined: Nov 17, 2005
Posts: 201
Now if in project all data(any variable) stores in db then how i can avoid it.


Data gets saved to the database. Data meaning person's name, ID, customer number, quantity purchased, date and time of purchase, date and time of office visit, payment date, stock bought or sold and quantity, student course enrollment date and course number ... all that sort of thing.

But regardless of how the GUI gets changed - with a pen or anything else - store that feature and coordinates in a database table? The data - things like I mentioned above - gets saved in the company database, not in the customer's database. But a GUI would run on the user's/customer's/office personel/employee's computer, not the companies. So any trivial settings get save on that computer/tablet too. Would you expect them to have a certain database or to set one up? No, it has to be transparent to them.

If I am still missing your main point please correct me.
Mandar Khire
Ranch Hand

Joined: Sep 11, 2007
Posts: 492

Bill Johnston,
If I am still missing your main point please correct me.

Yes...forget about Object Serialization Vs GUI co-ordinates utilization by database...
by doing this my one problem solve no just overlapping problem remains.
Martin Vajsar
Sheriff

Joined: Aug 22, 2010
Posts: 3610
    
  60

Mandar Khire,
Your post was moved to a new topic.
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

we are currently storing the users preferences on the database. why?
because the users hot desk, so storing them on the PC would be nonsense.
We are not storing co-ords but values like east or west. 1st page 2nd page 3rd page.
why would we want 100 files littering the server?
Mandar Khire
Ranch Hand

Joined: Sep 11, 2007
Posts: 492

Thanks Wendy Gibbons,
we are currently storing the users preferences on the database. why?

My whole program is just try to bring thought's in reality...its not have specific answer for why!
Might be i am wrong...
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

Mandar Khire wrote:Thanks Wendy Gibbons,
we are currently storing the users preferences on the database. why?

My whole program is just try to bring thought's in reality...its not have specific answer for why!
Might be i am wrong...

sorry Mandar my question was aimed at all the people who were saying we shouldn't be storing this information on the database, not you.
Bill Johnston
Ranch Hand

Joined: Nov 17, 2005
Posts: 201
Wendy Gibbons wrote:
Mandar Khire wrote:Thanks Wendy Gibbons,
we are currently storing the users preferences on the database. why?

My whole program is just try to bring thought's in reality...its not have specific answer for why!
Might be i am wrong...

sorry Mandar my question was aimed at all the people who were saying we shouldn't be storing this information on the database, not you.


I think that would just be me, wouldn't it? ... in which case I replied in that "other" topic Martin Vajsar moved this over to.
Mandar Khire
Ranch Hand

Joined: Sep 11, 2007
Posts: 492

I think that would just be me, wouldn't it?...

No pointer is not towards specifically for you...I think so...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Problem in jdbc with swing (old wine in new bottle)