How to call the GUI I created

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 3960 Views - Last Post: 06 June 2008 - 02:11 PM Rate Topic: -----

#1 deepacc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 27-May 08

How to call the GUI I created

Posted 06 June 2008 - 10:24 AM

Hi Guys
THis is for Part 4 of my inventory program. I needed to create GUI interface. I have coded a GUI which is below not sure if its right or not. But I can not figure out how to call this in my main file Please help me I know the answer is prob so simple I am just lost.

here is my gui code
import java.util.Arrays;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//a liitle GUI
class GUI extends JFrame {
protected double currentProdno;
private JTextField jtfprdItem; //1
private JTextField jtfprdName; //2
private JTextField jtfprdUnit; //3
private JTextField jtfprdPrice;//4
private JTextField jtfTotal; //5 getresult()
private JTextField jtfReStock; //6 getrestock()
private JTextField jtfstrCName;//7
private JTextField jtfinvTotal;//8
private JButton btnNext;

GUI() {
super("Inventory Part 4 Program");
//this.inventory = inventory;
currentProdno = 0;

JPanel jp;
JLabel jl;
JPanel outerPanel = new JPanel();
outerPanel.setLayout(new BoxLayout(outerPanel, BoxLayout.Y_AXIS));

JPanel titlePanel = new JPanel();
titlePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
jl = new JLabel("Inventory Part 4");
titlePanel.add(jl);
outerPanel.add(titlePanel);

JPanel numberPanel = new JPanel();
numberPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
jl = new JLabel(" Number: " );
numberPanel.add(jl);
jtfprdItem = new JTextField (1);
jtfprdItem.setEditable(false);
numberPanel.add(jtfprdItem);
outerPanel.add(numberPanel);

JPanel number1Panel = new JPanel();
number1Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
jl = new JLabel(" Name: " );
number1Panel.add(jl);
jtfprdName = new JTextField (2);
jtfprdName.setEditable(false);
number1Panel.add(jtfprdName);
outerPanel.add(number1Panel);

JPanel number2Panel = new JPanel();
number2Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
jl = new JLabel(" Units: " );
number2Panel.add(jl);
jtfprdUnit = new JTextField(3);
jtfprdUnit.setEditable(false);
number2Panel.add(jtfprdUnit);
outerPanel.add(number2Panel);

JPanel number3Panel = new JPanel();
number3Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
jl = new JLabel(" Price: " );
number3Panel.add(jl);
jtfprdPrice = new JTextField(4);
jtfprdPrice.setEditable(false);
number3Panel.add(jtfprdPrice);
outerPanel.add(number3Panel);

JPanel number4Panel = new JPanel();
number4Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
jl = new JLabel(" Total: $ " );
number4Panel.add(jl);
jtfTotal = new JTextField(5);
jtfTotal.setEditable(false);
number4Panel.add(jtfTotal);
outerPanel.add(number4Panel);

JPanel number5Panel = new JPanel();
number5Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
jl = new JLabel("Restocking Fee: $ " );
number5Panel.add(jl);
jtfReStock = new JTextField(6);
jtfReStock.setEditable(false);
number5Panel.add(jtfReStock);
outerPanel.add(number5Panel);

JPanel number6Panel = new JPanel();
number5Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
jl = new JLabel("Restocking Fee: $ " );
number5Panel.add(jl);
jtfstrCName = new JTextField(7);
jtfstrCName.setEditable(false);
number5Panel.add(jtfstrCName);
outerPanel.add(number6Panel);

JPanel number7Panel = new JPanel();
number6Panel.setLayout(new FlowLayout(FlowLayout.CENTER));
jl = new JLabel("Total Invenory Value: $" );
number6Panel.add(jl);
jtfTotal = new JTextField(8);
jtfTotal.setEditable(false);
outerPanel.add(number7Panel);



setContentPane(outerPanel);
setResizable(false);
setVisible(true);

}



} // end GUI class



here is my main code
public class Inventory
{
public static void main(String args[])
{
Movie Products[] = new Movie[4];

Products[0] = new Movie("0", "Little Mermaid",26, 12.99, "G");
Products[1] = new Movie("1", "A Walk to Remember",15, 15.89, "PG");
Products[2] = new Movie("2", "Men in Black",8, 5.00, "PG");
Products[3] = new Movie("3", "Boyz in the hood",20, 21.15, "PG13");

//initiate decimal format object
DecimalFormat Currency = new DecimalFormat("#0.00");

//print the inventory information
System.out.print("\nInventory of DVD Movies:\n\n");

for(int index = 0; index < Products.length; index++) {
System.out.println("Number: " + Products[index].getNum());
System.out.println("Name: " + Products[index].getName());
System.out.println("Rating: " + Products[index].getRating());
System.out.println("Stock: " + Products[index].getStock());
System.out.println("Price: $" + Currency.format(Products[index].getPrice()));
System.out.println("Restocking fee: $" + Currency.format(Products[index].getRestockingFee()));
System.out.println("Item Value: $" + Currency.format(Products[index].getInventoryTotal()));
}

//sorting the array
ProductInfo.SortInventory(Products);

//print the inventory information
System.out.print("\nSorted Inventory of DVD Movies:\n\n");

for(int index = 0; index < Products.length; index++) {
System.out.println("Number: " + Products[index].getNum());
System.out.println("Name: " + Products[index].getName());
System.out.println("Rating: " + Products[index].getRating());
System.out.println("Stock: " + Products[index].getStock());
System.out.println("Price: $" + Currency.format(Products[index].getPrice()));
System.out.println("Restocking fee: $" + Currency.format(Products[index].getRestockingFee()));
System.out.println("Item Value: $" + Currency.format(Products[index].getInventoryTotal()));
}

//calulcating total value and displaying
Double totalInv = Products[0].CalculateTotalInventoryValue(Products);
System.out.print("Total Inventory Value: $" + Currency.format(totalInv) + "\n");

// Import the java swing package so we can use swing controls like JFrame.

// Create a JFrame (application window with the title "HelloWorldSwing")
JFrame frame = new JFrame("Inventory Of DVD's");

// Set it so that it terminates the program when the window is closed.
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// Set the windows size and then show it.
frame.setSize(300,300);
frame.setVisible(true);

} // main

} // Inventory

Is This A Good Question/Topic? 0
  • +

Replies To: How to call the GUI I created

#2 mensahero  Icon User is offline

  • I Desire...
  • member icon

Reputation: 17
  • View blog
  • Posts: 678
  • Joined: 26-May 08

Re: How to call the GUI I created

Posted 06 June 2008 - 10:56 AM

View Postdeepacc, on 6 Jun, 2008 - 10:24 AM, said:

Hi Guys
THis is for Part 4 of my inventory program. I needed to create GUI interface. I have coded a GUI which is below not sure if its right or not. But I can not figure out how to call this in my main file Please help me I know the answer is prob so simple I am just lost.

here is my gui code
import java.util.Arrays;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//a liitle GUI
class GUI extends JFrame {
    protected double currentProdno;
    private JTextField jtfprdItem; //1
    private JTextField jtfprdName; //2
    private JTextField jtfprdUnit; //3
    private JTextField jtfprdPrice;//4
    private JTextField jtfTotal;   //5   getresult()
    private JTextField jtfReStock; //6   getrestock()
    private JTextField jtfstrCName;//7
    private JTextField jtfinvTotal;//8
    private JButton btnNext;

    GUI() {
        super("Inventory Part 4 Program");
        //this.inventory = inventory;
        currentProdno = 0;

        JPanel jp;
        JLabel jl;
        JPanel outerPanel = new JPanel();
        outerPanel.setLayout(new BoxLayout(outerPanel, BoxLayout.Y_AXIS));

        JPanel titlePanel = new JPanel();
        titlePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
        jl = new JLabel("Inventory Part 4");
        titlePanel.add(jl);
        outerPanel.add(titlePanel);

        JPanel numberPanel = new JPanel();
        numberPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("   Number: " );
        numberPanel.add(jl);
        jtfprdItem = new JTextField (1);
        jtfprdItem.setEditable(false);
        numberPanel.add(jtfprdItem);
        outerPanel.add(numberPanel);

        JPanel number1Panel = new JPanel();
        number1Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("   Name: " );
        number1Panel.add(jl);
        jtfprdName = new JTextField (2);
        jtfprdName.setEditable(false);
        number1Panel.add(jtfprdName);
        outerPanel.add(number1Panel);

        JPanel number2Panel = new JPanel();
        number2Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("   Units: " );
        number2Panel.add(jl);
        jtfprdUnit = new JTextField(3);
        jtfprdUnit.setEditable(false);
        number2Panel.add(jtfprdUnit);
        outerPanel.add(number2Panel);

        JPanel number3Panel = new JPanel();
        number3Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("   Price: " );
        number3Panel.add(jl);
        jtfprdPrice = new JTextField(4);
        jtfprdPrice.setEditable(false);
        number3Panel.add(jtfprdPrice);
        outerPanel.add(number3Panel);

        JPanel number4Panel = new JPanel();
        number4Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("   Total: $ " );
        number4Panel.add(jl);
        jtfTotal = new JTextField(5);
        jtfTotal.setEditable(false);
        number4Panel.add(jtfTotal);
        outerPanel.add(number4Panel);

        JPanel number5Panel = new JPanel();
        number5Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("Restocking Fee: $ " );
        number5Panel.add(jl);
        jtfReStock = new JTextField(6);
        jtfReStock.setEditable(false);
        number5Panel.add(jtfReStock);
        outerPanel.add(number5Panel);

        JPanel number6Panel = new JPanel();
        number5Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("Restocking Fee: $ " );
        number5Panel.add(jl);
        jtfstrCName = new JTextField(7);
        jtfstrCName.setEditable(false);
        number5Panel.add(jtfstrCName);
        outerPanel.add(number6Panel);

        JPanel number7Panel = new JPanel();
        number6Panel.setLayout(new FlowLayout(FlowLayout.CENTER));
        jl = new JLabel("Total Invenory Value: $" );
        number6Panel.add(jl);
        jtfTotal = new JTextField(8);
        jtfTotal.setEditable(false);
        outerPanel.add(number7Panel);



        setContentPane(outerPanel);
        setResizable(false);
        setVisible(true);

      }



} // end GUI class



here is my main code
public class Inventory
{
public static void main(String args[])
{
Movie Products[] = new Movie[4];

Products[0] = new Movie("0", "Little Mermaid",26, 12.99, "G");
Products[1] = new Movie("1", "A Walk to Remember",15, 15.89, "PG");
Products[2] = new Movie("2", "Men in Black",8, 5.00, "PG");
Products[3] = new Movie("3", "Boyz in the hood",20, 21.15, "PG13");

  //initiate decimal format object
  DecimalFormat Currency = new DecimalFormat("#0.00");

  //print the inventory information
  System.out.print("\nInventory of DVD Movies:\n\n");

for(int index = 0; index < Products.length; index++) {
System.out.println("Number:  " + Products[index].getNum());
System.out.println("Name:   " + Products[index].getName());
System.out.println("Rating:  " + Products[index].getRating());
System.out.println("Stock:   " + Products[index].getStock());
System.out.println("Price:   $" + Currency.format(Products[index].getPrice()));
System.out.println("Restocking fee: $" + Currency.format(Products[index].getRestockingFee()));
System.out.println("Item Value: $" + Currency.format(Products[index].getInventoryTotal()));
}

  //sorting the array
  ProductInfo.SortInventory(Products);

  //print the inventory information
  System.out.print("\nSorted Inventory of DVD Movies:\n\n");

for(int index = 0; index < Products.length; index++) {
System.out.println("Number:  " + Products[index].getNum());
System.out.println("Name:   " + Products[index].getName());
System.out.println("Rating:  " + Products[index].getRating());
System.out.println("Stock:   " + Products[index].getStock());
System.out.println("Price:   $" + Currency.format(Products[index].getPrice()));
System.out.println("Restocking fee: $" + Currency.format(Products[index].getRestockingFee()));
System.out.println("Item Value: $" + Currency.format(Products[index].getInventoryTotal()));
}

  //calulcating total value and displaying
  Double totalInv = Products[0].CalculateTotalInventoryValue(Products);
  System.out.print("Total Inventory Value: $" + Currency.format(totalInv) + "\n");

// Import the java swing package so we can use swing controls like JFrame.

// Create a JFrame (application window with the title "HelloWorldSwing")
        JFrame frame = new JFrame("Inventory Of DVD's");

        // Set it so that it terminates the program when the window is closed.
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // Set the windows size and then show it.
        frame.setSize(300,300);
        frame.setVisible(true);

} // main

} // Inventory



if you create a class for your GUI.. just create a new instance of it in the main..
Was This Post Helpful? 0
  • +
  • -

#3 deepacc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 27-May 08

Re: How to call the GUI I created

Posted 06 June 2008 - 11:04 AM

View Postmensahero, on 6 Jun, 2008 - 10:56 AM, said:

View Postdeepacc, on 6 Jun, 2008 - 10:24 AM, said:

Hi Guys
THis is for Part 4 of my inventory program. I needed to create GUI interface. I have coded a GUI which is below not sure if its right or not. But I can not figure out how to call this in my main file Please help me I know the answer is prob so simple I am just lost.

here is my gui code
import java.util.Arrays;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//a liitle GUI
class GUI extends JFrame {
    protected double currentProdno;
    private JTextField jtfprdItem; //1
    private JTextField jtfprdName; //2
    private JTextField jtfprdUnit; //3
    private JTextField jtfprdPrice;//4
    private JTextField jtfTotal;   //5   getresult()
    private JTextField jtfReStock; //6   getrestock()
    private JTextField jtfstrCName;//7
    private JTextField jtfinvTotal;//8
    private JButton btnNext;

    GUI() {
        super("Inventory Part 4 Program");
        //this.inventory = inventory;
        currentProdno = 0;

        JPanel jp;
        JLabel jl;
        JPanel outerPanel = new JPanel();
        outerPanel.setLayout(new BoxLayout(outerPanel, BoxLayout.Y_AXIS));

        JPanel titlePanel = new JPanel();
        titlePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
        jl = new JLabel("Inventory Part 4");
        titlePanel.add(jl);
        outerPanel.add(titlePanel);

        JPanel numberPanel = new JPanel();
        numberPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("   Number: " );
        numberPanel.add(jl);
        jtfprdItem = new JTextField (1);
        jtfprdItem.setEditable(false);
        numberPanel.add(jtfprdItem);
        outerPanel.add(numberPanel);

        JPanel number1Panel = new JPanel();
        number1Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("   Name: " );
        number1Panel.add(jl);
        jtfprdName = new JTextField (2);
        jtfprdName.setEditable(false);
        number1Panel.add(jtfprdName);
        outerPanel.add(number1Panel);

        JPanel number2Panel = new JPanel();
        number2Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("   Units: " );
        number2Panel.add(jl);
        jtfprdUnit = new JTextField(3);
        jtfprdUnit.setEditable(false);
        number2Panel.add(jtfprdUnit);
        outerPanel.add(number2Panel);

        JPanel number3Panel = new JPanel();
        number3Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("   Price: " );
        number3Panel.add(jl);
        jtfprdPrice = new JTextField(4);
        jtfprdPrice.setEditable(false);
        number3Panel.add(jtfprdPrice);
        outerPanel.add(number3Panel);

        JPanel number4Panel = new JPanel();
        number4Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("   Total: $ " );
        number4Panel.add(jl);
        jtfTotal = new JTextField(5);
        jtfTotal.setEditable(false);
        number4Panel.add(jtfTotal);
        outerPanel.add(number4Panel);

        JPanel number5Panel = new JPanel();
        number5Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("Restocking Fee: $ " );
        number5Panel.add(jl);
        jtfReStock = new JTextField(6);
        jtfReStock.setEditable(false);
        number5Panel.add(jtfReStock);
        outerPanel.add(number5Panel);

        JPanel number6Panel = new JPanel();
        number5Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
        jl = new JLabel("Restocking Fee: $ " );
        number5Panel.add(jl);
        jtfstrCName = new JTextField(7);
        jtfstrCName.setEditable(false);
        number5Panel.add(jtfstrCName);
        outerPanel.add(number6Panel);

        JPanel number7Panel = new JPanel();
        number6Panel.setLayout(new FlowLayout(FlowLayout.CENTER));
        jl = new JLabel("Total Invenory Value: $" );
        number6Panel.add(jl);
        jtfTotal = new JTextField(8);
        jtfTotal.setEditable(false);
        outerPanel.add(number7Panel);



        setContentPane(outerPanel);
        setResizable(false);
        setVisible(true);

      }



} // end GUI class



here is my main code
public class Inventory
{
public static void main(String args[])
{
Movie Products[] = new Movie[4];

Products[0] = new Movie("0", "Little Mermaid",26, 12.99, "G");
Products[1] = new Movie("1", "A Walk to Remember",15, 15.89, "PG");
Products[2] = new Movie("2", "Men in Black",8, 5.00, "PG");
Products[3] = new Movie("3", "Boyz in the hood",20, 21.15, "PG13");

  //initiate decimal format object
  DecimalFormat Currency = new DecimalFormat("#0.00");

  //print the inventory information
  System.out.print("\nInventory of DVD Movies:\n\n");

for(int index = 0; index < Products.length; index++) {
System.out.println("Number:  " + Products[index].getNum());
System.out.println("Name:   " + Products[index].getName());
System.out.println("Rating:  " + Products[index].getRating());
System.out.println("Stock:   " + Products[index].getStock());
System.out.println("Price:   $" + Currency.format(Products[index].getPrice()));
System.out.println("Restocking fee: $" + Currency.format(Products[index].getRestockingFee()));
System.out.println("Item Value: $" + Currency.format(Products[index].getInventoryTotal()));
}

  //sorting the array
  ProductInfo.SortInventory(Products);

  //print the inventory information
  System.out.print("\nSorted Inventory of DVD Movies:\n\n");

for(int index = 0; index < Products.length; index++) {
System.out.println("Number:  " + Products[index].getNum());
System.out.println("Name:   " + Products[index].getName());
System.out.println("Rating:  " + Products[index].getRating());
System.out.println("Stock:   " + Products[index].getStock());
System.out.println("Price:   $" + Currency.format(Products[index].getPrice()));
System.out.println("Restocking fee: $" + Currency.format(Products[index].getRestockingFee()));
System.out.println("Item Value: $" + Currency.format(Products[index].getInventoryTotal()));
}

  //calulcating total value and displaying
  Double totalInv = Products[0].CalculateTotalInventoryValue(Products);
  System.out.print("Total Inventory Value: $" + Currency.format(totalInv) + "\n");

// Import the java swing package so we can use swing controls like JFrame.

// Create a JFrame (application window with the title "HelloWorldSwing")
        JFrame frame = new JFrame("Inventory Of DVD's");

        // Set it so that it terminates the program when the window is closed.
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        // Set the windows size and then show it.
        frame.setSize(300,300);
        frame.setVisible(true);

} // main

} // Inventory



if you create a class for your GUI.. just create a new instance of it in the main..


Thank you is that not what I did on line 171 i think????
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: How to call the GUI I created

Posted 06 June 2008 - 11:04 AM

Please post your code like this :code:

In your GUI class you have the call to the setSize() method missing

	setResizable(false);
	setSize(400, 300);
	setVisible(true);



You Inventory contains only one static method main()
You do not really create an Inventory object.. so you can just cut&paste your main() method from Inventory and put it in the GUI class.

If you want to keep (for emotional reasons) your old Inventory class it is ok keep it.

Remove your JFrame ..... stuff and add

   GUI gui = new GUI();



In your GUI class you will need a method to receive the movies

// at the beginning with your declarations of variables
Movie[] movie;
// index of the movie showed
int index;

// at the end
// code to reveive the movie to display
void setMovie(Movie[] movie) {
   // keep the movies
   this.movie = movie;
   index = 0;
   display();
}
// code that display movie[index] in the JTextField
void display() {
	// someting like that
	// jtfrdName.setText(movie[0].name);
}

   // here code to put movie[0] into your JTextField
   //
   ....
}



You will eventually need a button to switch from one movie to another
Was This Post Helpful? 1
  • +
  • -

#5 mensahero  Icon User is offline

  • I Desire...
  • member icon

Reputation: 17
  • View blog
  • Posts: 678
  • Joined: 26-May 08

Re: How to call the GUI I created

Posted 06 June 2008 - 11:11 AM

Quote

 JFrame frame = new JFrame("Inventory Of DVD's");



Thank you is that not what I did on line 171 i think????



Aww.. sorry for that.. I never taught that your GUI is actually just a JFrame.. :blink:

well indeed you create a JFrame.. I can see it clearly.. but where exactly did you create an instance of your GUI CLASS..

like what pbl said..

GUI gui = new GUI() ; << something like this.. :blink:
Was This Post Helpful? 0
  • +
  • -

#6 deepacc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 27-May 08

Re: How to call the GUI I created

Posted 06 June 2008 - 11:24 AM

View Postpbl, on 6 Jun, 2008 - 11:04 AM, said:

Please post your code like this :code:

In your GUI class you have the call to the setSize() method missing

	setResizable(false);
	setSize(400, 300);
	setVisible(true);



You Inventory contains only one static method main()
You do not really create an Inventory object.. so you can just cut&paste your main() method from Inventory and put it in the GUI class.

If you want to keep (for emotional reasons) your old Inventory class it is ok keep it.

Remove your JFrame ..... stuff and add

   GUI gui = new GUI();



In your GUI class you will need a method to receive the movies

// at the beginning with your declarations of variables
Movie[] movie;
// index of the movie showed
int index;

// at the end
// code to reveive the movie to display
void setMovie(Movie[] movie) {
   // keep the movies
   this.movie = movie;
   index = 0;
   display();
}
// code that display movie[index] in the JTextField
void display() {
	// someting like that
	// jtfrdName.setText(movie[0].name);
}

   // here code to put movie[0] into your JTextField
   //
   ....
}



You will eventually need a button to switch from one movie to another

// at the beginning with your declarations of variables
Movie[] movie;
// index of the movie showed
int index;

// at the end
// code to reveive the movie to display
void setMovie(Movie[] movie) {
   // keep the movies
   this.movie = movie;
   index = 0;
   display();
}
// code that display movie[index] in the JTextField
void display() {
	// someting like that
	// jtfrdName.setText(movie[0].name);
}

   // here code to put movie[0] into your JTextField
   //
   ....
}


I am confused on this part I now get a window but it doesnt display what i have in the array. I am so confused.
Was This Post Helpful? 0
  • +
  • -

#7 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: How to call the GUI I created

Posted 06 June 2008 - 12:11 PM

Ok on your main() you should do

	// create a GUI object
	GUI gui = new GUI();
	// sends the movies to the GUI
	gui.setMovie(movie);



Now in you GUI you have to receive the Movie and display it

// movies to display
Movie[] movie;
// index of the movie to display
int index = 0;

	GUI() {
	....
	....
   setVisible(true);
   setSize(400, 300);
   }

   // to receive the inventory to display
   void setMovie(Movie[] movie) {
	   // keep the movies in an array that we will be able to access
	   this.movie = movie;
	   // display the first one
	  display();
   }
   // code that display movie[index] in the JTextField
   void display() {
	// now here you have to add the code to take the fiels in movie[index]
	// and to put them in the JTextField of GUI
	// as I don't have the code of the class Movie I cannot write it for you
	// but it should look like
	jtfrdName.setText(movie[index].getName());
	jtfprdUnit.setText("" + movie[index].getUnit());
	and so on
	
   }

   // to display next movie
   void displayNext() {
	  index++;
	  if(index >= movie.length)   // wrap around
		index = 0;
	  display();
	}
	// display previous
	void displayPrevious() {
		index--;
		if(index < 0)					// wrap around
		  index = movie.length - 1;
		display();
	}
} // en class GUY


Was This Post Helpful? 0
  • +
  • -

#8 deepacc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 27-May 08

Re: How to call the GUI I created

Posted 06 June 2008 - 12:32 PM

View Postpbl, on 6 Jun, 2008 - 12:11 PM, said:

Ok on your main() you should do

	// create a GUI object
	GUI gui = new GUI();
	// sends the movies to the GUI
	gui.setMovie(movie);



Now in you GUI you have to receive the Movie and display it

// movies to display
Movie[] movie;
// index of the movie to display
int index = 0;

	GUI() {
	....
	....
   setVisible(true);
   setSize(400, 300);
   }

   // to receive the inventory to display
   void setMovie(Movie[] movie) {
	   // keep the movies in an array that we will be able to access
	   this.movie = movie;
	   // display the first one
	  display();
   }
   // code that display movie[index] in the JTextField
   void display() {
	// now here you have to add the code to take the fiels in movie[index]
	// and to put them in the JTextField of GUI
	// as I don't have the code of the class Movie I cannot write it for you
	// but it should look like
	jtfrdName.setText(movie[index].getName());
	jtfprdUnit.setText("" + movie[index].getUnit());
	and so on
	
   }

   // to display next movie
   void displayNext() {
	  index++;
	  if(index >= movie.length)   // wrap around
		index = 0;
	  display();
	}
	// display previous
	void displayPrevious() {
		index--;
		if(index < 0)					// wrap around
		  index = movie.length - 1;
		display();
	}
} // en class GUY


import java.io.*;
import java.text.*;
import java.util.Arrays;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Inventory
{
public static void main(String args[])
{
	JFrame fram = new JFrame ();

Movie Products[] = new Movie[4];

Products[0] = new Movie("0", "Little Mermaid",26, 12.99, "G");
Products[1] = new Movie("1", "A Walk to Remember",15, 15.89, "PG");
Products[2] = new Movie("2", "Men in Black",8, 5.00, "PG");
Products[3] = new Movie("3", "Boyz in the hood",20, 21.15, "PG13");

  //initiate decimal format object
  DecimalFormat Currency = new DecimalFormat("#0.00");

  //print the inventory information
  System.out.print("\nInventory of DVD Movies:\n\n");

for(int index = 0; index < Products.length; index++) {
System.out.println("Number:  " + Products[index].getNum());
System.out.println("Name:   " + Products[index].getName());
System.out.println("Rating:  " + Products[index].getRating());
System.out.println("Stock:   " + Products[index].getStock());
System.out.println("Price:   $" + Currency.format(Products[index].getPrice()));
System.out.println("Restocking fee: $" + Currency.format(Products[index].getRestockingFee()));
System.out.println("Item Value: $" + Currency.format(Products[index].getInventoryTotal()));
}

  //sorting the array
  ProductInfo.SortInventory(Products);

  //print the inventory information
  System.out.print("\nSorted Inventory of DVD Movies:\n\n");

for(int index = 0; index < Products.length; index++) {
System.out.println("Number:  " + Products[index].getNum());
System.out.println("Name:   " + Products[index].getName());
System.out.println("Rating:  " + Products[index].getRating());
System.out.println("Stock:   " + Products[index].getStock());
System.out.println("Price:   $" + Currency.format(Products[index].getPrice()));
System.out.println("Restocking fee: $" + Currency.format(Products[index].getRestockingFee()));
System.out.println("Item Value: $" + Currency.format(Products[index].getInventoryTotal()));
}

  //calulcating total value and displaying
  Double totalInv = Products[0].CalculateTotalInventoryValue(Products);
  System.out.print("Total Inventory Value: $" + Currency.format(totalInv) + "\n");

// create a GUI object
	GUI gui = new GUI();
	// sends the movies to the GUI
	gui.setMovie(movie);





} // main

} // Inventory





I do not have a movie class above is my main program with th emovie array is that what u mean? I am so sorry about all the questions this stuff is confusing for non java people. But you have been so helpful.
Was This Post Helpful? 0
  • +
  • -

#9 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: How to call the GUI I created

Posted 06 June 2008 - 12:41 PM

OK you can remove that vecause you use an instance of GUI as JFrame

JFrame fram = new JFrame ();


And sorry your array of Movies is called Products[]

so

gui.setMovie(Products);
Was This Post Helpful? 0
  • +
  • -

#10 deepacc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 27-May 08

Re: How to call the GUI I created

Posted 06 June 2008 - 12:50 PM

View Postpbl, on 6 Jun, 2008 - 12:41 PM, said:

OK you can remove that vecause you use an instance of GUI as JFrame

JFrame fram = new JFrame ();


And sorry your array of Movies is called Products[]

so

gui.setMovie(Products);

i know u must be ready to kill me
ok so I removed that and also put in gui.setMovie(Products);

I get this error


C:\Documents and Settings\paccda\Desktop\Inventory.java:60: cannot find symbol
symbol : method setMovie(Movie[])
location: class GUI
gui.setMovie(Products);
^
1 error

Tool completed with exit code 1



and in my gui code I get these errors
C:\Documents and Settings\paccda\Desktop\InventoryButtons.java:125: cannot find symbol
symbol : method display()
location: class GUI
display();
^
C:\Documents and Settings\paccda\Desktop\InventoryButtons.java:134: cannot find symbol
symbol : method display()
location: class GUI
display();
^
C:\Documents and Settings\paccda\Desktop\InventoryButtons.java:141: cannot find symbol
symbol : method display()
location: class GUI
display();
^
3 errors

Tool completed with exit code 1
Was This Post Helpful? 0
  • +
  • -

#11 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: How to call the GUI I created

Posted 06 June 2008 - 01:11 PM

Repost you code
you obviously have a typo
Was This Post Helpful? 0
  • +
  • -

#12 deepacc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 27-May 08

Re: How to call the GUI I created

Posted 06 June 2008 - 01:33 PM

View Postpbl, on 6 Jun, 2008 - 01:11 PM, said:

Repost you code
you obviously have a typo

import java.util.Arrays;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//a liitle GUI
class GUI extends JFrame {
	protected double currentProdno;
	private JTextField jtfprdItem; //1
	private JTextField jtfprdName; //2
	private JTextField jtfprdUnit; //3
	private JTextField jtfprdPrice;//4
	private JTextField jtfTotal;   //5   getresult()
	private JTextField jtfReStock; //6   getrestock()
	private JTextField jtfstrCName;//7
	private JTextField jtfinvTotal;//8
	private JButton btnNext;

// movies to display
Movie[] movie;
// index of the movie to display
int index = 0;


	GUI(){
		super("Inventory Part 4 Program");
		//this.inventory = inventory;
		currentProdno = 0;

		JPanel jp;
		JLabel jl;
		JPanel outerPanel = new JPanel();
		outerPanel.setLayout(new BoxLayout(outerPanel, BoxLayout.Y_AXIS));

		JPanel titlePanel = new JPanel();
		titlePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
		jl = new JLabel("Inventory Part 4");
		titlePanel.add(jl);
		outerPanel.add(titlePanel);

		JPanel numberPanel = new JPanel();
		numberPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
		jl = new JLabel("   Number: " );
		numberPanel.add(jl);
		jtfprdItem = new JTextField (1);
		jtfprdItem.setEditable(false);
		numberPanel.add(jtfprdItem);
		outerPanel.add(numberPanel);

		JPanel number1Panel = new JPanel();
		number1Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
		jl = new JLabel("   Name: " );
		number1Panel.add(jl);
		jtfprdName = new JTextField (2);
		jtfprdName.setEditable(false);
		number1Panel.add(jtfprdName);
		outerPanel.add(number1Panel);

		JPanel number2Panel = new JPanel();
		number2Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
		jl = new JLabel("   Units: " );
		number2Panel.add(jl);
		jtfprdUnit = new JTextField(3);
		jtfprdUnit.setEditable(false);
		number2Panel.add(jtfprdUnit);
		outerPanel.add(number2Panel);

		JPanel number3Panel = new JPanel();
		number3Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
		jl = new JLabel("   Price: " );
		number3Panel.add(jl);
		jtfprdPrice = new JTextField(4);
		jtfprdPrice.setEditable(false);
		number3Panel.add(jtfprdPrice);
		outerPanel.add(number3Panel);

		JPanel number4Panel = new JPanel();
		number4Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
		jl = new JLabel("   Total: $ " );
		number4Panel.add(jl);
		jtfTotal = new JTextField(5);
		jtfTotal.setEditable(false);
		number4Panel.add(jtfTotal);
		outerPanel.add(number4Panel);

		JPanel number5Panel = new JPanel();
		number5Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
		jl = new JLabel("Restocking Fee: $ " );
		number5Panel.add(jl);
		jtfReStock = new JTextField(6);
		jtfReStock.setEditable(false);
		number5Panel.add(jtfReStock);
		outerPanel.add(number5Panel);

		JPanel number6Panel = new JPanel();
		number5Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
		jl = new JLabel("Restocking Fee: $ " );
		number5Panel.add(jl);
		jtfstrCName = new JTextField(7);
		jtfstrCName.setEditable(false);
		number5Panel.add(jtfstrCName);
		outerPanel.add(number6Panel);

		JPanel number7Panel = new JPanel();
		number6Panel.setLayout(new FlowLayout(FlowLayout.CENTER));
		jl = new JLabel("Total Invenory Value: $" );
		number6Panel.add(jl);
		jtfTotal = new JTextField(8);
		jtfTotal.setEditable(false);
		outerPanel.add(number7Panel);



		setContentPane(outerPanel);
		setResizable(false);
		setSize(400, 300);
		setVisible(true);

	  }

 // to receive the inventory to display
   void setMovie(Movie[] movie) {
	   // keep the movies in an array that we will be able to access
	   this.movie = movie;
	   // display the first one
	  display();
   }


   // to display next movie
   void displayNext() {
	  index++;
	  if(index >= movie.length)   // wrap around
		index = 0;
	  display();
	}
	// display previous
	void displayPrevious() {
		index--;
		if(index < 0)					// wrap around
		  index = movie.length - 1;
		display();
	}


} // end GUI class




Inventory code
import java.io.*;
import java.text.*;
import java.util.Arrays;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Inventory
{
public static void main(String args[])
{
	JFrame fram = new JFrame ();

Movie Products[] = new Movie[4];

Products[0] = new Movie("0", "Little Mermaid",26, 12.99, "G");
Products[1] = new Movie("1", "A Walk to Remember",15, 15.89, "PG");
Products[2] = new Movie("2", "Men in Black",8, 5.00, "PG");
Products[3] = new Movie("3", "Boyz in the hood",20, 21.15, "PG13");

  //initiate decimal format object
  DecimalFormat Currency = new DecimalFormat("#0.00");

  //print the inventory information
  System.out.print("\nInventory of DVD Movies:\n\n");

for(int index = 0; index < Products.length; index++) {
System.out.println("Number:  " + Products[index].getNum());
System.out.println("Name:   " + Products[index].getName());
System.out.println("Rating:  " + Products[index].getRating());
System.out.println("Stock:   " + Products[index].getStock());
System.out.println("Price:   $" + Currency.format(Products[index].getPrice()));
System.out.println("Restocking fee: $" + Currency.format(Products[index].getRestockingFee()));
System.out.println("Item Value: $" + Currency.format(Products[index].getInventoryTotal()));
}

  //sorting the array
  ProductInfo.SortInventory(Products);

  //print the inventory information
  System.out.print("\nSorted Inventory of DVD Movies:\n\n");

for(int index = 0; index < Products.length; index++) {
System.out.println("Number:  " + Products[index].getNum());
System.out.println("Name:   " + Products[index].getName());
System.out.println("Rating:  " + Products[index].getRating());
System.out.println("Stock:   " + Products[index].getStock());
System.out.println("Price:   $" + Currency.format(Products[index].getPrice()));
System.out.println("Restocking fee: $" + Currency.format(Products[index].getRestockingFee()));
System.out.println("Item Value: $" + Currency.format(Products[index].getInventoryTotal()));
}

  //calulcating total value and displaying
  Double totalInv = Products[0].CalculateTotalInventoryValue(Products);
  System.out.print("Total Inventory Value: $" + Currency.format(totalInv) + "\n");

// create a GUI object
	GUI gui = new GUI();
	// sends the movies to the GUI
	gui.setMovie(Products);





} // main

} // Inventory






also this is my product class code
import java.io.*;
import java.text.*;
import java.util.Arrays;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Inventory
{
public static void main(String args[])
{
	JFrame fram = new JFrame ();

Movie Products[] = new Movie[4];

Products[0] = new Movie("0", "Little Mermaid",26, 12.99, "G");
Products[1] = new Movie("1", "A Walk to Remember",15, 15.89, "PG");
Products[2] = new Movie("2", "Men in Black",8, 5.00, "PG");
Products[3] = new Movie("3", "Boyz in the hood",20, 21.15, "PG13");

  //initiate decimal format object
  DecimalFormat Currency = new DecimalFormat("#0.00");

  //print the inventory information
  System.out.print("\nInventory of DVD Movies:\n\n");

for(int index = 0; index < Products.length; index++) {
System.out.println("Number:  " + Products[index].getNum());
System.out.println("Name:   " + Products[index].getName());
System.out.println("Rating:  " + Products[index].getRating());
System.out.println("Stock:   " + Products[index].getStock());
System.out.println("Price:   $" + Currency.format(Products[index].getPrice()));
System.out.println("Restocking fee: $" + Currency.format(Products[index].getRestockingFee()));
System.out.println("Item Value: $" + Currency.format(Products[index].getInventoryTotal()));
}

  //sorting the array
  ProductInfo.SortInventory(Products);

  //print the inventory information
  System.out.print("\nSorted Inventory of DVD Movies:\n\n");

for(int index = 0; index < Products.length; index++) {
System.out.println("Number:  " + Products[index].getNum());
System.out.println("Name:   " + Products[index].getName());
System.out.println("Rating:  " + Products[index].getRating());
System.out.println("Stock:   " + Products[index].getStock());
System.out.println("Price:   $" + Currency.format(Products[index].getPrice()));
System.out.println("Restocking fee: $" + Currency.format(Products[index].getRestockingFee()));
System.out.println("Item Value: $" + Currency.format(Products[index].getInventoryTotal()));
}

  //calulcating total value and displaying
  Double totalInv = Products[0].CalculateTotalInventoryValue(Products);
  System.out.print("Total Inventory Value: $" + Currency.format(totalInv) + "\n");

// create a GUI object
	GUI gui = new GUI();
	// sends the movies to the GUI
	gui.setMovie(Products);





} // main

} // Inventory






View Postdeepacc, on 6 Jun, 2008 - 01:30 PM, said:

View Postpbl, on 6 Jun, 2008 - 01:11 PM, said:

Repost you code
you obviously have a typo

import java.util.Arrays;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//a liitle GUI
class GUI extends JFrame {
	protected double currentProdno;
	private JTextField jtfprdItem; //1
	private JTextField jtfprdName; //2
	private JTextField jtfprdUnit; //3
	private JTextField jtfprdPrice;//4
	private JTextField jtfTotal;   //5   getresult()
	private JTextField jtfReStock; //6   getrestock()
	private JTextField jtfstrCName;//7
	private JTextField jtfinvTotal;//8
	private JButton btnNext;

// movies to display
Movie[] movie;
// index of the movie to display
int index = 0;


	GUI(){
		super("Inventory Part 4 Program");
		//this.inventory = inventory;
		currentProdno = 0;

		JPanel jp;
		JLabel jl;
		JPanel outerPanel = new JPanel();
		outerPanel.setLayout(new BoxLayout(outerPanel, BoxLayout.Y_AXIS));

		JPanel titlePanel = new JPanel();
		titlePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
		jl = new JLabel("Inventory Part 4");
		titlePanel.add(jl);
		outerPanel.add(titlePanel);

		JPanel numberPanel = new JPanel();
		numberPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
		jl = new JLabel("   Number: " );
		numberPanel.add(jl);
		jtfprdItem = new JTextField (1);
		jtfprdItem.setEditable(false);
		numberPanel.add(jtfprdItem);
		outerPanel.add(numberPanel);

		JPanel number1Panel = new JPanel();
		number1Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
		jl = new JLabel("   Name: " );
		number1Panel.add(jl);
		jtfprdName = new JTextField (2);
		jtfprdName.setEditable(false);
		number1Panel.add(jtfprdName);
		outerPanel.add(number1Panel);

		JPanel number2Panel = new JPanel();
		number2Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
		jl = new JLabel("   Units: " );
		number2Panel.add(jl);
		jtfprdUnit = new JTextField(3);
		jtfprdUnit.setEditable(false);
		number2Panel.add(jtfprdUnit);
		outerPanel.add(number2Panel);

		JPanel number3Panel = new JPanel();
		number3Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
		jl = new JLabel("   Price: " );
		number3Panel.add(jl);
		jtfprdPrice = new JTextField(4);
		jtfprdPrice.setEditable(false);
		number3Panel.add(jtfprdPrice);
		outerPanel.add(number3Panel);

		JPanel number4Panel = new JPanel();
		number4Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
		jl = new JLabel("   Total: $ " );
		number4Panel.add(jl);
		jtfTotal = new JTextField(5);
		jtfTotal.setEditable(false);
		number4Panel.add(jtfTotal);
		outerPanel.add(number4Panel);

		JPanel number5Panel = new JPanel();
		number5Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
		jl = new JLabel("Restocking Fee: $ " );
		number5Panel.add(jl);
		jtfReStock = new JTextField(6);
		jtfReStock.setEditable(false);
		number5Panel.add(jtfReStock);
		outerPanel.add(number5Panel);

		JPanel number6Panel = new JPanel();
		number5Panel.setLayout(new FlowLayout(FlowLayout.LEFT));
		jl = new JLabel("Restocking Fee: $ " );
		number5Panel.add(jl);
		jtfstrCName = new JTextField(7);
		jtfstrCName.setEditable(false);
		number5Panel.add(jtfstrCName);
		outerPanel.add(number6Panel);

		JPanel number7Panel = new JPanel();
		number6Panel.setLayout(new FlowLayout(FlowLayout.CENTER));
		jl = new JLabel("Total Invenory Value: $" );
		number6Panel.add(jl);
		jtfTotal = new JTextField(8);
		jtfTotal.setEditable(false);
		outerPanel.add(number7Panel);



		setContentPane(outerPanel);
		setResizable(false);
		setSize(400, 300);
		setVisible(true);

	  }

 // to receive the inventory to display
   void setMovie(Movie[] movie) {
	   // keep the movies in an array that we will be able to access
	   this.movie = movie;
	   // display the first one
	  display();
   }


   // to display next movie
   void displayNext() {
	  index++;
	  if(index >= movie.length)   // wrap around
		index = 0;
	  display();
	}
	// display previous
	void displayPrevious() {
		index--;
		if(index < 0)					// wrap around
		  index = movie.length - 1;
		display();
	}


} // end GUI class




Inventory code
import java.io.*;
import java.text.*;
import java.util.Arrays;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Inventory
{
public static void main(String args[])
{
	JFrame fram = new JFrame ();

Movie Products[] = new Movie[4];

Products[0] = new Movie("0", "Little Mermaid",26, 12.99, "G");
Products[1] = new Movie("1", "A Walk to Remember",15, 15.89, "PG");
Products[2] = new Movie("2", "Men in Black",8, 5.00, "PG");
Products[3] = new Movie("3", "Boyz in the hood",20, 21.15, "PG13");

  //initiate decimal format object
  DecimalFormat Currency = new DecimalFormat("#0.00");

  //print the inventory information
  System.out.print("\nInventory of DVD Movies:\n\n");

for(int index = 0; index < Products.length; index++) {
System.out.println("Number:  " + Products[index].getNum());
System.out.println("Name:   " + Products[index].getName());
System.out.println("Rating:  " + Products[index].getRating());
System.out.println("Stock:   " + Products[index].getStock());
System.out.println("Price:   $" + Currency.format(Products[index].getPrice()));
System.out.println("Restocking fee: $" + Currency.format(Products[index].getRestockingFee()));
System.out.println("Item Value: $" + Currency.format(Products[index].getInventoryTotal()));
}

  //sorting the array
  ProductInfo.SortInventory(Products);

  //print the inventory information
  System.out.print("\nSorted Inventory of DVD Movies:\n\n");

for(int index = 0; index < Products.length; index++) {
System.out.println("Number:  " + Products[index].getNum());
System.out.println("Name:   " + Products[index].getName());
System.out.println("Rating:  " + Products[index].getRating());
System.out.println("Stock:   " + Products[index].getStock());
System.out.println("Price:   $" + Currency.format(Products[index].getPrice()));
System.out.println("Restocking fee: $" + Currency.format(Products[index].getRestockingFee()));
System.out.println("Item Value: $" + Currency.format(Products[index].getInventoryTotal()));
}

  //calulcating total value and displaying
  Double totalInv = Products[0].CalculateTotalInventoryValue(Products);
  System.out.print("Total Inventory Value: $" + Currency.format(totalInv) + "\n");

// create a GUI object
	GUI gui = new GUI();
	// sends the movies to the GUI
	gui.setMovie(Products);





} // main

} // Inventory






also this is my product class code
import java.io.*;
import java.text.*;
import java.util.Arrays;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Inventory
{
public static void main(String args[])
{
	JFrame fram = new JFrame ();

Movie Products[] = new Movie[4];

Products[0] = new Movie("0", "Little Mermaid",26, 12.99, "G");
Products[1] = new Movie("1", "A Walk to Remember",15, 15.89, "PG");
Products[2] = new Movie("2", "Men in Black",8, 5.00, "PG");
Products[3] = new Movie("3", "Boyz in the hood",20, 21.15, "PG13");

  //initiate decimal format object
  DecimalFormat Currency = new DecimalFormat("#0.00");

  //print the inventory information
  System.out.print("\nInventory of DVD Movies:\n\n");

for(int index = 0; index < Products.length; index++) {
System.out.println("Number:  " + Products[index].getNum());
System.out.println("Name:   " + Products[index].getName());
System.out.println("Rating:  " + Products[index].getRating());
System.out.println("Stock:   " + Products[index].getStock());
System.out.println("Price:   $" + Currency.format(Products[index].getPrice()));
System.out.println("Restocking fee: $" + Currency.format(Products[index].getRestockingFee()));
System.out.println("Item Value: $" + Currency.format(Products[index].getInventoryTotal()));
}

  //sorting the array
  ProductInfo.SortInventory(Products);

  //print the inventory information
  System.out.print("\nSorted Inventory of DVD Movies:\n\n");

for(int index = 0; index < Products.length; index++) {
System.out.println("Number:  " + Products[index].getNum());
System.out.println("Name:   " + Products[index].getName());
System.out.println("Rating:  " + Products[index].getRating());
System.out.println("Stock:   " + Products[index].getStock());
System.out.println("Price:   $" + Currency.format(Products[index].getPrice()));
System.out.println("Restocking fee: $" + Currency.format(Products[index].getRestockingFee()));
System.out.println("Item Value: $" + Currency.format(Products[index].getInventoryTotal()));
}

  //calulcating total value and displaying
  Double totalInv = Products[0].CalculateTotalInventoryValue(Products);
  System.out.print("Total Inventory Value: $" + Currency.format(totalInv) + "\n");

// create a GUI object
	GUI gui = new GUI();
	// sends the movies to the GUI
	gui.setMovie(Products);





} // main

} // Inventory





sorry the last code was a dup here is the prodcutinfo class
import java.util.Arrays;
class ProductInfo // class to store product information
{
private String num; // product's item number
private String name; // product's item name
private int stock; // number of item in stock
private double price; // price each of item
 
ProductInfo(String itemNumber, String itemName, int stockQty, double priceEach) // constructor for product info
{
num = itemNumber;
name = itemName;
stock = stockQty;
price = priceEach;
}
 
public String getNum()
{
return num;
}
public String getName()
{
return name;
}
public int getStock()
{
return stock;
}
public double getPrice()
{
return price;
}
public double getInventoryTotal()
{
return price * stock;
}
 
	//method to calculate total value of the inventory in an array of products
 public double CalculateTotalInventoryValue(ProductInfo[] product)
 {
  Double total = 0.0;
  for(int index = 0; index < product.length; index++)
  {
   ProductInfo inv = product[index];
   total += inv.getInventoryTotal();
  }
 
  return total;
 }
 
 //method to sort products based on product name
 public static ProductInfo[] SortInventory(ProductInfo[] product)
 {
  ProductInfo tmp;
  for (int i1 = 0; i1 < product.length; i1++)
  {
   for (int j1 = i1 + 1; j1 < product.length; j1++)
   {
	String s1 = product[i1].getName();
	String s2 = product[j1].getName();
	if( s1.compareTo(s2) > 0)
	{
	 tmp = product[i1];
	 product[i1] = product[j1];
	 product[j1] = tmp;
	}
   }
  }
 
  return product;
 
 }
 
} // end class ProductInfo


Was This Post Helpful? 0
  • +
  • -

#13 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: How to call the GUI I created

Posted 06 June 2008 - 01:49 PM

You have that missing in GUI

// code that display movie[index] in the JTextField
   void display() {
	// now here you have to add the code to take the fiels in movie[index]
	// and to put them in the JTextField of GUI
	// as I don't have the code of the class Movie I cannot write it for you
	// but it should look like
	jtfrdName.setText(movie[index].getName());
	jtfprdUnit.setText("" + movie[index].getUnit());
	///and so on
	
   }



That explains your last 3 errors
Was This Post Helpful? 1
  • +
  • -

#14 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: How to call the GUI I created

Posted 06 June 2008 - 01:54 PM

Works for me but I had to create my own movie class

It compiles....

public class Movie extends ProductInfo {

	Movie(String a, String b, int i, double x, String c) {
		super(a, b, i, x);
	}
	String getRating() {
		return "";
	}
	double getRestockingFee() {
		return 0.0;
	}
}


This post has been edited by pbl: 06 June 2008 - 01:54 PM

Was This Post Helpful? 1
  • +
  • -

#15 deepacc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 27-May 08

Re: How to call the GUI I created

Posted 06 June 2008 - 02:05 PM

View Postpbl, on 6 Jun, 2008 - 01:54 PM, said:

Works for me but I had to create my own movie class

It compiles....

public class Movie extends ProductInfo {

	Movie(String a, String b, int i, double x, String c) {
		super(a, b, i, x);
	}
	String getRating() {
		return "";
	}
	double getRestockingFee() {
		return 0.0;
	}
}


Thank you so i need that in my GUi code correct?
 // code that display movie[index] in the JTextField
		 void display() {
		  // now here you have to add the code to take the fiels in movie[index]
		  // and to put them in the JTextField of GUI
		  // as I don't have the code of the class Movie I cannot write it for you
		  // but it should look like
		  jtfrdName.setText(movie[index].getName());
		  jtfprdUnit.setText("" + movie[index].getUnit());
		  jtfprdItem.setText("" + movie[index].getItem());
		  ///and so on




So i have to include each here what does in "" then = movie?
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2