Welcome to Dream.In.Code
Become a Java Expert!

Join 150,038 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,586 people online right now. Registration is fast and FREE... Join Now!




How to call the GUI I created

2 Pages V  1 2 >  
Reply to this topicStart new topic

How to call the GUI I created

deepacc
6 Jun, 2008 - 09:24 AM
Post #1

New D.I.C Head
*

Joined: 27 May, 2008
Posts: 26

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
User is offlineProfile CardPM
+Quote Post

mensahero
RE: How To Call The GUI I Created
6 Jun, 2008 - 09:56 AM
Post #2

c0mput3rz Are Only Human
Group Icon

Joined: 26 May, 2008
Posts: 664



Thanked: 17 times
Dream Kudos: 75
My Contributions
QUOTE(deepacc @ 6 Jun, 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.

java

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..

User is offlineProfile CardPM
+Quote Post

deepacc
RE: How To Call The GUI I Created
6 Jun, 2008 - 10:04 AM
Post #3

New D.I.C Head
*

Joined: 27 May, 2008
Posts: 26

QUOTE(mensahero @ 6 Jun, 2008 - 10:56 AM) *

QUOTE(deepacc @ 6 Jun, 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.

java

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????

User is offlineProfile CardPM
+Quote Post

pbl
RE: How To Call The GUI I Created
6 Jun, 2008 - 10:04 AM
Post #4

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
Please post your code like this code.gif

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

CODE

    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

CODE

   GUI gui = new GUI();


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

CODE

// 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

User is online!Profile CardPM
+Quote Post

mensahero
RE: How To Call The GUI I Created
6 Jun, 2008 - 10:11 AM
Post #5

c0mput3rz Are Only Human
Group Icon

Joined: 26 May, 2008
Posts: 664



Thanked: 17 times
Dream Kudos: 75
My Contributions
QUOTE


CODE

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.gif

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.gif

User is offlineProfile CardPM
+Quote Post

deepacc
RE: How To Call The GUI I Created
6 Jun, 2008 - 10:24 AM
Post #6

New D.I.C Head
*

Joined: 27 May, 2008
Posts: 26

QUOTE(pbl @ 6 Jun, 2008 - 11:04 AM) *

Please post your code like this code.gif

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

CODE

    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

CODE

   GUI gui = new GUI();


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

CODE

// 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

CODE

// 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.

User is offlineProfile CardPM
+Quote Post

pbl
RE: How To Call The GUI I Created
6 Jun, 2008 - 11:11 AM
Post #7

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions

Ok on your main() you should do

CODE

    // 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

CODE

// 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

User is online!Profile CardPM
+Quote Post

deepacc
RE: How To Call The GUI I Created
6 Jun, 2008 - 11:32 AM
Post #8

New D.I.C Head
*

Joined: 27 May, 2008
Posts: 26

QUOTE(pbl @ 6 Jun, 2008 - 12:11 PM) *

Ok on your main() you should do

CODE

    // 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

CODE

// 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


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(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.
User is offlineProfile CardPM
+Quote Post

pbl
RE: How To Call The GUI I Created
6 Jun, 2008 - 11:41 AM
Post #9

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
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);


User is online!Profile CardPM
+Quote Post

deepacc
RE: How To Call The GUI I Created
6 Jun, 2008 - 11:50 AM
Post #10

New D.I.C Head
*

Joined: 27 May, 2008
Posts: 26

QUOTE(pbl @ 6 Jun, 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);

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


User is offlineProfile CardPM
+Quote Post

pbl
RE: How To Call The GUI I Created
6 Jun, 2008 - 12:11 PM
Post #11

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
Repost you code
you obviously have a typo
User is online!Profile CardPM
+Quote Post

deepacc
RE: How To Call The GUI I Created
6 Jun, 2008 - 12:33 PM
Post #12

New D.I.C Head
*

Joined: 27 May, 2008
Posts: 26

QUOTE(pbl @ 6 Jun, 2008 - 01:11 PM) *

Repost you code
you obviously have a typo

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;

// 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