Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
08-15-2005, 03:32 PM
|
#1
|
LQ Newbie
Registered: Apr 2005
Location: Brussels, Belgium
Distribution: Gentoo
Posts: 17
Rep:
|
Java Swing Card Game
Hello
Im a high school student doing a self study AP computer science class... (means... i show up and take the test... how i learn it all is up to me) and the lanuage being tested is Java. I was recommende to start with python 6 months ago and i got reasonably comfortable with it. The learning ends up being merely syntax, but where i am having trouble is my two side-tracked projects:
1) Card Games.... the engine i have no problem with... its the GUI thats killing me... Swing is the main toolkit I'm using. Working with Listeners and creating cards that can be moved.
2)Databse management front-end... a little longer term project (requested by my father.) Theres a databse with 170 members grouped into zones, and then in each zone districts, and then in each district, partners. at the moment, my father has a big whiteboard with a magentic card for each person. The groups get switched every 6 weeks, so this is pretty common task that is done. What i would like (eventually) is to recreate the white board in a card game like fashion (hence... this being project # 2)... and eventually allow for a card to be selected and the information from the database displayed. Big project, and the engine is relatively simple... its just a big GUI problem for me.
I learned from the GPL'd "How to Think Like a Computer Science" which has been translated into both python and java. It doesnt cover any GUI functions.
My school gave me another book... "Learn to Program with Java" by John Smiley... its crap... really is... it covers a bit of Listeners and GUI, but its mostly... "Heres what we are going to do, heres the code to do it...* Explain different parts of code...somehow assume that a program that calculate GPA is the only thing anyone is ever gonna want to create*"
I really enjoyed the GPL book above... it taught well... and who cant enjoy well done GPL work....
so what im looking for is a good guide to Swing that will explain a little more theory rather than just giving me the code.... although if i ahd to, im sure if i had some code to look over i could figure it out....
big post... thanks for reading it at least...
thanks
|
|
|
08-15-2005, 05:47 PM
|
#2
|
Member
Registered: Apr 2005
Location: Los Angeles
Distribution: openSUSE / Ubuntu
Posts: 294
Rep:
|
Try one of the Dietel books on Java. They're very comprehensive and with many good code sections.
HTH!
|
|
|
08-16-2005, 08:55 AM
|
#3
|
Senior Member
Registered: May 2002
Location: Horsham Australia
Distribution: elementary os 5.1
Posts: 2,479
Rep:
|
well, if you are taking Computer Science A (or took- I dunno, not clear in the post) Don't assume that CompSci AB is just the next step (woah... it's way on.) Also the A is totaly not gui oriented. my problem with the test was that gui was WAY cooler to learn than the other stuff- (sigh- got a 1) (stupid macuser tendancies) Don't worry about swing for the test (unless, of course, you have taken it- how did you go? now is the time to swing)
If you can get your hands on Sam's Teach Yourself Java in 21 days, chapters 8-12 cover gui stuff. swing is fun. you need to learn about frames, panels, layoutmanagers and components. There are also lots of gui tutorials online- Sun's stuff is good.
http://java.sun.com/docs/books/tutor...ing/index.html
titanium_geek
Last edited by titanium_geek; 08-16-2005 at 09:01 AM.
|
|
|
08-16-2005, 12:08 PM
|
#4
|
LQ Newbie
Registered: Apr 2005
Location: Brussels, Belgium
Distribution: Gentoo
Posts: 17
Original Poster
Rep:
|
Basically... My school doesnt offer AP comp sci... I just figure that if im gonna learn Java (which i was planning to do anyway) I might as well take the AP test (Preferably AB.) Im working on it now because i have a ridiculous School Schedule (International Baccalaurette... if it means anything... its jsut an international version of AP... except I take 7 AP level courses)... So my test wont be until April/May. Right now i just want to have some fun messing around... get comfortable. When I get closer to the test date, I'll leave GUI alone and focus on the core.
Ive checked out suns site and i have no probelm creating the GUI... im just having trouble creating Card-like Images (or Panels?) and tying in their location into the engine through Listeners.
Last edited by kermitthefrog91; 08-16-2005 at 12:11 PM.
|
|
|
08-16-2005, 12:31 PM
|
#5
|
Senior Member
Registered: May 2002
Location: Horsham Australia
Distribution: elementary os 5.1
Posts: 2,479
Rep:
|
took the AB and, thanks to the SUCKY info provided on the site, I got a 1. It was TOUGH though- lots of stuff about trees etc... also the fish study (why marine biologists need help doing their job I DON'T know.) didn't feature as much as the A. if there is no teacher, I would suggest doing the A. I played too much- I needed to have focused on passing the test, not learning java, to pass the test. (life sucks.  )
IB sounds tough- if stress is an issue, take the A. (I took 3 AP exams on top of my other load) I should have taken the A twice.
Ok, I rant. Enough.
The frame (window with the little x in the corner and a bar on top) is what holds the main panel. then the main panel organises the other panels according to the window manager. you need to have images on something- the panel. I think grid layout might be what you need
titanium_geek
|
|
|
08-16-2005, 01:53 PM
|
#6
|
LQ Newbie
Registered: Apr 2005
Location: Brussels, Belgium
Distribution: Gentoo
Posts: 17
Original Poster
Rep:
|
about the AP test. I mentioned the book "How to Think Like a Computer Scientist" in java, python, C++, and a couple of other languages (google it... its a pdf file... GPL'd... so its free and can be translated and modified without restriction) and the java version was specifically made to prepare for Ap comp Sci. It covers trees pretty well, along with Stacks, object orientation, etc. Im a senior this year and im gonna end up with about 20 days of external exams... with AP comp Sci being the least of my worries (7 IB exams (2 or 3 days each) along with a possible 5 AP exams (Phys,chem,french,spanish,ap comp sci.... i took calc last year....) so the test really wont matter much... ill already be accepted to whatever school i decide on....but to keep the stress off of it... im working on it now... during the summer... so ill just need to review for then.
ok moving on
I have no problem setting up a window with tabs, panels, scroll panels, images... no problem at all...
my problem is setting up a mouse listener so that i can drag an image into a new region of the panel, and have its new coordinates set into stored integers. From there its not a big deal translating those integers into the various regions and updating the information in the database withthe corresponding values. I just need to figure out how to do the listener part, along with a method to make the images able to be moved around the screen.
so lets refine the request. Other than the Sun website, are there any other guides out there that deal with listeners? and does anyone have any suggestions on how to make an image movable in its panel?
Thanks
Last edited by kermitthefrog91; 08-16-2005 at 01:56 PM.
|
|
|
08-16-2005, 02:28 PM
|
#8
|
LQ Newbie
Registered: Apr 2005
Location: Brussels, Belgium
Distribution: Gentoo
Posts: 17
Original Poster
Rep:
|
yeah i checked that out... its drag and drop operability between applications. not quite what im looking for... htough i think i figured out what i need to do...
i need to set up a mouse listener that is activated on the mouse being held down... i need to get the coordinates of the mouse then, and have it update the coordinates of my image each time the mouse moves... and then when i unclick it keeps the new settings... everything after that can be solved using a coupla of if statements in order to pinpoint the region its in. (actually... maybe ill do a tree in order to get a little practice out of it.) A simple command at the end can snap it into place where i want it, once i have the correct region its in.
Im still checking out Suns guides on listeners... but if anyone knows any other guides for using listeners, that would be nice...
oh.. yeah... titanium... spanish and french may be tricky.... Im not a native speaker in either, but i live in Belgium (a french speaking country... i go to int'l school in english), so french wont be horrible...
thanks...
|
|
|
08-16-2005, 02:35 PM
|
#9
|
Senior Member
Registered: May 2002
Location: Horsham Australia
Distribution: elementary os 5.1
Posts: 2,479
Rep:
|
http://www.ibiblio.org/obp/thinkCS/java/english/
is this it?
EDIT: if you know french, spanish should be easy- it's just the pronunciation...  english is my first tongue, but yeah, living in a spanish speaking country helps... good luck-
I know what you are saying with the mouse click- should work.
titanium_geek
Last edited by titanium_geek; 08-16-2005 at 02:50 PM.
|
|
|
08-16-2005, 03:15 PM
|
#10
|
LQ Newbie
Registered: Apr 2005
Location: Brussels, Belgium
Distribution: Gentoo
Posts: 17
Original Poster
Rep:
|
Yep thats it... scout around for a PDF...
yeah... only thing about french is im pretty fluent verbally... i just suck at writing... spanish isnt too bad because phonetic spelling exists...but french spelling is just ridiculous....
k... but do you have any idea how to do mouse listeners?
|
|
|
08-16-2005, 03:55 PM
|
#11
|
Senior Member
Registered: May 2002
Location: Horsham Australia
Distribution: elementary os 5.1
Posts: 2,479
Rep:
|
umm... not much.  sorry.
http://www.google.com/search?hl=en&q...=Google+Search
spelling? hahahahaha it's english that's crazy... (cough, dough and through all sound different)
titanium_geek
|
|
|
08-18-2005, 11:46 AM
|
#12
|
LQ Newbie
Registered: Apr 2005
Location: Brussels, Belgium
Distribution: Gentoo
Posts: 17
Original Poster
Rep:
|
ok ive got the listeners figured out...
i have the gourps as ArrayList/JPanels of ArrayLists/JPanels of ArrayLists/JPanels of people/JPanels.... when i drag the picture of the person, i need to be able to refer directly to the JPanel it is over, so that when i let go, i can run the code
Code:
//Person a is established in mouseClicked(), add/removePerson() is a method which affects both the arraylist as well as the panel
Area oldA = a.area;
oldA.removePerson(a);
Area newA = ______________ /// this is where i need help... this should be a method of determining which Area the mouse is released on
newA.addPerson(a);
I have the MouseInputListener implemented on the People JPanel.
Any thoughts?
|
|
|
All times are GMT -5. The time now is 08:12 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|