• 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

Java Swing Learning for GUI

 
Ranch Foreman
Posts: 911
8
  • Number of slices to send:
    Optional 'thank-you' note:
I am a QA tester that has used Selenium / Java for about a year.   I may have work that requires creating a simple front end interface.    

I have been finding examples By googling and I got one to work.  I notice there is a hierarchy of classes.

The Dev instantiates classes and connects them together.  I mean to create a browser frame.  Then add objects on to the browser.  There may be other intermediate objects such as the object that divides the screen into sections.

I get the main idea but I'd like to know it better.   I use the Murach book for concepts.  I use google which usually sends me to "Oracle - Java" examples which are good.

Guru99 and W3Schools has some introduction code and explanations but I'd like a class.  Has anyone run into a good one for Java GUI?  

To start I think that I will only need an input box,   I button to launch,  java to make changes to the input and then a text area that shows the result.  I think I can get this going but I'll need to be asking questions here.

Thanks,

Keivn
 
Marshal
Posts: 79422
377
  • 1
  • Number of slices to send:
    Optional 'thank-you' note:

kevin Abel wrote:. . . I use google . . .

Beware. You cannot tell from a search whether the examples will be any good. There are some danger signs for when you are straying from the principles of good object‑oriented GUI design:-
  • 1: Lots of code in the main() method.
  • 2: Unnecessarily subclassing display Components.
  • 3: Inappropriate use of Components as listeners; the commonest example is when you write addActionListener(this);
  • 4: Failure to start the Event Dispatch Thread.
  • 5: Failure to separate business logic from display. The logic and the display should be implemented in separate classes. Or even separate packages.
  • Unfortunately, many books and the Java™ Tutorials fall for some of those mistakes.
     
    kevin Abel
    Ranch Foreman
    Posts: 911
    8
    • Number of slices to send:
      Optional 'thank-you' note:
    I agree that there is a lot of poor code out there.   I don't know any better so I'm happy when it works.  I'm be using it for making small utilities.  I'll take advice as I go along but I don't think I would choose to stop working and retool for a year to be perfect.
     
    Campbell Ritchie
    Marshal
    Posts: 79422
    377
    • Number of slices to send:
      Optional 'thank-you' note:

    kevin Abel wrote:. . . I don't know any better . . .

    But we do, at least some of us. We can give you advice if we get the full details.

    . . . retool for a year to be perfect.

    Nobody expects perfection. But you want to be as good as you can be. Don't produce poor code and think nobody will notice.
     
    kevin Abel
    Ranch Foreman
    Posts: 911
    8
    • Number of slices to send:
      Optional 'thank-you' note:
    Campbell,
    I agree.  There is a small group of people quickly answering my questions and then some from random people.
    I appreciate it a lot.
    Kevin
     
    Campbell Ritchie
    Marshal
    Posts: 79422
    377
    • Number of slices to send:
      Optional 'thank-you' note:

    kevin Abel wrote:. . . some from random people. . . .

    That must be me

    I appreciate it a lot.

    That's a pleasure
     
    kevin Abel
    Ranch Foreman
    Posts: 911
    8
    • Number of slices to send:
      Optional 'thank-you' note:

    I completed watching the torturous Coursera class.   At the end of the class it would not allow me to go back to their cloud.  I can't get back to the course code.
    I downloaded all of the files at the start of the class to my C: drive.   I think the code below is the full working project.  I'll submit the code to get to see the line numbers.  Then I can ask questions based on the line numbers.  
    I'm glad that I took the class to get the main idea but I can tell I would require a lot of constructive criticism if I base my code of this as a starting point.



     
    kevin Abel
    Ranch Foreman
    Posts: 911
    8
    • Number of slices to send:
      Optional 'thank-you' note:
    (19)  JButton Button4 = new JButton("done");    // Is this saying create/instantiate a button, of the type Jbutton, with the variable name Button4 that has text in it that says "done" ??  Am I saying this correctly?
    (23) JPanel panel = new JPanel(null);   // is this saying create a panel of type Jpanel that has no details yet?  
    (32)  f.setDefaultCloseOperation(f.EXIT_ON_CLOSE); //there must be a better way to do this.
    (33)  f.setLayout(new BorderLayout(3, 3));   //  Is this creating a BorderLayout and setting it at the same time?  I don't even know what I'm saying here.  

    (46) through (52)   @Override
                   public void actionPerformed(ActionEvent e)
                   {
                     
                     f.dispose();
                      GenreFrame();
                   }

    Is this overriding the actionPerformed method?   I don't know what class this method belongs to.

    I can keep going but I'll stop for now.

    I'm going to get the Head First Java book and see if it is understandable.

    Thanks,

    Kevin




     
    Campbell Ritchie
    Marshal
    Posts: 79422
    377
    • 1
    • Number of slices to send:
      Optional 'thank-you' note:
    That code must have been written before Java7 when Strings became permissible as labels in switch‑case. But the use of Strings is probably inappropriate there. I am leaving that point until later.
    You don't need all those fields. Make them local variables in an intGui() method.
    That code is going to need a lot of work to beat it into shape, so let's try doing that in stages. Lots of small stages. Besides, I am too busy to write any more now.
     
    Campbell Ritchie
    Marshal
    Posts: 79422
    377
    • 1
    • Number of slices to send:
      Optional 'thank-you' note:
    I think the biggest design problem with that code is that it is a God Class. It is almighty, can do everything, and does do everything. It is a well‑known anti‑pattern.
    Solution. The display should display things and nothing else. The logic for the bookshop should be elsewhere. I think you need at least a Bookshop class, and a Book class. Maybe also a Purchase class. And probably more classes. Remember it is very easy to write too few classes and write non‑object‑oriented code, and it is quite difficult to write too many classes. There are a few places where I think you can write too many classes:-
     
    kevin Abel
    Ranch Foreman
    Posts: 911
    8
    • 1
    • Number of slices to send:
      Optional 'thank-you' note:
    Campbell,

    I think I'll leave this coursera material alone for now.

    I purchased the "Head First Java" book and it seems enjoyable after an hour of reading it.

    I'm not  sure if I will get the contract having to do with GUIs.  I have some idea of how  it works even though the old code is a mess.

    For 38 years I kept learning enough to keep a contract but seldom got to relax and learn for enjoyment.   I'm going to work with the book for now.

    I already have a question from the book so I'll make a new thread.  

    Thanks,

    Kevin



     
    Campbell Ritchie
    Marshal
    Posts: 79422
    377
    • Number of slices to send:
      Optional 'thank-you' note:
    It might still be worth writing a proper, object‑oriented, version of the bookshop app to see how it should be done. I haven't seen HFJ 3/e, but I liked the earlier editions.
     
    Campbell Ritchie
    Marshal
    Posts: 79422
    377
    • Number of slices to send:
      Optional 'thank-you' note:

    kevin Abel wrote:. . . Thanks . . .

    That's a pleasure
    reply
      Bookmark Topic Watch Topic
    • New Topic
    vceplus-200-125    | boson-200-125    | training-cissp    | actualtests-cissp    | techexams-cissp    | gratisexams-300-075    | pearsonitcertification-210-260    | examsboost-210-260    | examsforall-210-260    | dumps4free-210-260    | reddit-210-260    | cisexams-352-001    | itexamfox-352-001    | passguaranteed-352-001    | passeasily-352-001    | freeccnastudyguide-200-120    | gocertify-200-120    | passcerty-200-120    | certifyguide-70-980    | dumpscollection-70-980    | examcollection-70-534    | cbtnuggets-210-065    | examfiles-400-051    | passitdump-400-051    | pearsonitcertification-70-462    | anderseide-70-347    | thomas-70-533    | research-1V0-605    | topix-102-400    | certdepot-EX200    | pearsonit-640-916    | itproguru-70-533    | reddit-100-105    | channel9-70-346    | anderseide-70-346    | theiia-IIA-CIA-PART3    | certificationHP-hp0-s41    | pearsonitcertification-640-916    | anderMicrosoft-70-534    | cathMicrosoft-70-462    | examcollection-cca-500    | techexams-gcih    | mslearn-70-346    | measureup-70-486    | pass4sure-hp0-s41    | iiba-640-916    | itsecurity-sscp    | cbtnuggets-300-320    | blogged-70-486    | pass4sure-IIA-CIA-PART1    | cbtnuggets-100-101    | developerhandbook-70-486    | lpicisco-101    | mylearn-1V0-605    | tomsitpro-cism    | gnosis-101    | channel9Mic-70-534    | ipass-IIA-CIA-PART1    | forcerts-70-417    | tests-sy0-401    | ipasstheciaexam-IIA-CIA-PART3    | mostcisco-300-135    | buildazure-70-533    | cloudera-cca-500    | pdf4cert-2v0-621    | f5cisco-101    | gocertify-1z0-062    | quora-640-916    | micrcosoft-70-480    | brain2pass-70-417    | examcompass-sy0-401    | global-EX200    | iassc-ICGB    | vceplus-300-115    | quizlet-810-403    | cbtnuggets-70-697    | educationOracle-1Z0-434    | channel9-70-534    | officialcerts-400-051    | examsboost-IIA-CIA-PART1    | networktut-300-135    | teststarter-300-206    | pluralsight-70-486    | coding-70-486    | freeccna-100-101    | digitaltut-300-101    | iiba-CBAP    | virtuallymikebrown-640-916    | isaca-cism    | whizlabs-pmp    | techexams-70-980    | ciscopress-300-115    | techtarget-cism    | pearsonitcertification-300-070    | testking-2v0-621    | isacaNew-cism    | simplilearn-pmi-rmp    | simplilearn-pmp    | educationOracle-1z0-809    | education-1z0-809    | teachertube-1Z0-434    | villanovau-CBAP    | quora-300-206    | certifyguide-300-208    | cbtnuggets-100-105    | flydumps-70-417    | gratisexams-1V0-605    | ituonline-1z0-062    | techexams-cas-002    | simplilearn-70-534    | pluralsight-70-697    | theiia-IIA-CIA-PART1    | itexamtips-400-051    | pearsonitcertification-EX200    | pluralsight-70-480    | learn-hp0-s42    | giac-gpen    | mindhub-102-400    | coursesmsu-CBAP    | examsforall-2v0-621    | developerhandbook-70-487    | root-EX200    | coderanch-1z0-809    | getfreedumps-1z0-062    | comptia-cas-002    | quora-1z0-809    | boson-300-135    | killtest-2v0-621    | learncia-IIA-CIA-PART3    | computer-gcih    | universitycloudera-cca-500    | itexamrun-70-410    | certificationHPv2-hp0-s41    | certskills-100-105    | skipitnow-70-417    | gocertify-sy0-401    | prep4sure-70-417    | simplilearn-cisa    |
    http://www.pmsas.pr.gov.br/wp-content/    | http://www.pmsas.pr.gov.br/wp-content/    |