• 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

Inventory 4 GUI / Connecting Elements

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello! I am trying to figure out how to make a GUI for a Java Program I made, but I am having difficulty. How do I make elements connect to my written code? And what do I use to make a part in GUI that reads the output of the code I made? here is some of what I got if it helps. If you need more, let me know. I have never used/or done, GUI before...

Here's the GUI...


Warnings on lines:
139 - Can be replaced by multicatch.
152 - @ Add override







When I debug, it does not pull up GUI. The code is working well, but I don't know much about GUIs.
GUI-photo-1.PNG
[Thumbnail for GUI-photo-1.PNG]
GUI Photo
 
Saloon Keeper
Posts: 15510
363
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ofelia.

Your form needs to know about the existence of the products, and it also need to know when to update it's view.

This is called the Model View Controller paradigm. Your form simply "views" the model (so your model still needs a class that knows which products exist). Later, when you add buttons to add products, these will be the controllers that change the data in your model, and then tell the view to update.

So, what should happen is that the controller (right now just your main method) initializes the model and the view, and passes an instance of your model to your view. Do you see how empty your GUI constructor is? I'm sure you could change it to have a parameter of type Store (or whatever you want to name the class that tracks products), and then save the argument in a field of the GUI.

You then need a component that can display this data. Maybe a JTable would be a good choice. Take a look at this tutorial: http://docs.oracle.com/javase/tutorial/uiswing/components/table.html

Let us know your progress.
 
Os Stewart
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to understand this, but I am not getting it.
This is what I have so far. I changed the look of my GUI and I'm trying to figure out still how to implement my program into it to make it work.

GUI-photo-2.PNG
[Thumbnail for GUI-photo-2.PNG]
This image is all I have, just an image, I want it to list out all my results from the program
 
Marshal
Posts: 79180
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moved to our GUIs forum.
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ofelia Stewart wrote:Hello! I am trying to figure out how to make a GUI for a Java Program I made, but I am having difficulty. How do I make elements connect to my written code? And what do I use to make a part in GUI that reads the output of the code I made? here is some of what I got if it helps. If you need more, let me know. I have never used/or done, GUI before...


Hmmm ... which suggests to me that you might be taking on too much too soon.

GUI programming, IMO, is a black art, practised by strange, visually-oriented gnomes, who love mucking about with scrolling text, and animations, and buttons and boxes of all shapes and sizes; and don't care that they have to write a thousand lines of boilerplate in order to get anything to work (I jest, but not totally ridiculously - it really does seem to be something that you either like or you don't).

My suggestion: Have a look at the tutorials, and follow some of the examples and exercises, so that you get a good feel for how things hang together before you tackle something like this.

One thing I will say: You seem to have kept your GUI completely separate from your Inventory classes, which is a great place to start. Keep it up, and resist the urge to start mixing the two. There's no way that any 'J' class (JLabel, JComponent, etc.) should ever appear in something like a Product.

HIH

Winston
 
Hang a left on main. Then read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic