Hello guys! I need help. I have two forms: Input and Output. On the Input form, the user/s will have to input their name/s and times in which they are busy. When they click "finished", the Output form is supposed to display what they typed like their names and times. How do I do this? How do I get inputted info from the Input form and display it on the Output form?

Recommended Answers

All 8 Replies

The "OO" way is to create a class for whatever it is you are entering and displaying. This class represents the data and logic for whatever it is, and is the true core of the application. Such classes are generally referred to as a "model".
In your input form you create a new instance of the model class, and populate its fields with the data from the input form. The output form should have a constructor that takes an instance of the model class, and displays all the data from that instance. All the input form has to do is to create a new instance of the output form, passing the model instance as a parameter.

In my MainProject package, I have three files: Input.java, Output.java, and MainProject.java. Should I create the "model" class in the MainProject.java? Or should I create another form for this "model" class?

I would create the model class as a public class in its own .java file. It's not "another form", it has no user interface of its own. Think of it as a simple container for the set of data collected in the input form, so it can be passed to the output form as a single object.
This may seem a bit of a long way round, but in the long run it's always worth it. Later on you may have to keep more than one set of data - eg use the input form "n" times to create a list of these objects. You'll be able to have an array of them for printing, searching, sorting etc. That is how it usually goes...
Here's an example, using a collection of compact disks. (The code is to show the principle, don't expect to just copy/paste it.)
First, a very simple class for a CD with artist and album names

public class CD {
   private String artist; private String album;
   public String getArtist() {
      return artist;
   public void setArtist(String artist) {
      this.artist = artist;
   public String getAlbum() {
      return album;
   public void setAlbum(String album) {
      this.album = album;

then in a typical input form, in the action handler for the OK button, create a new CD, set its values from the input form fields, and create a new output form to display it...

nextCD = new CD();
new OutputForm(nextCD);

finally, in the output form, have a constructor that takes a CD and displays its values...

public OutputForm(CD aCD) {
  //  create the form etc etc
  // make form visible

Hmmmm... So basically, in the MainProject package, I'll have four .java files: Input, Output, MainProject, and the model class. The model class contains the logic and formulas of the whole package? Am I on the right track?

Getting closer...
Think of your application in two layers. The upper layer, the user interface, contains whatever it takes to interact with the user - ie the forms (JFrames, JLabels etc) and the logic needed to make them work, eg Input, Output. You may even have a choice of user interfaces (eg Swing forms, HTML web pages). The lower level, the model, contains everything (data and logic) that is independent of how any particular UI works.
Eg In a mortgage application the model will have variables for amount, interest rate, term etc, and methods for calculating repayments. All these things are fixed by how mortgages work, regardless of what the user interface may look like.
Finally you have a "master" class, eg "MainProject" that has the main(String[] args) method and gets everything started. Often this is pretty small and just displays the first UI form.

I am going to assume you are using a GUI, so when the user hits finished you need to use the .getText(); method to get the text from the text field, and store it in a variable. one you get all the text you then need to print out the variables in a JPanel, or another component. you can do this using setText();

please help me!!
I want to see my outputwindows in the form that I create it!!!
like this:
Cancelled by user.
BUILD FAILED (total time: 2 seconds)
this is all of things that java shows in output win!!!
can you help me to see that's in my form.!!!(my wording is bad sorry!!i can't speek english so good)

DaniWeb Member Rules (which you agreed to when you signed up) include:
"Do not hijack old threads by posting a new question as a reply to an old one"
Please start your own new thread for your question

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.