[Logo]
Forums Register Login
GUI to show astronomy events
Hello everyone,

Thank you for taking the time to read this.

So I'm a novice with Java OOP I am self teaching through a certain Helsinki uni course which is free. I'm using net beans and learning at my own pace which I am enjoying.

I am however keen to create somthing for my father in law as a sort of Christmas calendar for the run up to Christmas that will see him piece together code to create a program, easy enough I think.

The premise of the code is that I will want the code to print to ask for a month and having typed the month will get a response on all astronomy events happening in the given month ( he likes that stuff ) and thought it made it a bit fun.

In itself I can't see making the code for this hard, but what I would really like to do is then take this code and make it print to and LCD with touch to allow input from a screen (this thus far has been hard to find info on the Internet on how to do)

As I said I'm new, and this may not even be possible, if so how easy is it to create a GUI that does this? Or perhaps even an app? Sorry but I haven't progressed this far yet but would love to do this for him if I can.

Thank you and all the best,
Hi Jamie, welcome to the Ranch!

I'm not quite clear on what you want to do but... you mentioned Christmas in your time line. If you're a novice then I wouldn't expect you to be able to learn the basics and produce something usable in under a month. I mean, don't let that stop you from working on the project, because working on a project of your own choice is one important factor leading to success. I just don't think you can get it done in four weeks.
As Paul says, this is bigger than you think it is, especially if you are a complete novice.

You may need to delve deeper into what you want to achieve, breaking it down.

For example, if this is for astronomy events, do you have a source to call to look these things up?
Then I would investigate how to do a search on that source of data.

Forget (for now) about GUIs and touchscreens.
 

Jamie Porro wrote:...and having typed the month will get a response on all astronomy events happening in the given month


Where would you get this information from?  A web service?

For a start, why not code the prompting and input of the month?  Use Scanner for now; you can create a GUI later.  Include formatting the date and error correction.  That will tell us how something about what your coding skill level is.
Thank you all for ththe valuable feedback.

I feel that perhaps I should have explained myself better in what I want to achieve as I fear you all feel I want to do something incredibly complicated!

So my thoughts on what I wanted to do are along these lines;


System.out.print ("enter a mont")
reader.nextLine (so user will input a month)

I will be simply getting the events that take place online not looking to link data to anything and then;

Something like

If (user enters January for example)
System.out.print (all events within this given month)

Else (continue on for all the other months)

Nothing too fancy I know but a bit of fun

This in itself I don't see as a challenge but it's how I can then take this code and show it on a LCD of an added level of fun

Hope this makes sense

 

Jamie Porro wrote:...I will be simply getting the events that take place online not looking to link data to anything ...


I think you need to define what "simply getting the events that take place online" means.

If (user enters January for example)
System.out.print (all events within this given month)


Okay, so now what is the pseudocode for "all events within this given month"?
 

Knute Snortum wrote:

Jamie Porro wrote:...I will be simply getting the events that take place online not looking to link data to anything ...


I think you need to define what "simply getting the events that take place online" means.

If (user enters January for example)
System.out.print (all events within this given month)



By simply, I mean I will google "astronomy events" find a list of events over the given year.

Okay, so now what is the pseudocode for "all events within this given month"?



I'm sorry I'm unsure what you mean by this. My intention would just be to list the events as a print within the code
Sorry my comment didn't format very well I'm using my iPhone to type this. I've somehow managed to add my first comment within the quote and second but as expected
I would still get that part working first.
That is, having some code that will handle the "answering" of the question, and stick a simple terminal front end instead of a GUI.

I'm still not sure how you plan on doing it (though maybe a file-per-month and then simply display that?)...
 

Dave Tolls wrote:I would still get that part working first.
That is, having some code that will handle the "answering" of the question, and stick a simple terminal front end instead of a GUI.

I'm still not sure how you plan on doing it (though maybe a file-per-month and then simply display that?)...



I think the best thing for me to do is create what I think I want to create code wise and then come back to you all on this and see where that takes us!

I'm clearly not explaining myself very well
 

Jamie Porro wrote:I think the best thing for me to do is create what I think I want to create code wise and then come back to you all on this and see where that takes us!



That sounds like a plan. Let us know how it goes!
Don't like it at all, I am afraid.
You should be able to use a switch rather than those repeated ifs.
You have a main method much much too long.
There is very little coding to the blocks of print instructions. All you are doing is printing a list of ephemeris.
Your program should not hard-code the information to be printed - otherwise it will become obsolete after the last month you include.

you should instead put that information in an external file or database, and the program should read the information from that file.That way you can just update the file and send your frient the updated file, and the program will not have to be rewritten every few months.
 

Campbell Ritchie wrote:Don't like it at all, I am afraid.
You should be able to use a switch rather than those repeated ifs.
You have a main method much much too long.
There is very little coding to the blocks of print instructions. All you are doing is printing a list of ephemeris.



With respect Campbell, you have provided very little in the way of constructive support for me here, you assume I know what you mean by a switch and you have perhaps forgot that I'm doing this as a bit of fun for my father in law. I appreciate you will not like this, and as I mentioned above, I expect the is most certainly a better way of writing this code, I am however, constrained with time so trying to make do with what I currently know. Thank you for pointing out what I am doing but I'll be honest, your comment is a rather uninspiring one and has put me off wishing to seek help, which I had hoped to receive.

Again, nothing personal against you, but I don't feel inspired with what you have said!
 

Fred Kleinschmidt wrote:Your program should not hard-code the information to be printed - otherwise it will become obsolete after the last month you include.

You should instead put that information in an external file or database, and the program should read the information from that file.That way you can just update the file and send your frient the updated file, and the program will not have to be rewritten every few months.



Hey Fred, thank you for this. As it stands I lack the knowledge of how to do this, the intention here is to purely provide some basic information in a fun way (instead of say just googling it)

Perhaps I'm barking up the wrong tree asking for guidance here with the limited knowledge I have.
OK, when you say "LCD with touch" what device are you planning on running this on?

Since you plan on having a GUI you are going to need to create a class (a DAO, or DataAccessObject) that handles your data.

You would probably get away with it only having a simple Map<String, List<String>>, which is a Map that maps the month names and returns a List of Strings, which are your events.
And the DAO (DataAccessObject) would simply have a method called getEvents(String) which takes a month and returns the list of events.

This is a small step up from where you are at the moment, but is something you should be able to achieve easily enough.
 

Dave Tolls wrote:OK, when you say "LCD with touch" what device are you planning on running this on?

Since you plan on having a GUI you are going to need to create a class (a DAO, or DataAccessObject) that handles your data.

You would probably get away with it only having a simple Map<String, List<String>>, which is a Map that maps the month names and returns a List of Strings, which are your events.
And the DAO (DataAccessObject) would simply have a method called getEvents(String) which takes a month and returns the list of events.

This is a small step up from where you are at the moment, but is something you should be able to achieve easily enough.



So the LCD question is a good one as this was one of my set backs at the moment as when searching online about such a thing, and the options of being able to do this wasn't very clear online. Are you able to provide any steer on this I would appreciate it massively.

In terms of the other points I will have a look tonight. Thankyou !
So you don't have a target device at the moment?
Unfortunately not. It was one of the main reasons for raising the topic initially (although I have been provided with some great feedback on things that will help with this)
Well, I suspect it then comes down to budget I suppose?
And whether Java runs on whatever device is chosen.

Obviously, a cheap Android device comes to mind.

And before you actually purchase one, you could get hold of Android Studio, create your app, and test it in the emulator it comes packaged with.
No point splashing out until you have an actual app.

There may be cheaper ways to do it (Raspberry Pi, or Arduino?), but I have no idea on that.
 

Dave Tolls wrote:Well, I suspect it then comes down to budget I suppose?
And whether Java runs on whatever device is chosen.

Obviously, a cheap Android device comes to mind.

And before you actually purchase one, you could get hold of Android Studio, create your app, and test it in the emulator it comes packaged with.
No point splashing out until you have an actual app.

There may be cheaper ways to do it (Raspberry Pi, or Arduino?), but I have no idea on that.



This is fantastic guidance - I will do this tonight and keep you all updated on progress on this.

Thank you again for the support and advice
Just curious. Why an LCD display vs just using the computers console? Is it expected that the end user is not capable of running a GUI app? How would an LCD app be any better?
 

Carey Brown wrote:Just curious. Why an LCD display vs just using the computers console? Is it expected that the end user is not capable of running a GUI app? How would an LCD app be any better?



Oh no he is perfectly capable, my hope is that if I can make that work on an LCD then I could t eventually make it portable (this in not expecting to be able to do with my time frame but can build open hopefully)

Question, how easy is it to make a GUI app?
It seems that using a text file to supply events would be a good way to go. Here's a small sample delimited with the '|' character. The fields are: start date, optional end date, and event description. It should be relatively straight forward to create a small class to support these fields and a way to select them by month. Have you worked with lists or arrays at all?

    
 

Jamie Porro wrote:my hope is that if I can make that work on an LCD then I could t eventually make it portable (this in not expecting to be able to do with my time frame but can build open hopefully)
Question, how easy is it to make a GUI app?


Making it portable: You are probably talking a Raspberry Pi with LCD or building an Android app. An Android app would probably be easier and could build on any Java knowledge that you have. Whether Android or a Swing GUI is more difficult is hard to say. Swing has better support from development environments as opposed to Android which you would have to download to a phone for testing or run under a simulator.

I think your current path, that of creating a textual user interface first, is a good way to go. That allows you to concentrate on data structures and logic and get those thoroughly debugged.
 

Carey Brown wrote:It seems that using a text file to supply events would be a good way to go. Here's a small sample delimited with the '|' character. The fields are: start date, optional end date, and event description. It should be relatively straight forward to create a small class to support these fields and a way to select them by month. Have you worked with lists or arrays at all?

    



My course doesn't mention it for a while yet,  it I have free flow access so will visit it tonight. I had a look and it looks fairly straightforward to implement I will have a look on YouTube as well for a demonstration (will come back once I have looked into this)
 

Carey Brown wrote:

Jamie Porro wrote:my hope is that if I can make that work on an LCD then I could t eventually make it portable (this in not expecting to be able to do with my time frame but can build open hopefully)
Question, how easy is it to make a GUI app?


Making it portable: You are probably talking a Raspberry Pi with LCD or building an Android app. An Android app would probably be easier and could build on any Java knowledge that you have. Whether Android or a Swing GUI is more difficult is hard to say. Swing has better support from development environments as opposed to Android which you would have to download to a phone for testing or run under a simulator.

I think your current path, that of creating a textual user interface first, is a good way to go. That allows you to concentrate on data structures and logic and get those thoroughly debugged.



Android app sounds really interesting! But I had looked at raspberry pi and was keen to explore this at some point! So choices!

Swing sounds interesting though as he does spend a lot of time on his laptop for his hobby so could be a better route.

Thank you for the input!
Well, if it's to go on a laptop then that would solve target environment.


It would also be simpler, since you won't need emulators, and if it works on your machine it should work on his.
 

Dave Tolls wrote:Well, if it's to go on a laptop then that would solve target environment.


It would also be simpler, since you won't need emulators, and if it works on your machine it should work on his.



Okay guys!

So i have elected to go with a GUI within netbeans using the Swing option we have discussed. I have followed a tutorital in terms of building this and it has got me so far, the issue Iam currently posed with is making the bottons communicate (if that makes sense)

Ihave tried a few different options but my brain isnt comprehending what I need to do right now... I appreciate that using this GUI and Swing isn't something a novice would be expected to know so apologies if its not great! (I can refine it once I know it works though)

I have copied my app below and wonder if anyone can provide me with a solutions on how I can implement my code into this?

Sections I am struggling with at the moment have "// TODO add your handling code here:"

Thank you in advance!

Think I may have figured it out! - Just kept playing, and think I solved it! - If anyone else has a solution incase though that would be great! - I will keep you all posted
So I have managed to get text to appear but unsure how to get the next line to add (its all just showing on one line) :/ any suggestions?

This is what I added to the "enter button section"  - I tried making it seperate and made no difference i.e.multip setText lines...

Was only partially working...
if ((userInput) .equals ("January")); <<< think the semi colon should be {} but isnt working in that case...
If you want to display multiple lines of text use a JTextArea.
 

Carey Brown wrote:If you want to display multiple lines of text use a JTextArea.



I was looking at this last night rather late, I think I mis read it because I ignored it! I'll report back later ty Carey
Hey guys,

I hope you can answer this one for me. So i have managed to get the JtextArea to print on multiple lines using the \n fuction which is a great learn!

I am however having issues getting the code to read the user input field once the enter button is hit as at the moment, regardless of what I put, the results currently within the code show.. I am seriously confused at what it should be at the moment and at the moment, wont be able to give this to my father in law to build hisself as a bit of fun over christmas.

I have placed code below, perhaps you could give me some ideas of let me now what I am doing wrong, thank you again for all the help so far!

I tried to make the bit of code i was referring to red but it hasnt worked... its within the section below

private void enterButtonActionPerformed(java.awt.event.ActionEvent evt) {                                           

                
                   if(userInput == ("January"));
                   {
                   resultField.setText("January 1st - Mercury at Greatest Western Elongation" + "\n" + "January 2nd - Full Moon, Supermoon" + "\n" + "January 3rd & 4th - Quadrantids Meteor Shower" + "\n" + "January 17th - New Moon" + "\n" + "January 31st - Full Moon, Supermoon, Blue Moon" + "\n" + "January 31st - Total Lunar Eclipse");
                   }

                   
               
   
    }
also,apologies, it should real if(userInput) .equals ("January) {}
if( userInput.getText().equals("January") )
 

Carey Brown wrote:if( userInput.getText().equals("January") )



I love you... Slightly annoyed that all I needed was the getText() bit but atleast I was thinking along the right lines.

This thread has been viewed 640 times.

All times above are in ranch (not your local) time.
The current ranch time is
Sep 22, 2018 10:31:15.