• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

GUI to show astronomy events

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Jamie Porro
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Knute Snortum
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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"?
 
Jamie Porro
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Jamie Porro
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?)...
 
Jamie Porro
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 732
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jamie Porro
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
Jamie Porro
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jamie Porro
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 !
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you don't have a target device at the moment?
 
Jamie Porro
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jamie Porro
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Jamie Porro
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?

   
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Jamie Porro
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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)
 
Jamie Porro
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jamie Porro
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!

 
Jamie Porro
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Jamie Porro
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...

 
Jamie Porro
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Was only partially working...
if ((userInput) .equals ("January")); <<< think the semi colon should be {} but isnt working in that case...
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to display multiple lines of text use a JTextArea.
 
Jamie Porro
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Jamie Porro
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!

 
Jamie Porro
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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");
                  }

                   
               
   
   }
 
Jamie Porro
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
also,apologies, it should real if(userInput) .equals ("January) {}
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if( userInput.getText().equals("January") )
 
Jamie Porro
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic