no1zson 24 Posting Whiz in Training

Text area?
I have never heard of this.
Can I make it display the full contents of the currCD, whichever one that may be?

Care to quickly show? Or is this a long drawn out process that will only confuse me further.

This is the final step of this project, "The GUI should display the information one product at a time"

no1zson 24 Posting Whiz in Training

Right now, each time I add a cd it lists it in the panel. When I add the next one, it keeps the first one in the panel and lists the second one underneath it.
I only want one listed at a time. When I hit add, I want the last one out of the panel and ONLY the new one in there.
I thought that would be accomplished by fiddling with the toString, but now that you say that it seems like more of a panel issue.

no1zson 24 Posting Whiz in Training

of course not, if you could I would be a programming genious, because I try it 10 times a day it seams.
I also tried putting
CdwArtist currentCD = (CdwArtist) listModel.get( currCD );
back into my inventory class, and calling
return ("Artist: " + (listModel.get(currCD)artist)
but it errors also.
I think I am just grabbing at straws now that I am in the 11th hour and this project is due any minute now.

no1zson 24 Posting Whiz in Training

OK, you have to be talking about currCD that I kept trying to stick everywhere.
Now that I think I know the right place to put it I cannot get it to work.

return ("Artist: " + currCD.getArtist() +

I have tried it three or four different ways thinking I just had the syntax wrong, but I am now beginning to thing that maybe once again I am just using the wrong one.

no1zson 24 Posting Whiz in Training

Wow. For once I was actually thinking too much. That was way too simple. I tend to over analize when I start getting tired.
One more question before I close this out and get some sleep, maybe take a day or two off before I start working on new buttons to put in here, but I am going to try and format the output to be more aestetic than one continuous line, which will mean I only want to display one cd at a time in the output box.
I have been doing stupid crap to it for two days trying to impliment this, I know it has to be simple, but I am just not thinking about it right.
Here is my latest attempt ... I know I need to call newCD right?

public String toString()
	{
	return listModel.newCD("Artist: " + artist +
	" CD Name: " + name + 
	" Item Number: " + itemno + 
	" Price: $" + formatter.format(getPrice()) + 
	" In Stock: " + nstock + 
	" Stock Value: $" + formatter.format(getValue())  + 
	" Restocking Fee: $" + restock + 
	" Total Inventory Value: $"  + formatter.format(getTotal()));

I think this is the closest I have to being right, because it only gives me the symbol error, every other thing I have tried really blows up.

no1zson 24 Posting Whiz in Training

You are right, and I know it. If I am ever to be self sufficient I must learn the APIs. This is not something that was covered before class, not something covered during class, we are just kind of told they are there if we need them during the first week, and left to discover them on our own. I do not really have a problem with that, but when thrown neck deep in coding assignments trying to figure them out just confuses me more. I graduate in two more weeks, and at that time I plan to actually begin learning all these things that will actaully make me a better programmer.
Immediate problem for me is my grade, so long term has to be set aside for now, as frustrating as it may be.
I did go through the tutorial on formatting, and it was pretty helpful in some respects.
I am trying this:

import java.util.*;

public class CdwArtist extends Compactdisk
{
 
 private String artist; // artist performing on cd
 private float restock; // restocking percentage
 private float total; // total of all inventory stock
 

  
 // Artist constructor
  public CdwArtist()
 {
 artist = "";
 restock = .05f;
 total = .00f;
 }
 
 public CdwArtist(String in)
 {
 artist=in;
 }
 
 // get values
 public void setArtist(String in)
 {
 artist=in;
 }
 public void setRestock(float cdRestock)
 {
 restock = cdRestock;
 }
 public void setTotal(float cdtotal)
 {
 total = cdtotal;
 }
  
 // return value
 public String getArtist()
 {
 return (artist);
 } …
no1zson 24 Posting Whiz in Training

I looked at the documentation, and I know it should help, but it does not. I just do not yet understand how to read those parameters on that site and mine down to what I need.

I do however understand new DecimalFormat("0.00") ... I just do not know how or where to impliment.

In the runnable? Maybe in CdwArtist (as that is where my toString is? Maybe even in Inventory as that is my primary class? I want to put it right under my // new JLIst model
format = new DecimalFormat("0.00") ??

Even if that is right, how would I show an individual parameter to utilize the new format?

no1zson 24 Posting Whiz in Training

In an effort to correct the problem I have gone through and changed all participating variables to read as such, hoping it was simple formatting issue.

public Compactdisk()

    // 4 fields need to be set up
    { 
    name = "";
    price = .00f;
    itemno = 0;
    nstock = 0;
    i = 0;
    value = .00f;
    }

Nothing changes. The math is still right, but $20.00 shows as $20.0

If I put in an off price, such as 10.51 everything except the total is then right. The total will carry out how ever many spots it needs. 50.2345555 for example.
I just need these fields to round to a two digit decimal place.

no1zson 24 Posting Whiz in Training

That is not exactly what I get, but I have my math and all correct now (see above post), my problem is the zero after the decimal point. That is a monetary field and should carry two zeros.
I try entering 20.00 in the price field and the program explodes also, so I need some way to input and export these values as dollar type amounts.

Does that make sense?

no1zson 24 Posting Whiz in Training

I am so stupid. I left price out of the add statement. How was anything supposed to work without the price in there.

        // 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(Integer.parseInt(priceField.getText()));

Quick question though, how do I make my output carry two zeros after the decimal. Right now it has $2.0, or $4.0 and that is not right for monetary considerartion.

no1zson 24 Posting Whiz in Training

I am sure this is a symptom of the problem, but the only thing that IS showing up is Name, Artist and .05 for restocking fee, everything else, even price that I enter shows up as 0. Something has to be pointed to the wrong place I think.

no1zson 24 Posting Whiz in Training

I am closing this out. I have put too much time into the other code to abandon it now.

no1zson 24 Posting Whiz in Training

That is what I thought. I stayed up till midnight last night trying every different combination under the sun, and they still show up as 0.
Here is what I have now, along with the two classes. This is really getting to me.

import java.util.*;

public class CdwArtist extends Compactdisk
{
 
 private String artist; // artist performing on cd
 private float restock; // restocking percentage
 private float total; // total of all inventory stock
  
 // Artist constructor
  public CdwArtist()
 {
 artist = "";
 restock = .05f;
 total = 0;
 }
 
 public CdwArtist(String in)
 {
 artist=in;
 }
 
 // get values
 public void setArtist(String in)
 {
 artist=in;
 }
 public void setRestock(float cdRestock)
 {
 restock = cdRestock;
 }
 public void setTotal(float cdtotal)
 {
 total = cdtotal;
 }
  
 // return value
 public String getArtist()
 {
 return (artist);
 }
	
 // returns indivudual inventory value for a disk
 public float getTotal()
 {
 return(price * nstock)+((price * nstock)* restock);
 }	
	
	//new toString
	
	public String toString()
	{
	return ("Artist: " + artist + 
	" CD Name: " + name + 
	" Item Number: " + itemno + 
	" Price: $" +price + 
	" In Stock: " + nstock + 
	" Stock Value: $" + getValue() + 
	" Restocking Fee: $" + restock + 
	" Total Inventory Value: $"  + getTotal());
	}
} //End Class
import java.lang.Comparable;

public class Compactdisk implements Comparable
{// begin class

	//InventoryCD class has 5 fields
	public String name; //  Name of cd
	public float price; // price of cd
	public int …
no1zson 24 Posting Whiz in Training

I am a little confused as to when these calculations to be output are even performed. In my previous applications, I just output Value and by its very definition(stock * price) the total was what I received. I am still putting those figures in, stock and price show up in my output, but value is $0.
Is something different doing it this way?
I have removed all those fields, and am just inputting numbers.
Should I then have, in my addactionevent the calculations to be performed?
Why would value not be calculated as before as soon as price and stock are input?

no1zson 24 Posting Whiz in Training

Instead, consider this: Why not simply display the value of calculated fields in the toString() info that shows in the list entry and drop the text fields for them altogether? There is little need to provide text entry fields for data that the user doesn't need to enter or edit - such as values calculated from other inputs.

Genious in its simplicity, and it shortens my code considerably since I no longer need all those labels and fields.

I do have one more question though, concerning the placement in the tostring:

public float getTotal()
{
return(price * nstock)+((price * nstock)* restock);
}


//new toString


public String toString()
{
return "Artist:" + artist +
" CD Name: " + name +
" Item Number: " + itemno +
" Price: $" +price +
" In Stock: " + nstock +
" Stock Value: " + value +
" Restocking Fee: " + restock +
" Total Inventory Value: $"  + total;

How could I put a calculated field like the one above in here? What would it look like?

no1zson 24 Posting Whiz in Training

You are correct. With this one I am not going above and beyond anything that is being requested.
All I want with this is to be able to display the elements of the array one at a time, and perform those pesky calculations of course.
I will put an add and del button in sometime over the next few weeks if I stick with this one.

no1zson 24 Posting Whiz in Training

I knew that was the same error. I do not know why I cannot get that straight in my head.
I will work on that this evening.
Other than that, how does this look, as you are so familiar with the other version.

no1zson 24 Posting Whiz in Training

You are probably right. The assigment says show the values in the GUI, but not specifically in fields in the GUI, so maybe we could do it that way.
I am willing to give it a shot if you are willing to show me.

I put my other code up that I have been working on today also. I am taking tomorrow off work to concentrate and try and get both versions working. I will either be alot better by tomorrow, or alot more confused. :o)

no1zson 24 Posting Whiz in Training

Here is the panel to that class just in case you want to see it.

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.text.*;
import java.lang.*;


class FontJPanel extends JPanel 
{ 
// display welcome message 
public void paintComponent( Graphics g )
	{
   super.paintComponent( g ); //call superclass's paintComponent
	 // set font to Monospaced (Courier), italic, 12pt and draw a string 
	 g.setFont( new Font( "Monospaced", Font.ITALIC, 12 ) ); 
	 g.drawString( "min", 90, 70 ); 
	 
	 // set font to Serif (Times), bold, 24pt and draw a string 
	 g.setColor( Color.RED ); 
	 g.setFont( new Font( "Serif", Font.BOLD, 24 ) ); 
	 g.drawString( "OFFICE", 60, 60 ); 
	} // end method paintComponent 
} // end class FontJPanel
no1zson 24 Posting Whiz in Training

Crap. Just when I say I am doing fine I get these messages when I compile my main class.

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 Inventory3 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; // delete button 
	private JButton btnLast; // last button
	private JButton btnFirst; // first button
	private JButton btnModify; // modify button
	private JPanel buttonJPanel; // JPanle to hold buttons …
no1zson 24 Posting Whiz in Training

Hedging my bets, I have coded a simpler version of the program Ezzaral is helping me with. I fear I am in over my head over there and may just begin to annoy him with silly questions.
Most of what he and I are working on is beyond the scope of my class anyways, so I did not mind trying to learn more as it made class simpler. I do not want to end up without a working program to turn in though, so I set out on this one this morning.
I am only having one issue at the moment, and it is with "super".
I am not sure why it is not working in this class.
I am getting cannot find symbol, and I do not understand why.
Can anyone offer assistance?

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.text.*;
import java.lang.*;

class CdwArtist extends Compactdisk
{
 
 private String artist; 
  
 // Compactdisk constructor
  public CdwArtist(String Name, int item, int nstock, double price, String artist)
 {
	super(Name, item, nstock, price);
	
	artist = artist;
 }
 
 // get values
 public void setArtist(String artist)
 {
 artist=artist;
 }

 // return value
 public String getArtist()
 {
 return (artist);
 }
	
 // returns indivudual inventory value for a disk
 public double calcRestock()
 {
 return price * nstock * 0.05;
 }	
	

} //End Class

which extends this class

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.text.*;
import java.lang.*;

class Compactdisk //implements Comparable …
no1zson 24 Posting Whiz in Training

Yeah. I guess it would be hard to calculate using figures not really there yet.

I do not understand the concept of the ADD button scenario you just gave. How would creating a blank cd allow me to calculate those fields, when I cannot do it now?
The SAVE button I think I get, once all calculations are complete, then put it in the list.

It is the ADD part throwing me off. Can you elaborate for me?

no1zson 24 Posting Whiz in Training

I hate it when I am stupid. I looked for just that. :@

I would now expect my listener to work now that currCD is working, but it does not. It stays blank until I enter something manually.
I wrote this yesterday as a template before all this, so that if we got it working I could lay down ones for the other fields.
Am I missing something else?

// listener to perform calc upon leaving the price field
		priceField.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent evt)
			{
			valueField.setValue( ((CdwArtist) listModel.get( currCD )).getValue() );

			}
		});
no1zson 24 Posting Whiz in Training

That is a little clearer.
Do I leave the other one in also?
//CdwArtist currentCD = (CdwArtist) listModel.get( currCD );

Both ways I try it the other messages have gone - whew - and the only thing I am left with is
cannot find symbol on currCD here:
currCd = listModel.size()-1;

I thought maybe the -1 needed to be inside the paranthesis, but the message stayed the same so I put it back where you had it.

How can currCD work everywhere but here? <scratching head>

no1zson 24 Posting Whiz in Training

You are right about the toString(), and I can leave it like that for now, I will lose points because I only want to display one at a time, small problem.
For the currCd, I though for sure I understood what you were saying. I re-coded it, as so:

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 …
no1zson 24 Posting Whiz in Training

WOW, YOU could probably finish it in an hour! :icon_lol:

It is going to take me an hour to sit here and think each one through invididually, and a week to impliment AFTER I figure out what is what.

Delete button I am not worried about at the moment, empty fields either. It is the toString(), currCD, listeners, and actions for my fields that have my head spinning.

I have to remark out the CurrentCD line to get it to run, but I know I need it in there for currCD to work. Once that works
I think I just need a line in my buttons to finish it up, currCD++ and currCD-- should be all that is required. If there is more to that please let me know, because everything else needs that to work before I can start it.
The real thing I want to accomplish today is Field Functionality, to make my calculations populate the fields correctly. I need currCD and a bunch of listeners and actions to do that, and I am not sure about how to do those yet.
Display and toString() would come last. Ezzarral showed me some of that last week, but I am still quite shakey on it and cannot accomplish it without help.

no1zson 24 Posting Whiz in Training

You are right, I knew that line was the problem, but we put it in there yesterday to be able to label the cd products so that I would be able to use the buttons to move around in them. View one, the next, the previous etc etc etc.

That line has to be there for future functionality, I just do not think I did all I needed to do to make it work correctly.

Real problem is that now I am dazed and confused, I do not know what to do to move forward, and it is too late to go back to what I was trying to do before. I want to learn this stuff Ezzaral is showing me because it is so much cooler than the other way, but I think I may be above my head now and just becoming a nuisance. I hate coming so far with this code just to stop now though, I feel like a quitter if I do that.
I am trying to create a class (as a backup plan) just using the simple code from class, just so that I have something to turn in and salvage my grade, but I fear it will not be ready by tomorrow.

no1zson 24 Posting Whiz in Training

ok, I think I get that. curCD is my counter, currentCD is the object I am counting, right?

I am now able to compile again, but now I am getting the NullPointerException again, which from last time I remember tells me I probably do not have something initialized correctly.

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at Inventory2.initComponents(Inventory2.java:91)
	at Inventory2.<init>(Inventory2.java:48)
	at Inventory2$6.run(Inventory2.java:283)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

If I read this like you did last time that puts my problem at the currentCD line I just put in, which makes sence as it is the new part I am trying to do, but I just do not see what could be missing.
I have currCD = 0;, I want to add CurrentCD currentCD = new CurrentCD in there, but I do not think that is what it needs, as this line should do that. I am feeling the pressure right now.
This counter is not as hard as I am making it. I still have to work through the field calculation problems once I get this working, and I am feeling more lost that ever.
Project is due tomorrow, and I am kind of wishing I had just stayed with the simple little 5 element array like everyone else, but I tried to get fancy and now I am paying the price.
I have never turned in an incomplete project before, but this is looking …

no1zson 24 Posting Whiz in Training

OK, that makes sense to me. I like the first one better, one line keeps it simple.
Does this not leave me needing to initialize currentCd and currCD somewhere?

I would think currCD needs to be 0, but what about currentCD.

I also understand about currCD needing to update as I add, and delete, but I do not want to start that problem until I understand this first part, unless one not being finished will cause the other to error. Trying to solve more than one problem at a time was confusing me.

no1zson 24 Posting Whiz in Training

I hope this does not sound too dumb, but I actually understood that. I know what final is, and now I know why it is that way, but cannot for the life of me see why that affects this line, even if it is nested. The only other thing I can think of would be my cast, and I am not sure where else I would put it. Here is the code as it sits ...
I cannot believe you have not abandoned me and this project yet. You are a real glutten for punishment.

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; …
no1zson 24 Posting Whiz in Training

It is definatley not for the faint of heart.
I have only been using it for about a month now, and if it were not for the guys out here I think I would have eaten a bullet by now!

no1zson 24 Posting Whiz in Training

Have those been compiled yet? If it is looking for the physical class files, those are not created until after the java program has been compiled.

no1zson 24 Posting Whiz in Training

The only way I know to do that is like this:

priceField.addActionListener(new ActionListener()
		{
			final void actionPerformed(ActionEvent evt)
			{
			valueField.setValue("$"+new Float(currentCD.getValue()));
			}
		});

I am pretty sure this declares the action event as final, which is not right, but as I know no other way I do it, and then get.

Inventory2.java:187: actionPerformed(java.awt.event.ActionEvent) in  cannot implement actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener; attempting to assign weaker access privileges; was public
			final void actionPerformed(ActionEvent evt)
			           ^
Inventory2.java:189: local variable currentCD is accessed from within inner class; needs to be declared final
			valueField.setValue("$"+new Float(currentCD.getValue()));
no1zson 24 Posting Whiz in Training

All thunder is welcome here, as there is certainly none coming from me!
I do think I understand a little better. I added a cast to CdwArtist, andI made some changes that I think help, but got a new error that I have never seen before.

priceField.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent evt)
			{
			 [B]valueField.setValue("$"+new Float(currentCD.getValue()));[/B]
			}
		});

Inventory2.java:189: local variable currentCD is accessed from within inner class; needs to be declared final.
I do not know what to do with this. I know what it means to delcare something final, but not how or why it would apply to this statement.
I think I am getting dumber as the day goes on.

no1zson 24 Posting Whiz in Training

I tried to add this listener in an attempt to have my Value field calculated upon leaving the Price field.

// listener to perform calc upon leaving the price field
		priceField.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent evt)
			{
				valueField.setValue("$"+new Float(CdwArtist.getValue()));
			}
		})

It tells me getValue cannot be referenced from a static context. I am not sure what that means.
I then tried just to do the calculation manually and replaced it with ("$" + (nstock * price));, but it tells me those symbols are not found.

Obviously I am not coding this right, but it is the logic that I am having the most trouble with.
I do not understand why I have to do this step (even when I get it right) if I can get the field defintion problem worked out.
When I define a field as "getValue", and value returns (nstock * price), as defined in my CdwArist class, then why do I have to create a listener in the first place?
Am I making any sence?

no1zson 24 Posting Whiz in Training

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 …
no1zson 24 Posting Whiz in Training

OK. I do not really understand that, so I will try some reading.
I am going to close this thread since you long ago solved my original problem.

These fields and a counter is what I am working on now, and will open another thread if necessary. More like WHEN necessary.
Thanks again for all your help, Ezzaral.

no1zson 24 Posting Whiz in Training

I think I am going to need the cd to know its number. I want to be able to move back and forth in the list with PREVIOUS and NEXT buttons, I assume some kind of counter will need to be implimented?
I started trying to put in a "currCD" parameter just for that purpose, but got so lost in all this week that I am not sure what to try next to get it to work.
Also, on the fields, I understand that they can do anything I want, and when defining them in my parameters I thought I had them doing all kinds of things,

import java.util.*;

public class CdwArtist extends Compactdisk
{
 
 private String artist; // artist performing on cd
 private float restock; // restocking percentage
 private float total; // total of all inventory stock
  
 // Artist constructor
  public CdwArtist()
 {
 artist = "";
 restock = .05f;
 total = 0;
 }
 
 public CdwArtist(String in)
 {
 artist=in;
 }
 
 // get values
 public void setArtist(String in)
 {
 artist=in;
 }
 public void setRestock(float cdRestock)
 {
 restock = cdRestock;
 }
 public void setTotal(float cdtotal)
 {
 total = cdtotal;
 }
  
 // return value
 public String getArtist()
 {
 return (artist);
 }
	
 // returns indivudual inventory value for a disk
 public float getTotal()
 {
 return(price * nstock)+((price * nstock)* restock);
 }

but when I put value into my text field, it does not caculate anything. It stays blank until I go to that field and enter in information manually.
I …

no1zson 24 Posting Whiz in Training

Makes sense, I will work on that and see what I come up with.
My toString() is pretty simple:

public String toString()
	{
	return "Artist:" + artist +
	" CD Name: " + name + 
	" Item Number: " + itemno + 
	" Price: $" +price + 
	" In Stock: " + nstock + 
	" Stock Value: " + value + 
	" Restocking Fee: " + restock + 
	" Total Inventory Value: $"  + total;
	}

so, in the pane it just spits out
Arist:Seether CD Name:Disclaimer ItemNumber:1 Price $20.00 In Stock:1 etc etc etc all in one long row.
Are there commands or sytnax I could put in the toString() for carriage returns, or to show which number in the JList this item is? If so, where could I go to find all these options.

no1zson 24 Posting Whiz in Training

A few questions.
1. Formatting the output of the Jlist. My Pane has a window there and I can see what I entered, but it is just one big line of text. Where can I go to find ways to "pretty that up"
2. The fields I have that should perform calculations do not. I can enter anything I want there. Is this a result of the Jlist, or because I have them set wrong in my class?
3. Tab moves from one field to the next, until it is time to go to the second row of fields, then it does not work and I have to move the cursor there with the mouse. Is this normal?

Again, thanks for the help. I was so frustrated yesterday, and with your help, I have such a good understanding of this GUI now.

no1zson 24 Posting Whiz in Training

Fields must also be initialized!!!
duh!!
Thank you so much. This has of course pointed out other errors that I need to work on. But you have helped me so much today.
I enjoy the interaction.

no1zson 24 Posting Whiz in Training

I do not doubt it. I played with netbeans yesterday for awhile and it seemed easier than this, but the whole purpose is to familiarize myself with the guts of it.
I would like to understand what is happening in the background before I try to get fancy.

no1zson 24 Posting Whiz in Training

That is what I thought. I have gone through it and through it again.
8 fields. 1 jList. 4 buttons and a panel.
Am I just blind?

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 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 …
no1zson 24 Posting Whiz in Training

Does it have to be in the Inventory2 class? Or can this indicate a problem in one of the other two?
I cannot see anything wrong in this class.

If I am reading the error correctly, which is anything but garanteed, it does not like Inventory2, or artist.
Since I could see nothing here, I played with artist in my CdwArtist class, but nothing changes.

no1zson 24 Posting Whiz in Training

Wow. I am not even going to pretend to understand that!
As always you were right though, and after some modifications to my other two classes I was ready to go. No compile errors ... excitement high ... BOOM!

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at Inventory2.initComponents(Inventory2.java:82)
	at Inventory2.<init>(Inventory2.java:47)
	at Inventory2$5.run(Inventory2.java:231)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

I guess now is as good a time as any to learn about NullPointerException ... if you are willing to part with the knowledge, but man I was ready to see this work.
DOS is great, but it is not real programming until I get a GUI in my face!

no1zson 24 Posting Whiz in Training

I believe I have the toString right.
The only thing I am having trouble with, logically, and code wise at the moment is how to solve the String/Int problem in Inventory2.

Do these fields not need to be int, double, or float in order to perform calculations on them?

no1zson 24 Posting Whiz in Training

I feel like a genious (about the CdwArtist class), I had just gotten that to work, and have my sets going to that class ...
here is what it looks like now

// Create cd to add
			CdwArtist cd = new CdwArtist(artistField.getText());
			cd.setName(cdNameField.getText());	
			cd.setItemno(itemField.getText());
			cd.setNstock(nstockField.getText());
			cd.setPrice(priceField.getText());
			cd.setValue(valueField.getText());
			cd.setTotal(totalField.getText());
			cd.setRestock(rstkField.getText());

It must be working because it sees that some of those fields (Itemno for example) is defined as INT in the other class.
It is erroring telling me that those parameters cannot be applied to java.lang.String
I "kind of" understand what it is saying, I have numbers in these fields, some of which I will be doing calculations as, but it is expecting a String. Right? Where would I alter that?
I am going to look at the toString right now and see if I can figure out what you are telling me there.
Thanks again for your help!

no1zson 24 Posting Whiz in Training

I did not understand it at first, but after sitting down and comparing it to what I was writing I could see what I was trying to do, and it cleared up in my head.
Then I started coding, and as I created everything I could see the logic behind what was being built, how the buttons, fields, and JList all work together.
I do have a few questions of course, if you have a moment, ;)
Here is everything, from your original work, to what I have added:

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 …
no1zson 24 Posting Whiz in Training

Just so you know I was not just sitting around waiting on code, here is what I had come up with over the afternoon ... looking at what you hve done I think I was at least headed in the right direction. I was rewriting my entire Inventory class from the ground up. I am not exactly sure where I was going with it, but I kept the idea stream flowing and this is where it took me. :o)

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

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 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 JButton firstBtn; // first button 
	private JButton …
no1zson 24 Posting Whiz in Training

I am going to see what I can do with that and get back with you tomorrow.
I appreciate your patience.