Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-25-2008, 10:29 AM
Member
 
Join Date: Jul 2008
Posts: 20
booter4429 is on a distinguished road
Looking for some help.
Code:
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Inventory5 { public static void main(String[] args) { Movie dvd = null; Inventory inventory = new Inventory(); dvd = new Movie(15035, "The Davinci Code", 18, 19.99f, 2001); System.out.println(dvd); inventory.addMovie(dvd); dvd = new Movie(24478, "Fight Club", 14, 20.99f, 1998); System.out.println(dvd); inventory.addMovie(dvd); dvd = new Movie(32059, "Ladder 49", 1, 21.99f, 1995); System.out.println(dvd); inventory.addMovie(dvd); dvd = new Movie(35989, "National Treasure", 15, 18.99f, 2003); inventory.addMovie(dvd); System.out.println(dvd); dvd = new Movie(14418, "Facing the Giants", 10, 21.99f, 2006); System.out.println(dvd); inventory.addMovie(dvd); dvd = new Movie(13679, "Crimson Tide", 9, 7.99f, 2005); System.out.println(dvd); System.out.println("\nEnd of DVD collection!\n"); inventory.addMovie(dvd); inventory.printInventory(); new InventoryGUI(inventory); } } class DVD { private int itemNo; private String title; private int inStock; private float unitPrice; DVD(int itemNo, String title, int inStock, float unitPrice) { this.itemNo = itemNo; this.title = title; this.inStock = inStock; this.unitPrice = unitPrice; } public int getItemNo() { return itemNo; } public String getTitle() { return title; } public int getInStock() { return inStock; } public float getUnitPrice() { return unitPrice; } public float value() { return inStock * unitPrice; } public String toString() { return String.format("ItemNo=%2d Title=%-22s InStock=%3d Price=$%7.2f Value=$%8.2f", itemNo, title, inStock, unitPrice, value()); } } class Inventory { private final int INVENTORY_SIZE = 30; private DVD[] items; private int numItems; Inventory() { items = new Movie[INVENTORY_SIZE]; numItems = 0; } public int getNumItems() { return numItems; } public DVD getDVD(int n) { return items[n]; } public void addMovie(DVD item) { items[numItems] = item; ++numItems; } public double value() { double sumOfInventory = 0.0; for (int i = 0; i < numItems; i++) sumOfInventory += items[i].value(); return sumOfInventory; } public void printInventory() { System.out.println("\nAllen's DVD Inventory\n"); if (numItems <= 0) { System.out.println("Inventory is empty at the moment.\n"); } else { for (int i = 0; i < numItems; i++) System.out.printf("%3d %s\n", i, items[i]); System.out.printf("\nTotal value in inventory is $%,.2f\n\n", value()); } } } class Movie extends DVD { private int movieYear; public Movie(int MovieID, String itemName, int quantityOnHand, float itemPrice, int year) { super(MovieID, itemName, quantityOnHand, itemPrice); this.movieYear = movieYear; } public void setYear(int year) { movieYear = year; } public int getMovieYear() { return movieYear; } public float value() { return super.value() + restockingFee(); } public float restockingFee() { return super.value() * 0.05f; } } class InventoryGUI extends JFrame { private Inventory theInventory; private int index = 0; private final JLabel itemNumberLabel = new JLabel(" Item Number:"); private JTextField itemNumberText; private final JLabel prodnameLabel = new JLabel(" Product Name:"); private JTextField prodnameText; private final JLabel prodpriceLabel = new JLabel(" Price:"); private JTextField prodpriceText; private final JLabel numinstockLabel = new JLabel(" Number in Stock:"); private JTextField numinstockText; private final JLabel valueLabel = new JLabel(" Value:"); private JTextField valueText; private final JLabel restockingFeeLabel = new JLabel(" Restocking Fee:"); private JTextField restockingFeeText; private final JLabel totalValueLabel = new JLabel(" Inventory Total Value:"); private JTextField totalValueText; private JPanel centerPanel; private JPanel buttonPanel; InventoryGUI(Inventory inventory) { super("Allen's Movie Inventory"); final Dimension dim = new Dimension(140, 20); final FlowLayout flo = new FlowLayout(FlowLayout.LEFT); JPanel jp; theInventory = inventory; centerPanel = new JPanel(); centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS)); buttonPanel = new JPanel(); JButton nextButton = new JButton("Next"); nextButton.addActionListener(new NextButtonHandler()); buttonPanel.add(nextButton); centerPanel.add(buttonPanel); buttonPanel = new JPanel(); JButton previousButton = new JButton("Previous"); previousButton.addActionListener(new PreviousHandler()); buttonPanel.add(previousButton); centerPanel.add(buttonPanel); buttonPanel = new JPanel(); JButton firstButton = new JButton("First"); firstButton.addActionListener(new FirstHandler()); buttonPanel.add(firstButton); centerPanel.add(buttonPanel); buttonPanel = new JPanel(); JButton lastButton = new JButton("Last"); lastButton.addActionListener(new LastHandler()); buttonPanel.add(lastButton); centerPanel.add(buttonPanel); jp = new JPanel(flo); itemNumberLabel.setPreferredSize(dim); jp.add(itemNumberLabel); itemNumberText = new JTextField(10); itemNumberText.setEditable(false); jp.add(itemNumberText); centerPanel.add(jp); jp = new JPanel(flo); prodnameLabel.setPreferredSize(dim); jp.add(prodnameLabel); prodnameText = new JTextField(10); prodnameText.setEditable(false); jp.add(prodnameText); centerPanel.add(jp); jp = new JPanel(flo); prodpriceLabel.setPreferredSize(dim); jp.add(prodpriceLabel); prodpriceText = new JTextField(10); prodpriceText.setEditable(false); jp.add(prodpriceText); centerPanel.add(jp); jp = new JPanel(flo); numinstockLabel.setPreferredSize(dim); jp.add(numinstockLabel); numinstockText = new JTextField(10); numinstockText.setEditable(false); jp.add(numinstockText); centerPanel.add(jp); jp = new JPanel(flo); restockingFeeLabel.setPreferredSize(dim); jp.add(restockingFeeLabel); restockingFeeText = new JTextField(10); restockingFeeText.setEditable(false); jp.add(restockingFeeText); centerPanel.add(jp); jp = new JPanel(flo); valueLabel.setPreferredSize(dim); jp.add(valueLabel); valueText = new JTextField(10); valueText.setEditable(false); jp.add(valueText); centerPanel.add(jp); jp = new JPanel(flo); totalValueLabel.setPreferredSize(dim); jp.add(totalValueLabel); totalValueText = new JTextField(10); totalValueText.setEditable(false); jp.add(totalValueText); centerPanel.add(jp); setContentPane(centerPanel); repaintGUI(); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(360, 450); setResizable(false); setLocationRelativeTo(null); setVisible(true); } public void repaintGUI() { Movie temp = (Movie) theInventory.getDVD(index); if (temp != null) { itemNumberText.setText("" + temp.getItemNo()); prodnameText.setText(temp.getTitle()); prodpriceText.setText(String.format("$%.2f", temp.getUnitPrice())); restockingFeeText.setText(String.format("$%.2f", temp.restockingFee())); numinstockText.setText("" + temp.getInStock()); valueText.setText(String.format("$%.2f", temp.value())); } totalValueText.setText(String.format("$%.2f", theInventory.value())); } class NextButtonHandler implements ActionListener { public void actionPerformed(ActionEvent e) { int numItems = theInventory.getNumItems(); index = (++index) % numItems; repaintGUI(); } } class PreviousHandler implements ActionListener { public void actionPerformed(ActionEvent e) { int numItems = theInventory.getNumItems(); index = (--index) % numItems; repaintGUI(); } } class FirstHandler implements ActionListener { public void actionPerformed(ActionEvent e) { int numItems = theInventory.getNumItems(); index = (index) % numItems; repaintGUI(); } } class LastHandler implements ActionListener { public void actionPerformed(ActionEvent e) { int numItems = theInventory.getNumItems(); index = (index) % numItems; repaintGUI(); } } }

How do I Modify the Inventory Program by adding a button to the GUI that allows the user to move to the first item, the previous item, the next item, and the last item in the inventory. If the first item is displayed and the user clicks on the Previous button, the last item should display. If the last item is displayed and the user clicks on the Next button, the first item should display.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-25-2008, 10:57 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,545
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
You have lots of questions here. Seems to me, first of all you have add an button. Did you do that? Later you have to think about the functionality of the button.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-25-2008, 04:15 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
The program appears to have buttons and listeners.
If you get errors, copy and paste them here with your questions.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 08-25-2008, 06:13 PM
Member
 
Join Date: Jul 2008
Posts: 20
booter4429 is on a distinguished road
Quote:
Originally Posted by Norm View Post
The program appears to have buttons and listeners.
If you get errors, copy and paste them here with your questions.
I'm not getting any errors, but I don't know how to work with the first,last, and previous buttons. Any help will be grateful.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 08-25-2008, 06:49 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
Quote:
how to work with the first,last, and previous buttons
First thing then is put in some println() statements to see if the listener code is being executed.
When you see that it is, then design what you want to happen when a button is pressed. Then put that code in the program.

For example: what should happen when the first button is pressed? Describe that and think what the program will have to do to do it.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 08-25-2008, 06:52 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 4,545
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
As Norm says, mainly you have to study about ActionListners on buttons.

Here is a simple explanation on that.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 08-25-2008, 09:01 PM
Member
 
Join Date: Jul 2008
Posts: 20
booter4429 is on a distinguished road
Ok I have work that out now. thanks but I have one more, how do you includes a company logo.?? Anything will help...Thanks
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 08-26-2008, 01:48 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Code:
JLabel title = new JLabel("title name"); add(title, "North"); add(centerPanel); // no constraint -> center section repaintGUI(); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(360, 450); setResizable(false); setLocationRelativeTo(null); setVisible(true);
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 08-26-2008, 02:10 AM
Member
 
Join Date: Jul 2008
Posts: 20
booter4429 is on a distinguished road
I'm getting some errors with this.

Exception in thread "main" java.lang.IllegalArgumentException: adding container's parent to itself
at java.awt.Container.addImpl(Container.java:1017)
at java.awt.Container.add(Container.java:935)
at javax.swing.JFrame.addImpl(JFrame.java:545)
at java.awt.Container.add(Container.java:352)
at javaapplication52.InventoryGUI.<init>(Week8.java:3 16)
at javaapplication52.Week8.main(Week8.java:47)

Here is my code....
Code:
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Week8 { public static void main(String[] args) { Movie dvd = null; Inventory inventory = new Inventory(); dvd = new Movie(15035, "The Davinci Code", 18, 19.99f, 2001); System.out.println(dvd); inventory.addMovie(dvd); dvd = new Movie(24478, "Fight Club", 14, 20.99f, 1998); System.out.println(dvd); inventory.addMovie(dvd); dvd = new Movie(32059, "Ladder 49", 1, 21.99f, 1995); System.out.println(dvd); inventory.addMovie(dvd); dvd = new Movie(35989, "National Treasure", 15, 18.99f, 2003); inventory.addMovie(dvd); System.out.println(dvd); dvd = new Movie(14418, "Facing the Giants", 10, 21.99f, 2006); System.out.println(dvd); inventory.addMovie(dvd); dvd = new Movie(13679, "Crimson Tide", 9, 7.99f, 2005); System.out.println(dvd); System.out.println("\nEnd of DVD collection!\n"); inventory.addMovie(dvd); inventory.printInventory(); new InventoryGUI(inventory); } } class DVD { private int itemNo; private String title; private int inStock; private float unitPrice; DVD(int itemNo, String title, int inStock, float unitPrice) { this.itemNo = itemNo; this.title = title; this.inStock = inStock; this.unitPrice = unitPrice; } public int getItemNo() { return itemNo; } public String getTitle() { return title; } public int getInStock() { return inStock; } public float getUnitPrice() { return unitPrice; } public float value() { return inStock * unitPrice; } public String toString() { return String.format("ItemNo=%2d Title=%-22s InStock=%3d Price=$%7.2f Value=$%8.2f", itemNo, title, inStock, unitPrice, value()); } } class Inventory { private final int INVENTORY_SIZE = 30; private DVD[] items; private int numItems; Inventory() { items = new Movie[INVENTORY_SIZE]; numItems = 0; } public int getNumItems() { return numItems; } public DVD getDVD(int n) { return items[n]; } public void addMovie(DVD item) { items[numItems] = item; ++numItems; } public double value() { double sumOfInventory = 0.0; for (int i = 0; i < numItems; i++) sumOfInventory += items[i].value(); return sumOfInventory; } public void printInventory() { System.out.println("\n DVD Inventory\n"); if (numItems <= 0) { System.out.println("Inventory is empty at the moment.\n"); } else { for (int i = 0; i < numItems; i++) System.out.printf("%3d %s\n", i, items[i]); System.out.printf("\nTotal value in inventory is $%,.2f\n\n", value()); } } } class Movie extends DVD { private int movieYear; public Movie(int MovieID, String itemName, int quantityOnHand, float itemPrice, int year) { super(MovieID, itemName, quantityOnHand, itemPrice); this.movieYear = movieYear; } public void setYear(int year) { movieYear = year; } public int getMovieYear() { return movieYear; } public float value() { return super.value() + restockingFee(); } public float restockingFee() { return super.value() * 0.05f; } } class InventoryGUI extends JFrame { private Inventory theInventory; private int index = 0; private final JLabel itemNumberLabel = new JLabel(" Item Number:"); private JTextField itemNumberText; private final JLabel prodnameLabel = new JLabel(" Product Name:"); private JTextField prodnameText; private final JLabel prodpriceLabel = new JLabel(" Price:"); private JTextField prodpriceText; private final JLabel numinstockLabel = new JLabel(" Number in Stock:"); private JTextField numinstockText; private final JLabel valueLabel = new JLabel(" Value:"); private JTextField valueText; private final JLabel restockingFeeLabel = new JLabel(" Restocking Fee:"); private JTextField restockingFeeText; private final JLabel totalValueLabel = new JLabel(" Inventory Total Value:"); private JTextField totalValueText; private JPanel centerPanel; private JPanel buttonPanel; InventoryGUI(Inventory inventory) { super(" Movie Inventory"); final Dimension dim = new Dimension(140, 20); final FlowLayout flo = new FlowLayout(FlowLayout.LEFT); JPanel jp; theInventory = inventory; centerPanel = new JPanel(); centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.Y_AXIS)); buttonPanel = new JPanel(); JButton nextButton = new JButton("Next"); nextButton.addActionListener(new NextButtonHandler()); buttonPanel.add(nextButton); centerPanel.add(buttonPanel); buttonPanel = new JPanel(); JButton previousButton = new JButton("Previous"); previousButton.addActionListener(new PreviousHandler()); buttonPanel.add(previousButton); centerPanel.add(buttonPanel); buttonPanel = new JPanel(); JButton firstButton = new JButton("First"); firstButton.addActionListener(new FirstHandler()); buttonPanel.add(firstButton); centerPanel.add(buttonPanel); buttonPanel = new JPanel(); JButton lastButton = new JButton("Last"); lastButton.addActionListener(new LastHandler()); buttonPanel.add(lastButton); centerPanel.add(buttonPanel); jp = new JPanel(flo); itemNumberLabel.setPreferredSize(dim); jp.add(itemNumberLabel); itemNumberText = new JTextField(10); itemNumberText.setEditable(false); jp.add(itemNumberText); centerPanel.add(jp); jp = new JPanel(flo); prodnameLabel.setPreferredSize(dim); jp.add(prodnameLabel); prodnameText = new JTextField(10); prodnameText.setEditable(false); jp.add(prodnameText); centerPanel.add(jp); jp = new JPanel(flo); prodpriceLabel.setPreferredSize(dim); jp.add(prodpriceLabel); prodpriceText = new JTextField(10); prodpriceText.setEditable(false); jp.add(prodpriceText); centerPanel.add(jp); jp = new JPanel(flo); numinstockLabel.setPreferredSize(dim); jp.add(numinstockLabel); numinstockText = new JTextField(10); numinstockText.setEditable(false); jp.add(numinstockText); centerPanel.add(jp); jp = new JPanel(flo); restockingFeeLabel.setPreferredSize(dim); jp.add(restockingFeeLabel); restockingFeeText = new JTextField(10); restockingFeeText.setEditable(false); jp.add(restockingFeeText); centerPanel.add(jp); jp = new JPanel(flo); valueLabel.setPreferredSize(dim); jp.add(valueLabel); valueText = new JTextField(10); valueText.setEditable(false); jp.add(valueText); centerPanel.add(jp); jp = new JPanel(flo); totalValueLabel.setPreferredSize(dim); jp.add(totalValueLabel); totalValueText = new JTextField(10); totalValueText.setEditable(false); jp.add(totalValueText); centerPanel.add(jp); setContentPane(centerPanel); repaintGUI(); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(360, 450); setResizable(false); setLocationRelativeTo(null); setVisible(true); JLabel title = new JLabel("title name"); add(title, "North"); add(centerPanel); // no constraint -> center section repaintGUI(); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(360, 450); setResizable(false); setLocationRelativeTo(null); setVisible(true); } public void repaintGUI() { Movie temp = (Movie) theInventory.getDVD(index); if (temp != null) { itemNumberText.setText("" + temp.getItemNo()); prodnameText.setText(temp.getTitle()); prodpriceText.setText(String.format("$%.2f", temp.getUnitPrice())); restockingFeeText.setText(String.format("$%.2f", temp.restockingFee())); numinstockText.setText("" + temp.getInStock()); valueText.setText(String.format("$%.2f", temp.value())); } totalValueText.setText(String.format("$%.2f", theInventory.value())); } class NextButtonHandler implements ActionListener { public void actionPerformed(ActionEvent e) { int numItems = theInventory.getNumItems(); index = (++index) % numItems; repaintGUI(); } } class PreviousHandler implements ActionListener { public void actionPerformed(ActionEvent e) { int numItems = theInventory.getNumItems(); index = (index-1) % numItems; repaintGUI(); } } class FirstHandler implements ActionListener { public void actionPerformed(ActionEvent e) { int numItems = theInventory.getNumItems(); index = (index=0) % numItems; repaintGUI(); } } class LastHandler implements ActionListener { public void actionPerformed(ActionEvent e) { int numItems = theInventory.getNumItems(); index = (index=5) % numItems; repaintGUI(); } } }
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 08-26-2008, 02:20 AM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
Quote:
at javaapplication52.InventoryGUI.<init>(Week8.java:3 16)
Look at the source at line 316 in the InventoryGUI constructor.

Its very hard to see where that line is from your posting.
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 08-26-2008, 02:24 AM
Member
 
Join Date: Jul 2008
Posts: 20
booter4429 is on a distinguished road
JLabel title = new JLabel("title name");
add(title, "North");
add(centerPanel);// this is line 316
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 08-26-2008, 04:07 AM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
Quote:
adding container's parent to itself
How is centerPanel related to the container it is being added to?
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 08-26-2008, 05:34 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Looks like you did copy and paste without thinking about what changes you wanted/should make.
IllegalArgumentException: adding container's parent to itself
You've already set "centerPanel" as the contentPane:
Code:
setContentPane(centerPanel);
Then you come along and try to add "centerPanel" to the center section of the contentPane (which is "centerPanel"):
Code:
JLabel title = new JLabel("title name"); add(title, "North"); add(centerPanel); // no constraint -> center section
So change this
Code:
... jp = new JPanel(flo); totalValueLabel.setPreferredSize(dim); jp.add(totalValueLabel); totalValueText = new JTextField(10); totalValueText.setEditable(false); jp.add(totalValueText); centerPanel.add(jp); setContentPane(centerPanel); repaintGUI(); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(360, 450); setResizable(false); setLocationRelativeTo(null); setVisible(true); JLabel title = new JLabel("title name"); add(title, "North"); add(centerPanel); // no constraint -> center section repaintGUI(); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(360, 450); setResizable(false); setLocationRelativeTo(null); setVisible(true); }
to this
Code:
... jp = new JPanel(flo); totalValueLabel.setPreferredSize(dim); jp.add(totalValueLabel); totalValueText = new JTextField(10); totalValueText.setEditable(false); jp.add(totalValueText); centerPanel.add(jp); JLabel title = new JLabel("title name"); add(title, "North"); add(centerPanel); // no constraint -> center section repaintGUI(); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(360, 450); setResizable(false); setLocationRelativeTo(null); setVisible(true); }
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 08-26-2008, 06:01 AM
Member
 
Join Date: Jul 2008
Posts: 20
booter4429 is on a distinguished road
Ok I got it. Thanks

Last thing. How do I get this to work? It needs to go back and keep going back. But if I get the the 1st on I get an error.

Code:
class PreviousHandler implements ActionListener { public void actionPerformed(ActionEvent e) { int numItems = theInventory.getNumItems(); index = (index-1) % numItems; repaintGUI(); } }
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 08-26-2008, 06:47 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Code:
int x = 4; int countUp = 0; int countDown = x; for(int i = 0; i < 6; i++) { countUp = (countUp+1) % x; countDown = countDown -1; if(countDown < 0) countDown = x; System.out.printf("countUp = %d countDown = %d%n", countUp, countDown); }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +3. The time now is 01:25 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org