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!
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.
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);
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");
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.
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);
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");
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.
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);
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");
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
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.
// 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
// 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
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");
//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.
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
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);
// 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