Need help getting my add, save, search, modify, delete buttons to work I can get them to show up in the GUI but pressing them does nothing. I need the save button to save file to index.dat in folder c:\\data\ folder and create that folder if it doesn't exist

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.NumberFormat;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class InventoryMain extends JFrame implements ActionListener {
	// Index of current element of array
	private int position = 0;
	// create Cameras array
	Cameras[] productArray = null;

	// Various components that are used in the program
	private JLabel brandLabel = new JLabel("Brand:");
	private JTextField brandText = new JTextField("");
	private JLabel departmentLabel = new JLabel("Department: ");
	private JTextField departmentText = new JTextField("");
	private JLabel productNumberLabel = new JLabel("Product Number: ");
	private JTextField productNumberText = new JTextField("");
	private JLabel unitsInStockLabel = new JLabel("Quantity: ");
	private JTextField unitsInStockText = new JTextField("");
	private JLabel unitPriceLabel = new JLabel("Unit Price: ");
	private JTextField unitPriceText = new JTextField("");
	private JLabel invValueLabel = new JLabel("Inventory Value: ");
	private JTextField invValueText = new JTextField("");
	// Digital Camera object related components
	private JLabel imageResolutionLabel = new JLabel("Image Resolution: ");
	private JTextField imageResoultionText = new JTextField("");
	private JLabel restockingFeeLabel = new JLabel("Restocking Fee: ");
	private JTextField restockingFeeText = new JTextField("");
	private JLabel totalInvValueLabel = new JLabel("Total Inventory Value: ");
	private JTextField totalInvValueText = new JTextField("");

	private JButton nextButton, prevButton, firstButton, lastButton, saveButton, searchButton, deleteButton, modifyButton addButton;
	
	// logo graphics
		class Logo extends JPanel {
			public Logo() {
			super();
			setPreferredSize(new Dimension(200,200));
	}
		public void paint(Graphics g) {
			g.setColor(Color.green);
			g.fillRoundRect(60,60,110,90,15,15);
			g.setColor(Color.black);
			g.drawString("Cameras R Us", 90, 105);
	}
}

	public InventoryMain() {
		setProductData();
		// Sort the products
		sortCameras(productArray);

		JPanel buttonPanel = new JPanel();
		nextButton = new JButton("Next");
		nextButton.addActionListener(this);
		
		prevButton = new JButton("Prev");
		prevButton.addActionListener(this);
		
		firstButton = new JButton("First");
		firstButton.addActionListener(this);
		
		lastButton = new JButton("Last");
		lastButton.addActionListener(this);
		
		saveButton = new JButton("Save");
		saveButton.addActionListener(this);
		
		searchButton = new JButton("Search");
		searchButton.addActionListener(this);
		
		deleteButton = new JButton("Delete");
		deleteButton.addActionListener(this);
		
		modifyButton = new JButton("Modify");
		modifyButton.addActionListener(this);
		
		addButton = new JButton("Add");
		addButton.addActionListener(this);

		buttonPanel.add(nextButton);
		buttonPanel.add(prevButton);
		buttonPanel.add(firstButton);
		buttonPanel.add(lastButton);
		buttonPanel.add(save);
		buttonPanel.add(search);
		buttonPanel.add(delete);
		buttonPanel.add(modify);
		buttonPanel.add(add);
		buttonPanel.add(new Logo());
		
		

		getContentPane().setLayout(new BorderLayout());
		getContentPane().add(buttonPanel, BorderLayout.NORTH);

		JPanel dataPanel = new JPanel();
		dataPanel.setLayout(new GridLayout(9, 2));

		dataPanel.add(brandLabel);
		brandText.setEditable(false);
		dataPanel.add(brandText);

		dataPanel.add(departmentLabel);
		departmentText.setEditable(false);
		dataPanel.add(departmentText);

		dataPanel.add(productNumberLabel);
		productNumberText.setEditable(false);
		dataPanel.add(productNumberText);

		dataPanel.add(unitsInStockLabel);
		unitsInStockText.setEditable(false);
		dataPanel.add(unitsInStockText);

		dataPanel.add(unitPriceLabel);
		unitPriceText.setEditable(false);
		dataPanel.add(unitPriceText);

		dataPanel.add(invValueLabel);
		invValueText.setEditable(false);
		dataPanel.add(invValueText);

		dataPanel.add(imageResolutionLabel);
		imageResoultionText.setEditable(false);
		dataPanel.add(imageResoultionText);

		dataPanel.add(restockingFeeLabel);
		restockingFeeText.setEditable(false);
		dataPanel.add(restockingFeeText);

		dataPanel.add(totalInvValueLabel);
		totalInvValueText.setEditable(false);
		dataPanel.add(totalInvValueText);

		displayProduct();
		getContentPane().add(dataPanel, BorderLayout.CENTER);
		
			

		setDefaultCloseOperation(EXIT_ON_CLOSE);
		pack();
		setSize(800, 600);
		setResizable(false);

	}

	private void setProductData() {
		int maxItems = 3;
		productArray = new Cameras[maxItems];
		try {
			String camera;
			String department;
			int number;
			int stock;
			double price;
			String imageResolutionStr;
			double imageResolution;
			for (int k = 0; k < productArray.length; k++) {
				camera = JOptionPane
						.showInputDialog("Enter A Brand For Camera "
								+ String.valueOf(k + 1) + " of "
								+ String.valueOf(maxItems));
				department = JOptionPane
						.showInputDialog("Enter A Department For Camera "
								+ String.valueOf(k + 1) + " of "
								+ String.valueOf(maxItems));
				number = Integer.parseInt(JOptionPane
						.showInputDialog("Enter Product Number For Camera "
								+ String.valueOf(k + 1) + " of "
								+ String.valueOf(maxItems)));
				stock = Integer.parseInt(JOptionPane
						.showInputDialog("Enter Quantity For Camera "
								+ String.valueOf(k + 1) + " of "
								+ String.valueOf(maxItems)));
				price = Double.parseDouble(JOptionPane
						.showInputDialog("Enter A Price For Camera "
								+ String.valueOf(k + 1) + " of "
								+ String.valueOf(maxItems)));
				imageResolutionStr = JOptionPane
						.showInputDialog("Enter Image Resolution "
								+ String.valueOf(k + 1) + " of "
								+ String.valueOf(maxItems)
								+ " (Leave blank if not a digital camera)");
				// If image resolution left blank assume its Camera object
				// otherwise its digital camera
				if (null == imageResolutionStr
						|| imageResolutionStr.trim().equals("")) {
					productArray[k] = new Cameras(camera, department, number,
							stock, price);
				} else {
					imageResolution = Double.parseDouble(imageResolutionStr);
					productArray[k] = new DigitalCameras(camera, department,
							number, stock, price, imageResolution);
				}
			}
		} catch (Exception ec) {
			System.out.println(ec.getMessage());
			System.exit(-1);
		}

	}

	private void sortCameras(Cameras Cameras[]) {
		int in, out, NumOfEle = Cameras.length;
		for (out = 1; out < NumOfEle; out++) {
			Cameras temp = Cameras[out];
			in = out;
			while (in > 0
					&& Cameras[in - 1].getproductName().compareTo(
							temp.getproductName()) > 0) {
				Cameras[in] = Cameras[in - 1];
				--in;
			}
			Cameras[in] = temp;
		}
	}

	private double calculateEntireInventory() {
		Cameras obj = null;
		double totalInventory = 0;
		for (int i = 0; i < productArray.length; i++) {
			obj = productArray[i];
			totalInventory += obj.getValue();
		}
		return totalInventory;
	}

	// button pushes...
	public void actionPerformed(ActionEvent event) {
		if (event.getSource () == nextButton) {
			if (position < productArray.length - 1)
				position++;
			else
				position = 0;
		} else if (event.getSource () == firstButton) {
			position = 0;
		} else if (event.getSource () == lastButton) {
			position = productArray.length - 1;
		} else if (event.getSource () == prevButton) {
			if (position > 0)
				position--;
			else
				position = productArray.length - 1;
		} 
		
		displayProduct ();
 
	}

	public void displayProduct() {
		NumberFormat formatter = NumberFormat.getCurrencyInstance();
		Cameras product = productArray[position];
		double totalInvValue = calculateEntireInventory();
		// Start of getting the values
		brandText.setText(product.getproductName());
		departmentText.setText(product.getproductDepartment());
		productNumberText.setText(product.getproductNumber() + "");
		unitsInStockText.setText(product.getunitsNumber() + "");
		unitPriceText.setText(formatter.format(product.getunitPrice()));
		invValueText.setText(formatter.format(product.getValue()));
		if (product instanceof DigitalCameras) {
			imageResolutionLabel.setVisible(true);
			imageResoultionText.setVisible(true);
			restockingFeeLabel.setVisible(true);
			restockingFeeText.setVisible(true);
			imageResoultionText.setText(((DigitalCameras) product)
					.getImageResolution() + "");
			restockingFeeText.setText(formatter
					.format(((DigitalCameras) product).getRestockingfee()));
		} else {
			imageResolutionLabel.setVisible(false);
			imageResoultionText.setVisible(false);
			restockingFeeLabel.setVisible(false);
			restockingFeeText.setVisible(false);
			imageResoultionText.setText("");
			restockingFeeText.setText("");
		}
		totalInvValueText.setText(formatter.format(totalInvValue));
	}

	// main method
	public static void main(String[] args) {
		InventoryMain gui = new InventoryMain();
		gui.setVisible(true);

	}

}
public class DigitalCameras extends Cameras {
	double ImageResolution;
	double rate = 0.05;
	private double restockingfee;

	public DigitalCameras(String camera, String department, int number,
			int stock, double price, double ImageResolution) {
		super(camera, department, number, stock, price);
		this.ImageResolution = ImageResolution;
	}

	public double getImageResolution() {
		return ImageResolution;
	}

	public void setImageResolution(double ImageResolution) {
		this.ImageResolution = ImageResolution;
	}

	public double getRestockingfee() {
		return super.getValue() * rate;
	}

	// calculates inventory value after adding restocking fee
	public double getValue() {
		double value = super.getValue();
		// Add 5% restocking fee
		value = value + getRestockingfee();
		return value;
	}
}
public class Cameras {
	private String productName;
	private String productDepartment;
	private int productNumber;
	private int unitsNumber;
	private double unitPrice;

	public Cameras() {
	}

	public Cameras(String camera, String department, int number, int stock,
			double price) {
		productName = camera;
		productDepartment = department;
		productNumber = number;
		unitsNumber = stock;
		unitPrice = price;
	}

	public void setproductName(String camera) {
		setproductName(camera);
	}

	public String getproductName() {
		return productName;
	}

	public void setproductDepartment(String department) {
		setproductDepartment(department);
	}

	public String getproductDepartment() {
		return productDepartment;
	}

	public void setproductNumber(int number) {
		productNumber = number;
	}

	public int getproductNumber() {
		return productNumber;
	}

	public void setunitsNumber(int stock) {
		unitsNumber = (stock < 0) ? 0 : stock;
	}

	public double getunitsNumber() {
		return unitsNumber;
	}

	public void setunitPrice(double price) {
		unitPrice = (price < 0.0) ? 0.0 : price;
	}

	public double getunitPrice() {
		return unitPrice;
	}

	public double getValue() {
		return getunitPrice() * unitsNumber;
	}

	public void setProductName(String productName) {
		this.productName = productName;
	}
}

You can start by adding those buttons to the elseifs in you actionPerformed method - have them just call methods add(), save() etc, then write those methods, one at a time, testing each small step with lots of print statements as you go.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.