Java GUI programming
-
Hi programmers, I'm working on a Java project that has a graphical interface and do some other stuffs, as serial/network communication, calculations, etc. In your experience, what is the right way to start? Start from the GUI and then program all the functions, or create all the backgrounds method and classes and then program the GUI? Another issue: you normally prefer to make some variables public or to pass them all as parameters? I'm a bit confused, expecially for Listeners. Thanks, Francesco
-
Hi programmers, I'm working on a Java project that has a graphical interface and do some other stuffs, as serial/network communication, calculations, etc. In your experience, what is the right way to start? Start from the GUI and then program all the functions, or create all the backgrounds method and classes and then program the GUI? Another issue: you normally prefer to make some variables public or to pass them all as parameters? I'm a bit confused, expecially for Listeners. Thanks, Francesco
If you follow one of the modern patterns (MVC, MVVM etc) your GUI should be separated from your business logic such that you can test the latter even before the GUI is designed. So work on the business side of things first, it's much easier to add or modify the GUI than to rework your classes to match the display. It's generally not good practice to have public variables, as such. Pass them as parameters or use setters and getters[^].
-
If you follow one of the modern patterns (MVC, MVVM etc) your GUI should be separated from your business logic such that you can test the latter even before the GUI is designed. So work on the business side of things first, it's much easier to add or modify the GUI than to rework your classes to match the display. It's generally not good practice to have public variables, as such. Pass them as parameters or use setters and getters[^].
Dear Richard, Thanks for your reply, I'll study about the two patterns you suggested me. For public variables, I show my problem: I want to write data on RS232 port, wait a reply, read data arrived and elaborate them. I create a SerialPort object using RxTx libraries and I setted a Listener to it. In my main class, a method write the data on the serial port and then wait on a Condition variable. The listener have to notify to the waiting method the arrival of the data. The two methods are on completely different classes, so I thought to make the condition variable global. Unfortunately, at now the program doesn't work. What shall be the right way to do solve kind of problem? Francesco
-
Dear Richard, Thanks for your reply, I'll study about the two patterns you suggested me. For public variables, I show my problem: I want to write data on RS232 port, wait a reply, read data arrived and elaborate them. I create a SerialPort object using RxTx libraries and I setted a Listener to it. In my main class, a method write the data on the serial port and then wait on a Condition variable. The listener have to notify to the waiting method the arrival of the data. The two methods are on completely different classes, so I thought to make the condition variable global. Unfortunately, at now the program doesn't work. What shall be the right way to do solve kind of problem? Francesco
Francesco Fraccaroli wrote:
Unfortunately, at now the program doesn't work. What shall be the right way to do solve kind of problem?
Sorry, but that information does not help us to understand what is happening. I suggest you open a new question, and show the part of your program that does not work, and explain exactly what errors you are seeing. Don't forget to add <pre> tags (use the
code
button above the edit window) around your code so it is readable like:// your code snippets here
-
Hi programmers, I'm working on a Java project that has a graphical interface and do some other stuffs, as serial/network communication, calculations, etc. In your experience, what is the right way to start? Start from the GUI and then program all the functions, or create all the backgrounds method and classes and then program the GUI? Another issue: you normally prefer to make some variables public or to pass them all as parameters? I'm a bit confused, expecially for Listeners. Thanks, Francesco
http://techgurulab.com/course/java-tutorials/[^] This link is useful to increase your basic concept with respect to your Question.