I need to use a GUI for a program (with a main, superclass and subclass) that I've already written (am quite proud of actually. LOL). I'm super new at this so I want to keep it simple and just display the output of my program (an array of inventory objects) in a GUI. My text book is like reading mud, and very unhelpful.

Where do I start? Again, all I want to do is that the output of my program and display it in the text area of a GUI. no interaction quite yet for me, hence my super rookie status.

Recommended Answers

All 4 Replies

TrickyT show what you have done so far ok..?

so, ALL i want to do it just print this toString() output inside of a GUI. ... everything I read seems way more complicated that I am able to understand right now. There has to be an easier way?

here's my main program:

// Inventory Program main includes an array and loaded constructors
import java.util.*;
        

public class Inventory 
{
    
  
   	public static void main(String[] args)
    {
	
 	int iNum;	// Variable for camera's item number
	String iName; 	// Variable for camera's name
	int iStock;	// Variable for number of units in stock
        String iDept;   // Variable for department
	double iPrice;	// Variable for price of each unit
	double iRes;	// Variable for Digital subclass
        
	
        
	System.out.println( );								// One blank line
	System.out.println( "____________________________________________________ " ); // Show a long line
	System.out.println( );								// One blank line
	System.out.println( "Welcome to the Inventory Program ");
	System.out.println( "____________________________________________________ " ); // Show a long line
	System.out.println( "Here are the contents of our inventory");
	
        // create and initialize array
        Camera[] arrCam = new Camera[4];
        Camera p1 = new Camera("CanonF1", 1001, "Electronics", 12, 99.99);
        Camera p2 = new Camera("CanonF2", 1002, "Electronics", 13, 110.99);
        Camera p3 = new DigitalCamera("CanonD1", 2001, "Electronics", 10, 299.99, 8.0);
        Camera p4 = new DigitalCamera("CanonD2", 2002, "Electronics", 15, 399.99, 10.0);
        
        arrCam[0] = p1;
        arrCam[1] = p2;
        arrCam[2] = p3;
        arrCam[3] = p4;
    

	System.out.println( );		// One blank Line
	//System.out.println( "List of Current Inventory" ); // Display welcome line
	//System.out.println( "________________________________" ); // One long line
        //System.out.println( );		// One blank Line
		
    
    
        
                for(int number = 0; number < arrCam.length; number++)
    	
                {
		System.out.printf( "\n%s\n", arrCam[number].toString());
                } 
                // display total inventory using method calculateTotInvent() developed below
                System.out.println( "________________________________" ); // One long line
                System.out.println( );					// One blank line
		System.out.printf("Value of Entire Inventory: %.2f\n", calculateTotInvent(arrCam));
                System.out.println( "________________________________" ); // One long line

		// Show Program Exit Message
		System.out.println( );				// One blank line
		System.out.println( "Now exiting the program."); // Show Exit Message	
		System.out.println( );				// One blank line
							
	} // end method main
	

    
    
     public static double calculateTotInvent(Camera[] arrCam){ 
           
    	double totValue=0.0;
        {
            
    	for(int number =0 ; number < arrCam.length; number++)
            {
    		totValue+= arrCam[number].getIValue();
            }   
        }
    	return totValue;
           
     }
      
    } // end class Inventory

here's my superclass

public class Camera extends Object
{
        protected int iNum2;	// Variable for instance of camera's item number
	protected String iName2; 	// Variable for instance of camera's name
	protected int iStock2;	// Variable for instance of number of units in stock
        protected String iDept2; //variable for department
	protected double iPrice2;	// Variable for instance of price of each unit	
	
	// constructor to create camera object
	public Camera(String iName, int iNum, String iDept, int iStock, double iPrice)
	{
	this.iName2 = iName;
	this.iNum2 = iNum;
        this.iDept2 = iDept;
	this.iStock2 = iStock;
	this.iPrice2 = iPrice;
          
	}

	// Methods to retrieve this info is below
	//method to get item Number
	public int getINum() 
	{
		return this.iNum2;
	}
	
	//method to get item Name
	public String getIName() 
	{
		return this.iName2;
	}
	public String getIDept() 
	{
		return this.iDept2;
	}
	//method to get number of stock
	public int getIStock()
	{	
		return this.iStock2;
	}
        // method to get price of each unit
	public double getIPrice()
	{
		return this.iPrice2;
	}
       public float getIValue() 
       {
        
                return (float) (iPrice2 * iStock2);
       }
               
    @Override
       public String toString()
       {
           return String.format( "%s: %s\n%s: %d\n%s: %s\n%s: %d\n%s: $%.2f\n%s: $%.2f", "Item Name", getIName(), "Item number", getINum(), "Department", getIDept(), "In Stock", getIStock(), "Price each" , getIPrice(), "Value in Stock", getIValue() );
       }
       // end method toString

       } // end class Camera

and here is my subclass

public class DigitalCamera extends Camera

{
	double iRes2;
	float reStock2;
        
            
	public DigitalCamera(String iName2, int iNum2, String IDEPT, int iStock2, double iPrice2, double iRes)    
	{
		super(iName2, iNum2, IDEPT, iStock2, iPrice2);
		this.iRes2 = iRes;
	}
      
	
	public void setIRes(float iRes)
	{
		this.iRes2 = iRes;
	}
	public double getIRes()
	{
		return iRes2;
	}

	
	public float getReStock()
	{
		return (float) ((iStock2 * iPrice2) * 0.05);
	}
 
    @Override
        public float getIValue() 
       {
        
                return (float) ((iPrice2 * iStock2) * 1.05);
	      
       }
	@Override
        public String toString()
       {
           return String.format( "%s %s\n%s: $%.2f\n%s: %.1f", "Digital", super.toString(), "5% restock fee", getReStock(), "Resolution", getIRes());
       }
	
    
        
}//class ends

nope, it's a bit the "no pain, no gain" scenario. using Windows/Linux is supposed to be quite easy for the user, but try to write one from scratch, that'll be a bit harder to do.

look at the first link mKorbel provided you with, that's your best place to start learning.

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.