I am sure anyone here for more than an hour is familiar with the project I have been working on.
I am currently researching listeners to try and get my fields to execute the proper calculations when moving from one to the next. Right now, even though I have those functions defined in classes, they are not being executed. Hopefully I will figure that out soon.
I also want to be able to go forwards and backwards through this list as it is created.
Lack of forsite left me without a counter in this application until now.
I am already in above my head with this being my first GUI and my first JLIST, but can someone look at this counter mechanism I am trying to put in and give me an idea of what is wrong with it?
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.text.*;
import java.lang.*;
public class Inventory2 extends JFrame
{
private JLabel cdNameLabel; // name label
private JLabel artistLabel; // item number label
private JLabel nstockLabel; // units in stock label
private JLabel priceLabel; // price each label
private JLabel itemLabel; // item number label
private JLabel valueLabel; // value of that item label
private JLabel rstkLabel; // cost to restock label
private JLabel totalLabel; // total value of inventory label
private JTextField cdNameField; // name display
private JTextField artistField; // artist display
private JFormattedTextField nstockField; // units in stock display
private JFormattedTextField priceField; // price each display
private JTextField itemField; // item number display
private JFormattedTextField valueField; // value of that item display
private JFormattedTextField rstkField; // cost to restock display
private JFormattedTextField totalField; // value of all inventory combine
private NumberFormat nstockFormat; // format field and parse numbers
private NumberFormat priceFormat; // format field and parse numbers
private NumberFormat valueFormat; // format field and parse numbers
private NumberFormat rstkFormat; // format field and parse numbers
private NumberFormat totalFormat;
private JButton btnAdd; // first button
private JButton btnPrev; // previous button
private JButton btnNext; // next button
private JButton btnDel; // last button
private JPanel buttonJPanel; // JPanle to hold buttons
private JPanel fieldJPanel; // JPanel to hold labels and displays
private JPanel fontJPanel; // JPanel to display logo
private int currCD; // current product display to use for button action
private int i; // iterator
private double total = 0; // variable for total inventory
private JList Inventorylist; // JList to take place of old array
private DefaultListModel listModel;
private JScrollPane jScrollPanel;
public Inventory2() // create class and method to perform GUI build
{
initComponents();
}
private void initComponents()
{
// create label names
cdNameLabel = new JLabel("CD Name:");
artistLabel = new JLabel("Artist:");
nstockLabel = new JLabel("In Stock:");
priceLabel = new JLabel("Each Item Cost:$");
itemLabel = new JLabel("Item Number:");
valueLabel = new JLabel("Value of Item Inventory:$");
rstkLabel = new JLabel("Cost to Re-Stock Item:$");
totalLabel = new JLabel("Total Value of Inventory:$");
// initial fields
cdNameField = new JTextField(25);
cdNameField.setEditable(true);
artistField = new JTextField(15);
artistField.setEditable(true);
nstockField = new JFormattedTextField(nstockFormat);
nstockField.setEditable(true);
nstockField.setColumns(10);
priceField = new JFormattedTextField(priceFormat);
priceField.setEditable(true);
priceField.setColumns(10);
itemField = new JTextField(5);
itemField.setEditable(true);
valueField = new JFormattedTextField(valueFormat);
valueField.setEditable(true);
valueField.setColumns(10);
rstkField = new JFormattedTextField(rstkFormat);
rstkField.setEditable(true);
rstkField.setColumns(5);
totalField = new JFormattedTextField(totalFormat);
totalField.setColumns (10);
totalField.setEditable(true);
// JList
jScrollPanel = new JScrollPane();
Inventorylist = new JList();
[B]//Instantiate object for JList
for (currCD = 0; currCD <99; currCD++)
// add values to textFields
cdNameField.setText(currCD.getcdName());
artistField.setText(currCD.getArtist());
nstockField.setValue(new Float(currCD.getValue()));
priceField.setValue(new Float("$"+currCD.getPrice()));
itemField.setText(currCD.getItem());
valueField.setValue(new Float("$" + currCD.getValue()));
rstkField.setValue(new Float(currCD.getRestock()));
totalField.setValue(new Float("$" + currCD.getValue()));[/B]
// buttons
btnAdd = new JButton();
btnNext = new JButton();
btnPrev = new JButton();
btnDel = new JButton();
getContentPane().setLayout(new FlowLayout());
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
// place textFields and labels
//artist
artistLabel.setText("Artist");
getContentPane().add(artistLabel);
artistField.setMinimumSize(new Dimension(75,19));
artistField.setPreferredSize(new Dimension(75,19));
getContentPane().add(artistField);
// cd name
cdNameLabel.setText("CD Name");
getContentPane().add(cdNameLabel);
cdNameField.setMinimumSize(new Dimension(75,19));
cdNameField.setPreferredSize(new Dimension(75,19));
getContentPane().add(cdNameField);
// copies in stock
nstockLabel.setText("Copies In Stock");
getContentPane().add(nstockLabel);
nstockField.setMinimumSize(new Dimension(75,19));
nstockField.setPreferredSize(new Dimension(75,19));
getContentPane().add(nstockField);
//price of cd
priceLabel.setText("Price");
getContentPane().add(priceLabel);
priceField.setMinimumSize(new Dimension(75,19));
priceField.setPreferredSize(new Dimension(75,19));
getContentPane().add(priceField);
//item number of cd
itemLabel.setText("Item Number");
getContentPane().add(itemLabel);
itemField.setMinimumSize(new Dimension(75,19));
itemField.setPreferredSize(new Dimension(75,19));
getContentPane().add(itemField);;
// value of individual cd in stock
valueLabel.setText("Value");
getContentPane().add(valueLabel);
valueField.setMinimumSize(new Dimension(75,19));
valueField.setPreferredSize(new Dimension(75,19));
getContentPane().add(valueField);
// restocking fee
rstkLabel.setText("Restock Fee");
getContentPane().add(rstkLabel);
rstkField.setMinimumSize(new Dimension(75,19));
rstkField.setPreferredSize(new Dimension(75,19));
getContentPane().add(rstkField);
// total value of inventory
totalLabel.setText("Total Inventory Value");
getContentPane().add(totalLabel);
totalField.setMinimumSize(new Dimension(75,19));
totalField.setPreferredSize(new Dimension(75,19));
getContentPane().add(totalField);
// add buttons
//ADD
btnAdd.setText("Add");
btnAdd.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
btnAddActionPerformed(evt);
}
});
getContentPane().add(btnAdd);
// PREVIOUS
btnPrev.setText("Previous");
btnPrev.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
btnAddActionPerformed(evt);
}
});
getContentPane().add(btnPrev);
// NEXT
btnNext.setText("Next"); btnNext.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
btnAddActionPerformed(evt);
}
});
getContentPane().add(btnNext);
// DELETE
btnDel.setText("Delete");
btnDel.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
btnAddActionPerformed(evt);
}
});
getContentPane().add(btnDel);
// new Jlist model
listModel = new DefaultListModel();
Inventorylist.setModel(listModel);
jScrollPanel.setViewportView(Inventorylist);
getContentPane().add(jScrollPanel);
pack();
}// close
private void btnAddActionPerformed(ActionEvent evt)
{
// Create cd to add
CdwArtist cd = new CdwArtist(artistField.getText());
cd.setName(cdNameField.getText());
cd.setItemno(Integer.parseInt(itemField.getText()));
cd.setNstock(Integer.parseInt(nstockField.getText()));
cd.setPrice(Float.parseFloat(priceField.getText()));
cd.setValue(Float.parseFloat(valueField.getText()));
cd.setTotal(Float.parseFloat(totalField.getText()));
cd.setRestock(Float.parseFloat(rstkField.getText()));
// Add cd to list
listModel.addElement(cd);
// Clear the text fields after add
artistField.setText(null);
cdNameField.setText(null);
itemField.setText(null);
nstockField.setText(null);
priceField.setText(null);
valueField.setText(null);
rstkField.setText(null);
totalField.setText(null);
}// end ADD
// run it
public static void main(String args[])
{
java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
new Inventory2().setVisible(true);
}
});
}
} // close class
currCD is going to be the number of the cd I am working on. Right now, in the bolded area, I am getting "Int cannot be rerefernced" pointing at the . in front of each "get". I do not now what this means and do not know what to do in order to eliminate the error and move forward.