• 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: 928
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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: 79508
379
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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: 928
    10
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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: 79508
    379
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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: 928
    10
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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: 79508
    379
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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: 928
    10
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    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: 928
    10
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    (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: 79508
    379
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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: 79508
    379
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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: 928
    10
    • Likes 1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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: 79508
    379
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    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: 79508
    379
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator

    kevin Abel wrote:. . . Thanks . . .

    That's a pleasure
     
    reply
      Bookmark Topic Watch Topic
    • New Topic