import java.text.*;
import javax.swing.*;
import java.awt.event.*;
public class PlainWrapParts extends JFrame implements ItemListener, ActionListener
{
//create the main panel, radio buttons, and text fields for the panel
JPanel mainPanel = new JPanel();
String[][] partNumberString =
{{"PR214","PR223","PR224","PR246","PR247","PR248","PR324", "PR326","PR444"},
{"MR43T","R43","R43N","R46N","R46TS","R46TX","S46","SR46E","47L"},
{"RBL8","RJ6","RN4","RN8","RBL17Y","RBL12-6","J11","XEJ8","H12"},
{"14K22","14K24","14K30","14K32","14K33","14K35","14K38","14K40","14K44"}};
String [] brandString = {"Plain Wrap", "Brand A", "Brand C", "Brand X"};
int counterInteger = 0;
int plainWrapInteger [][] = new int [14][4];
String plainWrapString, brandAString, brandCString, brandXString, nameString;
JComboBox plainWrapComboBox = new JComboBox(partNumberString[0]);
JTextField brandATextField = new JTextField(5);
JTextField brandCTextField = new JTextField(5);
JTextField brandXTextField = new JTextField(5);
JButton clearButton = new JButton("Clear Items");
JButton summaryButton = new JButton("Summary of Sales");
JTextField plainWrapAddTextField = new JTextField(5);
JTextField brandAAddTextField = new JTextField(5);
JTextField brandCAddTextField = new JTextField(5);
JTextField brandXAddTextField = new JTextField(5);
JButton addButton = new JButton("Add an item");
JTextArea outputTextArea = new JTextArea(20,30);
JScrollPane mainScrollPane = new JScrollPane(outputTextArea);
public static void main(String[] args)
{
// Create an object of the class
PlainWrapParts myPartsStore = new PlainWrapParts();
myPartsStore.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public PlainWrapParts()
{
//setting title, size of the designFrame
designFrame();
add(mainPanel);
setTitle("Plain Wrap Auto");
setSize(500,600);
setVisible(true);
}
public void designFrame()
{
//add items to the panels
mainPanel.add(new JLabel("Plain Wrap"));
mainPanel.add(plainWrapComboBox);
mainPanel.add(new JLabel("Brand A"));
mainPanel.add(brandATextField);
mainPanel.add(new JLabel("Brand C"));
mainPanel.add(brandCTextField);
mainPanel.add(new JLabel("Brand X"));
mainPanel.add(brandXTextField);
mainPanel.add(new JLabel("Plain Wrap"));
mainPanel.add(plainWrapAddTextField);
mainPanel.add(new JLabel("Brand A"));
mainPanel.add(brandAAddTextField);
mainPanel.add(new JLabel("Brand C"));
mainPanel.add(brandCAddTextField);
mainPanel.add(new JLabel("Brand X"));
mainPanel.add(brandXAddTextField);
mainPanel.add(addButton);
mainPanel.add(clearButton);
mainPanel.add(mainScrollPane);
brandXTextField.addActionListener(this);
brandXAddTextField.addActionListener(this);
plainWrapComboBox.addItemListener(this);
clearButton.addActionListener(this);
addButton.addActionListener(this);
}
//Different actions performed when the buttons are pushed
public void itemStateChanged(ItemEvent evt)
{
String ss = (String) plainWrapComboBox.getSelectedItem();
}
public void actionPerformed(ActionEvent evt)
{
Object sourceObject = evt.getSource();
//if purchase button pushed everything sent to total class for calculation
if(sourceObject == addButton)
{
getInput();
add();
}
//if clear button pushed everything thing is cleared
else if(sourceObject == clearButton)
{
clear();
}
}
public void getInput()
{
//validate entry
try
{
if((!(plainWrapAddTextField.getText()).equals("")))
{
nameString = plainWrapAddTextField.getText();
if((!(brandAAddTextField.getText()).equals("")))
{
nameString = brandAAddTextField.getText();
if((!(brandCAddTextField.getText()).equals("")))
{
nameString = brandCAddTextField.getText();
if((!(brandXAddTextField.getText()).equals("")))
{
nameString = brandXAddTextField.getText();
try
{
add();
}
catch (Exception e)
{
JOptionPane.showMessageDialog(null, "invalid");
brandATextField.selectAll();
brandATextField.requestFocus();
}
}
else
{ JOptionPane.showMessageDialog(null, "Enter Brand X");
brandXAddTextField.selectAll();
brandXAddTextField.requestFocus();
}}
else
{ JOptionPane.showMessageDialog(null, "Enter Brand C");
brandCAddTextField.selectAll();
brandCAddTextField.requestFocus();
}}
else
{
JOptionPane.showMessageDialog(null, "Enter Brand A");
brandAAddTextField.selectAll();
brandAAddTextField.requestFocus();
}
}
else
{
JOptionPane.showMessageDialog(null, "Enter Plain Wrap");
plainWrapAddTextField.selectAll();
plainWrapAddTextField.requestFocus();
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "invalid");
brandATextField.selectAll();
brandATextField.requestFocus();
}
}
public void add()
{
boolean done = false;
int arrayCount = plainWrapComboBox.getItemCount() - 1;
for (int i = 0; i <= arrayCount; i++)
if(plainWrapString.equals(partNumberString[0][i]))
{
done = true;
break;
}
if(done)
{
JOptionPane.showMessageDialog(null, "Duplicate part number!");
}
else if(plainWrapString.length() != 0 && brandAString.length() != 0
&& brandCString.length() != 0 && brandXString.length() != 0)
{
plainWrapAddTextField.setText(plainWrapString);
brandAAddTextField.setText(brandAString);
brandCAddTextField.setText(brandCString);
brandXAddTextField.setText(brandXString);
}
}
public boolean checkInput(String userInputString)
{
boolean foundBoolean = false;
int indexInteger = 0;
String inputString = new String();
while(!foundBoolean && indexInteger < plainWrapComboBox.getItemCount())
{
inputString = (String) plainWrapComboBox.getItemAt(indexInteger);
if(userInputString.equalsIgnoreCase(inputString))
{
foundBoolean = true;
}
else
{
indexInteger++;
}
}
return foundBoolean;
}
public void displayPlainWrapFound(boolean partsBoolean, String inputString)
{
if(partsBoolean)
{
JOptionPane.showMessageDialog(null,"This part is already in the list");
plainWrapAddTextField.selectAll();
plainWrapAddTextField.requestFocus();
}
else
{
plainWrapComboBox.addItem(inputString);
JOptionPane.showMessageDialog(null,"This part is added to the list");
plainWrapAddTextField.setText("");
}
}
public void clear()
{
plainWrapAddTextField.setText("");
brandAAddTextField.setText("");
brandCAddTextField.setText("");
brandXAddTextField.setText("");
outputTextArea.setText("");
plainWrapComboBox.requestFocus();
}
}