I do not even know how to correctly ask this question.
I have an item field in the code I am about to post. Simple intger meant to be an item number for a cd. The user enters this number.
Over the last week I have played with Add buttons, Del buttons, Modify and everything else and it brought to light a problem I want to address today.
I have always just used 1 for the first item, 2 for the second and so on ...
well after I am done will all the button nonsence the item numbers are all over the place.
How could I make it so that the item number field would be restructured and stay in ascending order no matter what was added or deleted?
If I delete cd number 4, then make 5 number 4, 6 number 5 and so on ... the next cd added should just take the next highest number ...
Does that make sense?
Here is my primary class. I can post the others if needed. - import java.util.*;
-
import java.awt.*;
-
import java.awt.event.*;
-
import javax.swing.*;
-
import javax.swing.event.*;
-
import java.text.*;
-
import java.lang.*;
-
import javax.swing.JFrame;
-
-
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 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 NumberFormat nstockFormat; // format field and parse numbers
-
private NumberFormat priceFormat; // format field and parse numbers
-
private JButton btnAdd; // first button
-
private JButton btnPrev; // previous button
-
private JButton btnNext; // next button
-
private JButton btnDel; // last button
-
private JButton btnFirst; // first button
-
private JButton btnLast; // last button
-
private JButton btnModify; // modify button
-
private JButton btnSave; // save button
-
private JButton btnSearch; // search 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;
-
private double total = 0; // variable for total inventory
-
private JList Inventorylist; // JList to take place of old array
-
private DefaultListModel listModel;
-
private JScrollPane jScrollPanel;
-
private float Invtotal = .00f;
-
-
DecimalFormat formatter = new DecimalFormat("0.00");
-
-
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:");
-
-
-
// 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(5);
-
priceField = new JFormattedTextField(priceFormat);
-
priceField.setEditable(true);
-
priceField.setColumns(5);
-
itemField = new JTextField(4);
-
itemField.setEditable(true);
-
-
// JList
-
jScrollPanel = new JScrollPane();
-
Inventorylist = new JList();
-
currCD = 0;
-
-
-
// buttons
-
btnAdd = new JButton();
-
btnNext = new JButton();
-
btnPrev = new JButton();
-
btnDel = new JButton();
-
btnLast = new JButton();
-
btnFirst = new JButton();
-
btnModify = new JButton();
-
btnSave = new JButton();
-
btnSearch = new JButton();
-
-
getContentPane().setLayout(new FlowLayout());
-
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
-
-
// add shapesJPanel to frame
-
ShapesJPanel logo = new ShapesJPanel();
-
logo.setPreferredSize(new Dimension(200,200));
-
getContentPane().add( logo );
-
-
// place textFields and labels
-
-
//artist
-
artistLabel.setText("Artist");
-
getContentPane().add(artistLabel);
-
-
artistField.setMinimumSize(new Dimension(70,20));
-
artistField.setPreferredSize(new Dimension(70,20));
-
getContentPane().add(artistField);
-
-
// cd name
-
cdNameLabel.setText("CD Name");
-
getContentPane().add(cdNameLabel);
-
-
cdNameField.setMinimumSize(new Dimension(70,20));
-
cdNameField.setPreferredSize(new Dimension(70,20));
-
getContentPane().add(cdNameField);
-
-
// copies in stock
-
nstockLabel.setText("Copies In Stock");
-
getContentPane().add(nstockLabel);
-
-
nstockField.setMinimumSize(new Dimension(5,20));
-
nstockField.setPreferredSize(new Dimension(5,20));
-
getContentPane().add(nstockField);
-
-
//price of cd
-
priceLabel.setText("Price: $");
-
getContentPane().add(priceLabel);
-
-
priceField.setMinimumSize(new Dimension(20,20));
-
priceField.setPreferredSize(new Dimension(20,20));
-
getContentPane().add(priceField);
-
-
//item number of cd
-
itemLabel.setText("Item Number");
-
getContentPane().add(itemLabel);
-
-
itemField.setMinimumSize(new Dimension(5,20));
-
itemField.setPreferredSize(new Dimension(5,20));
-
getContentPane().add(itemField);
-
-
-
-
// add listeners
-
-
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)
-
{
-
btnPrevActionPerformed(evt);
-
}
-
});
-
getContentPane().add(btnPrev);
-
-
// NEXT
-
btnNext.setText("Next");
-
btnNext.addActionListener(new ActionListener()
-
{
-
public void actionPerformed(ActionEvent evt)
-
{
-
btnNextActionPerformed(evt);
-
}
-
});
-
getContentPane().add(btnNext);
-
-
// SEARCH
-
btnSearch.setText("Search");
-
btnSearch.addActionListener(new ActionListener()
-
{
-
public void actionPerformed(ActionEvent evt)
-
{
-
btnAddActionPerformed(evt);
-
}
-
});
-
getContentPane().add(btnSearch);
-
-
// FIRST
-
btnFirst.setText("First");
-
btnFirst.addActionListener(new ActionListener()
-
{
-
public void actionPerformed(ActionEvent evt)
-
{
-
btnFirstActionPerformed(evt);
-
}
-
});
-
getContentPane().add(btnFirst);
-
-
// LAST
-
btnLast.setText("Last");
-
btnLast.addActionListener(new ActionListener()
-
{
-
public void actionPerformed(ActionEvent evt)
-
{
-
btnLastActionPerformed(evt);
-
}
-
});
-
getContentPane().add(btnLast);
-
-
// MODIFY
-
btnModify.setText("Modify");
-
btnModify.addActionListener(new ActionListener()
-
{
-
public void actionPerformed(ActionEvent evt)
-
{
-
btnModifyActionPerformed(evt);
-
}
-
});
-
getContentPane().add(btnModify);
-
-
// SAVE
-
btnSave.setText("Save");
-
btnSave.addActionListener(new ActionListener()
-
{
-
public void actionPerformed(ActionEvent evt)
-
{
-
btnAddActionPerformed(evt);
-
}
-
});
-
getContentPane().add(btnSave);
-
-
// DELETE
-
btnDel.setText("Delete");
-
btnDel.addActionListener(new ActionListener()
-
{
-
public void actionPerformed(ActionEvent evt)
-
{
-
btnDeleteActionPerformed(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 newCD = new CdwArtist();
-
newCD.setArtist(artistField.getText());
-
newCD.setName(cdNameField.getText());
-
newCD.setItemno(Integer.parseInt(itemField.getText()));
-
newCD.setNstock(Integer.parseInt(nstockField.getText()));
-
newCD.setPrice(Float.parseFloat(priceField.getText()));
-
-
// Add cd to list
-
listModel.addElement(newCD);
-
currCD = listModel.size()-1; // sets currCD to added index
-
-
-
// Clear the text fields after add
-
artistField.setText(null);
-
cdNameField.setText(null);
-
itemField.setText(null);
-
nstockField.setText(null);
-
priceField.setText(null);
-
-
}// end ADD
-
-
private void btnPrevActionPerformed(ActionEvent evt)
-
{
-
// Grab Previous cd
-
if (--currCD<0) currCD = listModel.size()-1;
-
CdwArtist newCD = (CdwArtist) listModel.get( currCD );
-
-
-
artistField.setText(newCD.getArtist());
-
cdNameField.setText(newCD.getName());
-
itemField.setText(String.valueOf(newCD.getItemno()));
-
nstockField.setText(String.valueOf(newCD.getNstock()));
-
priceField.setText(formatter.format(newCD.getPrice()));
-
-
-
}// end PREV
-
-
private void btnNextActionPerformed(ActionEvent evt)
-
{
-
// Grab Next cd
-
if (++currCD >= listModel.size()) currCD= 0;
-
CdwArtist newCD = (CdwArtist) listModel.get( currCD );
-
-
-
artistField.setText(newCD.getArtist());
-
cdNameField.setText(newCD.getName());
-
itemField.setText(String.valueOf(newCD.getItemno()));
-
nstockField.setText(String.valueOf(newCD.getNstock()));
-
priceField.setText(formatter.format(newCD.getPrice()));
-
-
-
}// end NEXT
-
-
-
private void btnFirstActionPerformed(ActionEvent evt)
-
{
-
// Grab First cd
-
CdwArtist newCD = (CdwArtist) listModel.get(0);
-
currCD = 0;
-
-
artistField.setText(newCD.getArtist());
-
cdNameField.setText(newCD.getName());
-
itemField.setText(String.valueOf(newCD.getItemno()));
-
nstockField.setText(String.valueOf(newCD.getNstock()));
-
priceField.setText(formatter.format(newCD.getPrice()));
-
-
-
}// end FIRST
-
-
-
private void btnLastActionPerformed(ActionEvent evt)
-
{
-
// Grab Last cd
-
CdwArtist newCD = (CdwArtist) listModel.lastElement();
-
currCD = listModel.size()-1;
-
-
-
artistField.setText(newCD.getArtist());
-
cdNameField.setText(newCD.getName());
-
itemField.setText(String.valueOf(newCD.getItemno()));
-
nstockField.setText(String.valueOf(newCD.getNstock()));
-
priceField.setText(formatter.format(newCD.getPrice()));
-
-
-
}// end LAST
-
-
private void btnDeleteActionPerformed(ActionEvent evt)
-
{
-
// Delete cd
-
listModel.remove(currCD);
-
-
-
// Clear the text fields after delete
-
artistField.setText(null);
-
cdNameField.setText(null);
-
itemField.setText(null);
-
nstockField.setText(null);
-
priceField.setText(null);
-
-
-
}// end DELETE
-
-
private void btnModifyActionPerformed(ActionEvent evt)
-
{
-
// Modify cd
-
listModel.remove(currCD);
-
-
// Create cd to add
-
CdwArtist newCD = new CdwArtist();
-
newCD.setArtist(artistField.getText());
-
newCD.setName(cdNameField.getText());
-
newCD.setItemno(Integer.parseInt(itemField.getText()));
-
newCD.setNstock(Integer.parseInt(nstockField.getText()));
-
newCD.setPrice(Float.parseFloat(priceField.getText()));
-
-
// Add cd to list
-
listModel.addElement(newCD);
-
currCD = listModel.size()-1; // sets currCD to added index
-
-
-
// Clear the text fields after add
-
artistField.setText(null);
-
cdNameField.setText(null);
-
itemField.setText(null);
-
nstockField.setText(null);
-
priceField.setText(null);
-
-
-
}// end Modify
-
-
// Search the Name Field
-
cdNameField.addCaretListener(new CaretListener()
-
{
-
public void caretUpdate(CaretEvent e)
-
{
-
JTextField f = (JtextField)e.getSource();
-
final String s = f.getText();
-
-
-
// run it
-
public static void main(String args[])
-
{
-
JFrame frame = new JFrame( "CD Inventory Logo" );
-
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
-
-
java.awt.EventQueue.invokeLater(new Runnable()
-
{
-
public void run()
-
{
-
new Inventory2().setVisible(true);
-
}
-
});
-
}
-
-
} // close class
21 2875 JosAH 11,448
Recognized Expert MVP
Don't allow the user to enter that (integer) key him/herself. Users are stupid
beings that make mistakes all the time. Have you had a look at the Bitset
class yet? I might come in handy.
kind regards,
Jos
I did. It is what I thought of useing, but the API just confuses me.
I do not yet understand how to use the API properly, so I have been scanning the internet for code examples of one that is actually being used, but I cannot find a model to try and use to set mine up.
JosAH 11,448
Recognized Expert MVP
I did. It is what I thought of useing, but the API just confuses me.
It just allows you to set bits or reset them; either single bits or a range of them.
You can also go fancy and 'or', 'and', 'xor' and whatever with two entire bit sets.
You just need the simple stuff: get the first bit that wasn't set to true and set
a bit to true or false. Compare it with a boolean[] array except that a BitSet is
more clever than that.
kind regards,
Jos
wow. Now I feel dumb. I know nothing about arrays, and boolean is just a term to me at this point for true or false.
I understand the basic concept, but have no idea how to code it.
Am I reformatting the field? Am I creating a whole new field? Am I creating this bit and then applying it to my itemno field?
I am lost.
JosAH 11,448
Recognized Expert MVP
wow. Now I feel dumb. I know nothing about arrays, and boolean is just a term to me at this point for true or false.
I understand the basic concept, but have no idea how to code it.
Am I reformatting the field? Am I creating a whole new field? Am I creating this bit and then applying it to my itemno field?
I am lost.
Read all about that BitSet class and judge for yourself whether you can use it
or not; maybe my suggestion was all wrong. You won't know until you've understood
what that set is all about ;-)
kind regards,
Jos
I have read it, and I do think it will help, but reading about it does not show me how to code it in to my existing program. That is what I do not understand.
I understand that you do not wish to just hand out code,
but could you show code examples of what I might try? I have never seen this implemented anywhere, it is hard for me to see how I would put it in action with what I already have.
JosAH 11,448
Recognized Expert MVP
I have read it, and I do think it will help, but reading about it does not show me how to code it in to my existing program. That is what I do not understand.
I understand that you do not wish to just hand out code,
but could you show code examples of what I might try? I have never seen this implemented anywhere, it is hard for me to see how I would put it in action with what I already have.
There's a saying: "code to the interface, not to the implementation". You want a
'thing' that gives you a unique integer number when you ask for it and you can
return a number (previously given to you by that 'thing') telling it that it can be
used again in the future if you ask for another number again.
Those numbers are your primary keys for your CD collection.
Here goes: -
public interface PrimaryKeyGenerator {
-
public int give();
-
public void take();
-
}
-
If you pass a PrimaryKeyGenerator (an interface!) to your CD collection at
construction time (store it as a member variable), you can use it all over the
place, i.e. when you insert a new CD you ask it to give() you a number; when
you delete a CD you let that object take() it back.
You should be able to program and compile your CD collection class using this
interface; of course it won't run (yet) because there is no implementation of this
interface yet.
Here's a stupid implementation: i.e. it generates the numbers 0, 1, 2 ... and
it doesn't do anything when you make it take() a number back again. You
obviously don't want this implementation as a final implementation but it is
enough to get you started. We'll implement a clever PrimaryKeyGenerator
later when you understand that BitSet API. Here's the stupid interface implementation: -
public class StupidPrimaryKeyGenerator implements PrimaryKeyGenerator {
-
private int key;
-
public synchronized int give() { return key++; }
-
public void take() { }
-
}
-
kind regards,
Jos
OK, that is an explaination I THINK I understand.
So, I do not want the user entering anything in to my itemField, I should probably just set editable to false and be done with it right off the bat.
I should then impliment the public int give(); every time a cd is added, which stupidkeygenerator will give the next available number?
Is that about the long and short of it, or am I twisted?
If all that is right, my only remaining question (at the moment) would be how does int give() know to give its number to itemField?
should I not also have to change the way the field is built and initialize?
currently I have this: - private JTextField itemField;
-
and
-
itemField = new JTextField(4);
-
itemField.setEditable(true);
-
and
-
newCD.setItemno(Integer.parseInt(itemField.getText()));
-
when a cd is added
If I am to code the interface, and not the implementation, will not most of that need to change also?
OK, that is an explaination I THINK I understand.
So, I do not want the user entering anything in to my itemField, I should probably just set editable to false and be done with it right off the bat.
I should then impliment the public int give(); every time a cd is added, which stupidkeygenerator will give the next available number?
Is that about the long and short of it, or am I twisted?
If all that is right, my only remaining question (at the moment) would be how does int give() know to give its number to itemField?
should I not also have to change the way the field is built and initialize?
currently I have this: - private JTextField itemField;
-
and
-
itemField = new JTextField(4);
-
itemField.setEditable(true);
-
and
-
newCD.setItemno(Integer.parseInt(itemField.getText()));
-
when a cd is added
If I am to code the interface, and not the implementation, will not most of that need to change also?
But now in that class you have a KeyGenerator object, so instead of setting itemNo with value entered by the user, you simply call the give method and use the number that it has generated as the itemNo
JosAH 11,448
Recognized Expert MVP
OK, that is an explaination I THINK I understand.
So, I do not want the user entering anything in to my itemField, I should probably just set editable to false and be done with it right off the bat.
I should then impliment the public int give(); every time a cd is added, which stupidkeygenerator will give the next available number?
Erm, you should just invoke the give() method if you want a new primary key
for a new CD. The method is implemented by the implementation of that interface
(here it's the stupid implementation which you pass to the constructor of your
CD collection object just once).
Is that about the long and short of it, or am I twisted?
Yep, I think it's right: you pass a key generator to the constructor of your CD
collection class and the methods of your class use that thing when they want
a new number or if they want to give a number back to it.
If all that is right, my only remaining question (at the moment) would be how does int give() know to give its number to itemField?
should I not also have to change the way the field is built and initialize?
It doesn't know that: all it does is give a new unique number; your methods
are supposed to stick that number in a text field or in some other place.
currently I have this: - private JTextField itemField;
-
and
-
itemField = new JTextField(4);
-
itemField.setEditable(true);
-
and
-
newCD.setItemno(Integer.parseInt(itemField.getText()));
-
when a cd is added
If I am to code the interface, and not the implementation, will not most of that need to change also?
Nope, don't parse anything from that textfield; use that number the generator
give()s you. It's a unique number and that's what you want. If you want to display
the data given a currCD, simply retrieve it from your JList and display it in the
text field (the user can't edit it anyway).
kind regards,
Jos
OK. after two hours, several curse words I think I am pretty close.
I tried to take all that and weave it into the fabric of my current code.
This is what I have.
I took the generator and put it into my primary Inventory class - public interface PrimaryKeyGenerator
-
{
-
public int give();
-
public void take();
-
}
No compile issues so I moved forward.
I then took the code from your implementor class in put it in my objects class
cdwartist where I already have several object defined. - // returns indivudual inventory value for a disk
-
public float getTotal()
-
{
-
return(price * nstock)+((price * nstock)* restock);
-
}
-
-
// generates automotic number for itemno
-
public synchronized int give()
-
{
-
return key++;
-
}
-
// takes back number from itemno
-
public void take()
-
{
-
}
and - private float invtotal; // total inventory value of all cds
-
private int key; // generator for itemno field
No compile issues there, so I think I am getting somewhere. I move back to my primary inventory class to make the itemno field use this key everytime a cd is added ... - // Create cd to add
-
CdwArtist newCD = new CdwArtist();
-
newCD.setArtist(artistField.getText());
-
newCD.setName(cdNameField.getText());
-
newCD.setItemno(give());
-
//newCD.setItemno(Integer.parseInt(itemField.getText()));
-
newCD.setNstock(Integer.parseInt(nstockField.getText()));
-
newCD.setPrice(Float.parseFloat(priceField.getText()));
I left the old one in (commented out) until I get this one working, but this is where I hit a snag, and it errors saying Inventory2.java:289: cannot find symbol
symbol : method give()
location: class Inventory2
newCD.setItemno(give());
I think I am close but just missing a simple step somewhere ... any suggestions?
JosAH 11,448
Recognized Expert MVP
OK. after two hours, several curse words I think I am pretty close.
I tried to take all that and weave it into the fabric of my current code.
You did what? You should have made at least three separate files:
1) PrimaryKeyGenerator.java
2) StupidPrimaryKeyGenerator.java
3) CDInventory.java
and your add and delete functionality should just have invoked the give() and
take() methods. The give() call on the PrimaryKeyGenerator should be the
substitute for parsing that text field.
kind regards,
Jos
Object-oriented programming tries to run away from all that weaving and lumping together of functionality.
Code that achieves different functionality should be kept as separate as possible so that different functionalities can be worked on at different times (and possibly by different people too).
In your case the unique number generating functionality should not be mixed with the rest of the inventory management code. Always be on the look out for this when designing your programs. If you require new functionality that consists of many actions(e.g generation and management of primary keys) you must add a new object (read class) to your system that can do this functionality and implements the required methods without affecting the rest of your code.
OK, my post was a little ambiguous.
I did use three classes, two of them I already had.
the first, as you pointed out was Inventory.java (my application)
I initialized the components - public interface PrimaryKeyGenerator
-
{
-
public int give();
-
public void take();
-
}
the second was simpleprimarykeygenerator.java
here is pretty self explainatory, i put
public class SimplePrimaryKeyGenerator implements PrimaryKeyGenerator - {
-
private int key;
-
-
public synchronized int give()
-
{
-
return key++;
-
}
-
-
public void take()
-
{
-
}
-
} // end class
and the third was cdwartist.java that I already had, and where I define many of my objects. I put - // generates automotic number for itemno
-
public synchronized int give()
-
{
-
return key++;
-
}
-
// takes back number from itemno
-
public void take()
-
{
-
}
Is that not acceptable? I did not make a new class for each one because I thought it would be better to group like objects.
JosAH 11,448
Recognized Expert MVP
OK, my post was a little ambiguous.
I did use three classes, two of them I already had.
the first, as you pointed out was Inventory.java (my application)
I initialized the components - public interface PrimaryKeyGenerator
-
{
-
public int give();
-
public void take();
-
}
the second was simpleprimarykeygenerator.java
here is pretty self explainatory, i put
public class SimplePrimaryKeyGenerator implements PrimaryKeyGenerator - {
-
private int key;
-
-
public synchronized int give()
-
{
-
return key++;
-
}
-
-
public void take()
-
{
-
}
-
} // end class
and the third was cdwartist.java that I already had, and where I define many of my objects. I put - // generates automotic number for itemno
-
public synchronized int give()
-
{
-
return key++;
-
}
-
// takes back number from itemno
-
public void take()
-
{
-
}
Is that not acceptable? I did not make a new class for each one because I thought it would be better to group like objects.
Erm, no, I don't find that acceptable because you're defining those methods
again which you defined before in a class that implements the PrimaryKeyGenerator
interface. What's the use of that? Never repeat yourself. All you need is that
SimplePKG (acronym alert!) as the implementation for the interface; there's
no need to repeat the implementation anywhere else.
Think of an interface as a 'promiss' or a 'contract'; think of the SimplePKG class
as an implementation of that contract or a fulfillment of that contract. You don't
need anything else.
kind regards,
Jos
Well, as I was going through and coding everything it dawned on me, I am already using a counter in my app, currCD that is tied to my list index.
I simply changed two lines of code.
I set itemno=(currCD+1) so that it would not start with 0 as the index does
and I added ++currCD to my ADD button so that it would keep up with my new cds.
It actually took longer to clean out all the stuff I put in today than it did to get that to work! :o)
Thanks guys. have a nice weekend.
JosAH 11,448
Recognized Expert MVP
Well, as I was going through and coding everything it dawned on me, I am already using a counter in my app, currCD that is tied to my list index.
I simply changed two lines of code.
I set itemno=(currCD+1) so that it would not start with 0 as the index does
and I added ++currCD to my ADD button so that it would keep up with my new cds.
It actually took longer to clean out all the stuff I put in today than it did to get that to work! :o)
Thanks guys. have a nice weekend.
currCD cannot be the primary key for a new CD, because currCD is some sort
of cursor in your table, e.g. it could be 0 (first CD in the list) and you don't want
another CD with that value as its primary key.
kind regards,
Jos
I do not know about all that, but it is working as planned, so I am leaving it alone before I break it. :o)
Thanks Jos
JosAH 11,448
Recognized Expert MVP
I do not know about all that, but it is working as planned, so I am leaving it alone before I break it. :o)
Thanks Jos
You're welcome of course but using the currCD member variable as a primary
key is not going to work; your heading off for the wrong track if you try it that
way; you'll see (this is not a threat ;-)
kind regards,
Jos
I think the term "primary number" is our problem. I am not sure what that means or implies, I simply wanted itemno field to be automatically kept in ascending order instead of user entered.
Each new disk has a number higher than the previous last numbered disk.
From all my testing and retesting this solution satisfies that requirement.
JosAH 11,448
Recognized Expert MVP
I think the term "primary number" is our problem. I am not sure what that means or implies, I simply wanted itemno field to be automatically kept in ascending order instead of user entered.
Each new disk has a number higher than the previous last numbered disk.
From all my testing and retesting this solution satisfies that requirement.
Maybe I misunderstood your description of your new algorithm. If it ain't broke,
don't fix it ;-)
kind regards,
Jos
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Roman Thurnherr |
last post by:
Hi all
I'm using two JLists with the same MouseListener in a JFrame. How can I find
out on which JList the MouseEvent was released?
Is it generally possible or should I use a MouseListener for each JList?
Thanx for your help
Roman
|
by: Prakash |
last post by:
Hi !
I have a field "sub_tran_no" in my form in continuous view.
When the user presses a button "Re-Number", I'd like to:
1) Save the current record pointer position
2) Save the current field which has focus
3) go to the top of the recordset & start re-numbering
the "sub_tran_no" field with the values 1,2,3, until eof.
|
by: Salha |
last post by:
Hello there,
Can you help me in following problem:
Am working on a chemistry dictionary. I want to have all the chemistry terms in a JList and whenever i select a term from a JList, it displays the meaning in a text area (as any encyclopedia) and the term in a textfield. My questions:
1. How can i load the chemistry terms in to the JList...
|
by: paoparaopao |
last post by:
Hi,
I want to drag rows up/down in a JList; for example, drag 3rd row to 1st row.
I have setDragEnabled(true) for JList, but it doesn't work!
How do I drag rows in JList?
Thanks!
|
by: Nepomuk |
last post by:
Hi!
I'm trying to use a JList. Here's the code:
String languages = {
"deutsch", // german
"english", // english
"castellano", // castilian
"français", // french
"italiano", // italian
"日本語", // japanese
| |
by: sukatoa |
last post by:
I came from List in awt....
Im currently having an experiment about JList....
say like 140,280 ( h,w )
i have 4 values that have been set on JList
using addElement from DefaultListModel....
|
by: wishbone34 |
last post by:
Hi, here is some of my code
public class ControlIL extends JFrame implements ActionListener, ListSelectionListener {
private JList Items;
//builds the UI
public ControlIL(){
DefaultListModel model = new DefaultListModel();
|
by: Gangreen |
last post by:
Hi all,
I've bumped into an odd problem creating a GUI in swing. As you will see in the screenshots, I have a tabbed layout. Each tab is a Jpanel. On this panel I have put a JList, containing a series of objects. My intention is to have a single column of objects in the list, and have it to scroll when the objects exceed the vertical space.
...
|
by: Gangreen |
last post by:
hi,
I have an arrayList in my program that I want to display in a Jlist. I need the JList to update his contents when the elements in the arraylist change/ an element is added/deleted/...
I'm lost on how to do this. Passing the arrayList as an array into the Jlistconstructor will just display the elements, but no updates will be made...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |