This is my code:
import java.awt.*; import java.awt.event.*; import java.text.DecimalFormat; import javax.swing.*; public class Stapler extends Ink{ String[] name = {"Stapler", "Pens", "Paper","Staples"}; int[] numberItem = {123456, 654321, 987654,963147}; int[] inStock = {123, 321, 987,721}; double[] price = {4.75, 2.50, 1.37,1.36}; double[] tut = {inStock[0] * price[0] * restockFee + inStock[0] * price[0], inStock[1] * price[1] * restockFee + inStock[1] * price[1], inStock[2] * price[2] * restockFee + inStock[2] * price[2],inStock[3] * price[3] * restockFee + inStock[3] * price[3] }; double every = (price[2]*inStock[2]+price[1]*inStock[1]+price[0]*inStock[0] * restockFee + price[2]*inStock[2]+price[1]*inStock[1]+price[0]*inStock[0] * stockfee + inStock[3] * price[3] * restockFee + inStock[3] * price[3] ); private Stapler bob; public String getnaM(){ return(sub); } public int getiN(){ return(numb); } public double geteach(){ return(pricE); } public int getstocks(){ return(iNs); } public double getaL(){ return(vaL); } public double getFee(){ return(stockfee);} public String[] getnames(){ return(name); } public int[] getItemnumber(){ return(numberItem); } public double[] getprices(){ return(price); } public int[] getunits(){ return(inStock); } public double[] getVolume() { return (tut); } public double getEverything(){ return(every);} Stapler(){ } /** * @param args the command line arguments */ public static void main(String[] args) { final Stapler stapler; stapler = new Stapler(); final DecimalFormat f = new DecimalFormat("$0.00"); final int[] be = {0,1,2,3}; JPanel p = new JPanel(); JFrame myFrame = new JFrame("Inventory Program"); myFrame.setSize(295, 175);// width, height myFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); myFrame.setVisible(true); final JTextArea out = new JTextArea(); out.setEditable(false); JButton btnFirst = new JButton("First"); btnFirst.setActionCommand("First"); JButton btnLast = new JButton("last"); btnLast.setActionCommand("last"); JButton btnNext = new JButton("Next"); btnNext.setActionCommand("Next"); JButton btnPrevious = new JButton("Prev"); btnPrevious.setActionCommand("Prev"); btnFirst.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { out.setText(""); out.append("Product name: "+stapler.getnames()[0]); out.append("\nProduct number: "+stapler.getItemnumber()[0]); out.append("\nPrice of one product: "+f.format(+stapler.getprices()[0])); out.append("\nNumber of units in stock: "+stapler.getunits()[0]); out.append("\nTotal value of product in stock: "+f.format(+stapler.getVolume()[0])); } }); btnPrevious.addActionListener(new ActionListener() { private int b; @Override public void actionPerformed(ActionEvent e) { if(b>0) { --b; out.setText(""); out.append("Product name: "+stapler.getnames()[b]); out.append("\nProduct number: "+stapler.getItemnumber()[b]); out.append("\nPrice of one product: "+f.format(+stapler.getprices()[b])); out.append("\nNumber of units in stock: "+stapler.getunits()[b]); out.append("\nTotal value of product in stock: "+f.format(+stapler.getVolume()[b])); }else{out.setText(""); out.append("Product name: "+stapler.getnames()[2]); out.append("\nProduct number: "+stapler.getItemnumber()[2]); out.append("\nPrice of one product: "+f.format(+stapler.getprices()[2])); out.append("\nNumber of units in stock: "+stapler.getunits()[2]); out.append("\nTotal value of product in stock: "+f.format(+stapler.getVolume()[2]));} } }); btnNext.addActionListener(new ActionListener() { private int i; @Override public void actionPerformed(ActionEvent e) { if(i < be.length -1) { i++; out.setText(""); out.append("Product name: "+stapler.getnames()[i]); out.append("\nProduct number: "+stapler.getItemnumber()[i]); out.append("\nPrice of one product: "+f.format(+stapler.getprices()[i])); out.append("\nNumber of units in stock: "+stapler.getunits()[i]); out.append("\nTotal value of product in stock: "+f.format(+stapler.getVolume()[i])); }else{ out.setText(""); out.append("Product name: "+stapler.getnames()[0]); out.append("\nProduct number: "+stapler.getItemnumber()[0]); out.append("\nPrice of one product: "+f.format(+stapler.getprices()[0])); out.append("\nNumber of units in stock: "+stapler.getunits()[0]); out.append("\nTotal value of product in stock: "+f.format(+stapler.getVolume()[0])); } } }); btnLast.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { out.setText(""); out.append("Product name: "+stapler.getnames()[2]); out.append("\nProduct number: "+stapler.getItemnumber()[2]); out.append("\nPrice of one product: "+f.format(+stapler.getprices()[2])); out.append("\nNumber of units in stock: "+stapler.getunits()[2]); out.append("\nTotal value of product in stock: "+f.format(+stapler.getVolume()[2])); } }); p.add(out); myFrame.add(p); p.add(btnFirst); p.add(btnPrevious); p.add(btnLast); p.add(btnNext); btnFirst.setLayout(new BorderLayout()); p.add(btnFirst, BorderLayout.SOUTH); btnPrevious.setLayout(new BorderLayout()); p.add(btnPrevious, BorderLayout.SOUTH); btnNext.setLayout(new BorderLayout()); p.add(btnNext, BorderLayout.SOUTH); btnLast.setLayout(new BorderLayout()); p.add(btnLast, BorderLayout.SOUTH); } }
My problem is i cannot get my next button to continure to loop around. After the else statment is true it is stuck on the else until the program is restarted. Also i need help with my previous button logic. The previous button goes straight to the last array of information. How do i get my next button to work compltly and how do i fix my previous button to work. Thank you.
ink:
public class Ink { String sub = ("Staples"); int numb = (963147); double pricE = (1.36); int iNs = (721); double restockFee = (.05); double vaL = (iNs * pricE); double stockfee = (vaL * restockFee + vaL); }