Help with a first attempt at adding a GUI to a program

I am so lost and frustrated in the GUI for the imfamous Inventory Prog

Page 1 of 1

4 Replies - 1358 Views - Last Post: 15 June 2007 - 09:03 AM Rate Topic: -----

#1 dgilmore286   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 09-May 07

Help with a first attempt at adding a GUI to a program

Post icon  Posted 15 June 2007 - 06:23 AM

Hi all,
Novice here yet again…
I have the well known Inventory project that has been a subject here several times. I am at the stage where I have to add the first GUI part to the project and I am totally at a loss.
I have my attempt at adding a JTextArea to the driver program, I have tried several attempts by following some of the examples from the book, even to the point of copying some of the code from one of the examples and for the life of me I just cannot figure this out. Below is the code that I have attempted so far, it compiles fine but will not even show any GUI windows. I have not removed the display methods that were from the previous stage, and that data still shows fine in the command window when I run the program, bit it seems to just ignore all the new code I entered for the GUI. Can some one PLEASE help this poor old fart out? I know you all must be sick of seeing these pleas for help on this particular project….

Thank you all so much in advance

A VERY Frustrated, Dave.
import javax.swing.Box;
import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;

class TextAreaFrame extends JFrame
	{
	   private JTextArea textArea1; // displays demo string

	   // no-argument constructor
	   public TextAreaFrame()
	   {
		  super( "Inventory of DVD Movies" );
		  Box box = Box.createHorizontalBox(); // create box
		  String movieData = "Need to find a way to add the *.displayInventory() For all movies in the array";

		  textArea1 = new JTextArea( movieData, 25, 30 ); // create textarea1
		  box.add( new JScrollPane( textArea1 ) ); // add scrollpane
		  add( box ); // add box to frame
	   } // end TextAreaFrame constructor
	} // end class TextAreaFrame

	class TextAreaInventory
	{
		{//block
		  TextAreaFrame textAreaFrame = new TextAreaFrame();
		  textAreaFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
		  textAreaFrame.setSize( 425, 200 ); // set frame size
		  textAreaFrame.setVisible( true ); // display frame
	   }//end block
   } // TextAreaInventory

public class InventoryArrayTest2gui
{
	public static void main ( String args [] )
	{
	   //create 4 instances of class Product1
	   Movie movieA = new Movie( "X-men", "PG-13", 110, 22, 1 );
	   Movie movieB = new Movie( "Evil Dead 2: Dead By Dawn", "R", 220, 12, 1 );
	   Movie movieC = new Movie( "Andromeda Strain, The", "PG", 330, 9, 1);
	   Movie movieD = new Movie( "Underworld: Evolution", "PG-13", 440, 38, 1 );

	   //Create Array products and assign elements
	   Movie products[] = { movieA, movieB, movieC, movieD };

	   //Display objects from array products
	   System.out.printf( "\nInventory of DVD Movies:\n\n" );

	 //Loop to iterate through array, formatting and displaying the contents
	  for ( int counter = 0; counter < products.length; counter++ )
	  {
		  System.out.printf( "Item #%s\n", ( counter +1) );
		  products[ counter ].displayInventory();
		  products[ counter ].displayItemValue();
	  }

	  //Process to sort movies aphabetically by title and display in sorted order
		products[0].sortInventory(products);

	  //display Sorted Inventory data
	  System.out.printf( "\nSorted Inventory of DVD Movies:\n\n" );
	  for ( int counter = 0; counter < products.length; counter++ )
	  {
		  System.out.printf( "Item #%S\n", ( counter + 1)  );
		  products[ counter ].displayInventory();
		  products[ counter ].displayItemValue();
	  }

	  //cummulative formula for caluclating and displaying the extended inventory total value
	  Double totalValue = products[0].CalculateTotalInventoryValue(products);
	  System.out.printf( "%s%s%.2f\n\n", "Total Inventory Value is: ", "$", totalValue );

	}//end main

}//end class InventoryTest2gui



Is This A Good Question/Topic? 0
  • +

Replies To: Help with a first attempt at adding a GUI to a program

#2 William_Wilson   User is offline

  • lost in compilation
  • member icon

Reputation: 207
  • View blog
  • Posts: 4,812
  • Joined: 23-December 05

Re: Help with a first attempt at adding a GUI to a program

Posted 15 June 2007 - 08:16 AM

as the last lines of your TextAreaFrame constructor try, using the line:
setVisible(true);

but you really should have a set of items listed in the jframe to denote size position, etc. ex:
			setResizable(true);						//allow window to be resized: true?false
			setLocation(100,100);					//location on the screen to display window
			setDefaultCloseOperation(EXIT_ON_CLOSE);//what to do on close operation: exit, do_nothing, etc
			setSize(200,50);						//set the size of the window
			setVisible(true);						//show the window: true?false


there are more, but these are the minimum set i would suggest.
Was This Post Helpful? 0
  • +
  • -

#3 dgilmore286   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 09-May 07

Re: Help with a first attempt at adding a GUI to a program

Posted 15 June 2007 - 08:26 AM

I had tried all that but it is still not showing any GUI when I compile and run. I get no compilation or runtime errors, just no GUI. I cannot even figure out how to make the GUI show, let alone how to fix the text that is displayed once the GUI works so that is shows all the data from the products array. THis class is so darn hard and the text is basically no help in understand what the assignment is asking us to make.
Was This Post Helpful? 0
  • +
  • -

#4 William_Wilson   User is offline

  • lost in compilation
  • member icon

Reputation: 207
  • View blog
  • Posts: 4,812
  • Joined: 23-December 05

Re: Help with a first attempt at adding a GUI to a program

Posted 15 June 2007 - 08:46 AM

you need to use getContentPane() to add things to your JFrame:
getContentPane().add( box );

also you never call:
new TextAreaInventory();
so how do you expect the window to be created?
Was This Post Helpful? 0
  • +
  • -

#5 dgilmore286   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 69
  • Joined: 09-May 07

Re: Help with a first attempt at adding a GUI to a program

Posted 15 June 2007 - 09:03 AM

Ok, thanks, I will try this and see what happens...

Thank you again...

D
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1