Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I could explain more of an architecture that would let your price field get populated after the relevant data had been entered, but honestly it would require some additional changes that I don't really think you would find worth it just now.

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.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

ActionPerformed will only get triggered by hitting enter in the text field with the listener. Even if triggers though, you will not get the value from a new CD that you are entering, because it is not yet in the list model until you click "add". Instead, what will be set in the field will be the value of the last CD (the one that currCD points to). To alleviate that you would have to either calc the price from text fields that you do have, or have the "Add" button create a new blank CD to work with and put in a Save button that added it to the list model.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You have "currCd" - your variable is "currCD". Case matters.

You don't need the //CdwArtist currentCD = (CdwArtist) listModel.get( currCD ); line in there for anything.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
private void btnAddActionPerformed(ActionEvent evt)
        {
            // Create cd to add
            currCD++;
            artistField.getText(currCD.getArtist());
            cdNameField.getText(currCD.getcdName());    
            Integer.parseInt(itemField.getText(currCD.getitemno()));
            Integer.parseInt(nstockField.getText(currCD.getNstock()));
            Float.parseFloat(priceField.getText(currCD.getPrice()));
            Float.parseFloat(valueField.getText(currCD.getValue()));
            Float.parseFloat(totalField.getText(currCD.getTotal()));
            Float.parseFloat(rstkField.getText(currCD.getrestock()));    
            
            // Add cd to list
            
            
            listModel.addElement(currCD);

Ok, I see. That was not the "currentCD" reference I was talking about. I meant a persistent one that you kept at the class level.
You do need to create a CdwArtist object there to add it to the list. Perhaps we should just call that "newCD" to avoid confusion. Also, since the index is 0 based, it would be easier to initialize currCD with a value of -1 when you declare it, so your add code would be:

private void btnAddActionPerformed(ActionEvent evt)
        {
            // Create cd to add
            CdwArtist newCD = new CdwArtist();
            newCD.setArtist(artistField.getText());
            newCD.setCdName(cdNameField.getText());    
            newCD.setItemNo(Integer.parseInt(itemField.getText());
            
                        <snip other sets>

            // Add cd to list
            listModel.addElement(newCD);
            currCD = listModel.size()-1;    // set currCD to the index that was added
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

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.

No, if you stick with currCD and access the cd object with listModel.get(currCD), you do not need currentCD necessarily. It's just a convenience reference and is probably just confusing you.

Display and toString() would come last.

I thought you already put a toString() method on your CdwArtist class? There was discussion about an item number and line breaks but I thought you had that part in there. You don't really need to get all that fancy on the toString() representation of the object in the list.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

implementing the delete button (remove the element from the array and repopulate the list display to reflect thus), and not allowing it to add CDs with blank values, what do you need to do?

Removing the cd from the list with listModel.remove( currCD ); should update the list display automatically, so that's one less thing to worry about.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you are speaking in terms of game programming, C++ is still the king. C#, Java, and Python are also valid choices.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It would be a lot easier to just download Wampserver or XAMPP. Both will install Apache, MySQL, and PHP already configured.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, as masijade mentioned, initialize the array elements to the value you want to represent "empty" before you start filling it. You didn't say what the valid range for your number entries was, but filling with -1 or Integer.MIN_VALUE can be useful values to represent "unset".

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I made the following change and it works fine

<?php    //instantiate.php

    require('animal.inc');
    
    session_start();

    $dog = new Animal("Woof!");
    
    $_SESSION['dog'] = $dog;    
   
?>

<?php    //call.php

    require('animal.inc');
    
    session_start();

    echo " a dog goes woof";
    
    $dog = $_SESSION['dog'];
    
    //error on next line
    $noise = $dog->makeNoise();
    echo "<BR><B>$noise</B>";
?>

The only change was to provide 'dog' as the key in the session array.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

currentCD was just used as an example of a variable that points to the current CdwArtist object. currCD is an index pointer that can be used to retrieve a CdwArtist object from the list model by index. You can keep one or the other updated to point to your current record. It doens't matter which really, one is by index and the other by reference. Both will allow you to work with a specific entry in the list.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This is the piece that it is complaining about

//Instantiate object for JList
        CdwArtist currentCD = (CdwArtist) listModel.get( currCD );

because currentCD is local to the method and not final. However, even with that changed to final, it still would not behave as you would like.

You want to set the valueField text with the value from whatever CD you are currently on. You have a pointer for this, currCD, so you actually want

valueField.setValue( ((CdwArtist) listModel.get( currCD )).getValue() );

This gets the cd from the model and does the cast in one statement. You alternately move the currentCD declaration into the listener itself if that would make more sense to you

CdwArtist currentCD = (CdwArtist) listModel.get( currCD ); 
valueField.setValue( currentCD.getValue );

Both of these still depend on currCD pointing to the index of the cd in the list, so you must update currCD when you add a new cd, remove one, or move in the list.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I appreciate the help, but that is not what it is. I'm getting errors from the commands in the files im calling in the batch file. I have basically concluded that the place I got these from is worthless...

Again, you don't state what the specific errors are. If you posted some of them it might help.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

That's possibly the most offending thing people can say.
Everyone bad rep this man for saying such crap.

He is already bad-repped into the ground. Just ignore him.

joshSCH commented: Yea, lemme spread some around real quick so I can -rep him more +18
jbennet commented: yeah i agree +22
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you got that batch file from another source, you might see if there is another file like "setEnv.bat" in the directory, which sets the environment classpath. If so, run that one first.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You don't mention what problem you are having with the batch file - but I am thinking it's probably a class path issue. Are you getting things like "No class def found" ?

javac needs to know the class path to find any other classes that your java file is using. This can be specified with the -cp option for the javac command or it can be set via the CLASSPATH environment variable. Here is some more info on that:
http://java.sun.com/javase/6/docs/technotes/tools/windows/classpath.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It is only the local variables inside the method that declares the anonymous inner class that must be final. Here is an explanation that might help:
http://mindprod.com/jgloss/nestedclasses.html#ANONYMOUSVISIBILITY
I'm not sure where you have defined currentCD, but that may be the one that needs to be final. The local variables need to be final because you are defining a separate class to act upon them and it needs to be sure the local reference will remain intact.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ezzaral,

as i understand it, what the user will see are instructions in english. Unfortunately, i'm doing this stuff for a brazilian client and their english over here isn't that good ;-)

Hmm, yeah I don't see anything on the site about internationalized instructions. Sorry =\

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

:( While I'm making my post and trying to work with some errors on my own project, Ezzaral beats me to the punch and steals my thunder.

GG. :p

No, no, your thunder is still valid - the additional explanation may click in an area that mine was vague :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
//Instantiate object for JList
		for (currCD = 0; currCD <99; currCD++)
		
		// add values to textFields
		cdNameField.setText(currCD.getcdName());

You cannot call a method on an int variable, which is what you have tried to do here. You really don't even need this loop to try to set up all cds in the list in the first place. You add one when the user clicks 'add'. If you keep currCD updated to point to the current index of the CD in the list, you can access the object with the expression listModel.get(currCD); . You will need to cast it to CdwArtist to use it's methods though:

CdwArtist currentCD = (CdwArtist) listModel.get( currCD );

since the get() method returns the generic type Object.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You are calling the method in a static context because you have used the class name rather than an object reference to call the getValue() function. You will need to use the current CD object for this call. Your method is almost correct though. You want to set the text of the value field to the result of cd.getValue().

valueField.setText( currentCd.getValue() );

The getValue() method will do the calculation for you, you just need the listeners to call that calculation at the right time and put the value into the field you want it displayed in.

TheGathering commented: You beat me to it :-\ +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can store your object in $_SESSION[] if you need to maintain it throughout many page views. Keep in mind you can't have session_autostart turned on if you wish to include user objects in the SESSION global array, since it needs to load the class definition before the session is started.
See here for more info:
http://www.php.net/manual/en/ref.session.php

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Take a look at ReCaptcha, it might help.
http://recaptcha.net/

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You should place one or more labels which can be used to display the image as an ImageIcon when the box is clicked. See the following tutorial on loading images as ImageIcon.
http://java.sun.com/docs/books/tutorial/uiswing/components/icon.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

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 would have thought that after putting in price, and nstock, a value would appear by itself.

Text fields just display data and let you edit data. They are not "bound" to fields unless you manage that binding yourself. You can make the fields respond by adding listeners such ActionListener, FocusListener, etc. These listeners allow you to perform actions when various events occur, like the user pressing enter, moving to a different component, clicking things, etc. Your button listeners do exactly this currently. They let you specify what code get executed when that event occurs.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You should use a BufferedReader to read the lines and then use either String.split() or the Scanner to separate the items for your use. This is exactly what Masijade told you in the first response to your post by the way.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You could put the number in the string, if the CD knows it's number. You can't easily do the carriage return. It's possible but you would have to supply custom renderers for JList to use and I doubt you want to get into that just yet.

A list generally just shows items as single entries. Tables are generally used to present information in spreadsheet-like listings. If you want to display multiple pieces of info on an item in separate cells, you would want to use a table instead. JTable of course has it's own model architecture that is a bit more complex than JList.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

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"

Well, I can't see it here so that's a bit tough to answer. The item in the JList will show whatever you have specified in the toString() method. You may have to play with that a bit.

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?

At this point they are just text fields, they don't do anything that you don't tell them to do.

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?

The tab order is determined by the FocusTraversalPolicy. You can specify this yourself by creating your own. It's not that difficult. Here is a Sun demo on it:
http://java.sun.com/docs/books/tutorial/uiswing/examples/misc/FocusTraversalDemoProject/src/misc/FocusTraversalDemo.java
and there is more info here:
http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html#customFocusTraversal

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

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.

I knew you would spot it if you kept looking :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, I would think the problem is the Office-specific content and tags in the file. You might take a look at this filter:
http://www.microsoft.com/downloads/details.aspx?FamilyID=209ADBEE-3FBD-482C-83B0-96FB79B74DED&displaylang=EN
from Microsoft that supposedly removes that content. I'm not sure it will fix everything but perhaps it's a start. I'm not surprised that Apache running on a Linux box would balk at Excel mso content, but I don't have direct experience with that.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

J2EE is also designed for such things, but it can be a pretty heavy architecture for a simple client-server app.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Take a look at the component on line 82 and I think you will see which component(s) are causing the problem.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You might want to post a fragment of the code that is not displaying correctly (the xml or xhtml output).

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The trace points to

at Inventory2.initComponents(Inventory2.java:82)

Make sure you don't have a ui component that you haven't initialized yet.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

NullPointerException occurs when you attempt to call a method on an object that is null. You probably tried to call a method on an object you haven't yet initialized. The stack trace indicates this is occuring around line 82 (the line number is not always exact) in the initComponents() method.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You cannot declare a variable in a while condition, which you are attempting with the "int count" part. Change this to

int count;
while( (count = in.read(data,0,1024)) != -1)

instead. Notice the change from != null to != -1 also. The read method returns -1 at the end of the stream, not null.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

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?

The numeric type wrapper objects, such as Integer, Float, Double, etc. have static methods for parsing strings to primary types. In the case of the int, you can use Integer.parseInt(itemField.getText()); to convert the string to an int value.

You will of course get an error if the input cannot be parsed into an int, which is something that would need to be guarded against in a production program, but for your purposes now you can just parse it - you don't need the additional complexity of validation just yet :)

Other parsing functions include Float.parseFloat(), Double.parseDouble(), and Long.parseLong() in case you need them.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

first: CD cd = new CD(artistField.getText());
I know what this is doing, but I am getting the error cannot find symbol pointing at CD.
I even understand the error, I do not see where CD is defined anywhere, nor do I know where it would be put.
second: I also plan to go in an modify my previous Compactdisk and CdwArtist classes for use with this class. How does this class know to use those two?

CD was the small inner class that I put in my listing to hold cd data. You will want to change that to your own CdwArtist class. You will need to override the toString method on that class so that it shows what you want in the list also. Look at the bottom of my code for the CD class definition to see how that is done.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This is accomplished with sockets via http. See if this helps:
http://www2.sys-con.com/itsg/virtualcd/Java/archives/0204/dibella/index.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You do not have much of your code inside a method - it's in the class file. Place that code inside a method, either main or another method that you call from main to execute like A5.run() or something.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, GUI code can be a little complex to jump into. You just have to start simple and keep at it. Perhaps this demo will help. It's just a tiny form I knocked up that let's you add a CD with artist and title to a JList.

import javax.swing.DefaultListModel;

public class ListDemo extends javax.swing.JFrame {
    
    private javax.swing.JButton btnAdd;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblArtist;
    private javax.swing.JLabel lblTitle;
    private javax.swing.JList lstInventory;
    private javax.swing.JTextField txtArtist;
    private javax.swing.JTextField txtTitle;
    
    private DefaultListModel listModel;
    
    
    public ListDemo() {
        initComponents();
    }
    
    private void initComponents() {
        lblArtist = new javax.swing.JLabel();
        txtArtist = new javax.swing.JTextField();
        lblTitle = new javax.swing.JLabel();
        txtTitle = new javax.swing.JTextField();
        btnAdd = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        lstInventory = new javax.swing.JList();

        getContentPane().setLayout(new java.awt.FlowLayout());

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        
        lblArtist.setText("Artist");
        getContentPane().add(lblArtist);

        txtArtist.setMinimumSize(new java.awt.Dimension(75, 19));
        txtArtist.setPreferredSize(new java.awt.Dimension(75, 19));
        getContentPane().add(txtArtist);

        lblTitle.setText("Title");
        getContentPane().add(lblTitle);

        txtTitle.setMinimumSize(new java.awt.Dimension(75, 19));
        txtTitle.setPreferredSize(new java.awt.Dimension(75, 19));
        getContentPane().add(txtTitle);

        btnAdd.setText("Add");
        btnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddActionPerformed(evt);
            }
        });

        getContentPane().add(btnAdd);
        
        listModel = new DefaultListModel();
        lstInventory.setModel(listModel);        

        jScrollPane1.setViewportView(lstInventory);

        getContentPane().add(jScrollPane1);

        pack();
    }

    private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {                                       
        // Create cd and set title
        CD cd = new CD(txtArtist.getText());
        cd.setTitle(txtTitle.getText());
        
        // Add the cd to list
        listModel.addElement(cd);
        
        // Clear the text fields
        txtArtist.setText(null);
        txtTitle.setText(null);
    }                                      
    
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ListDemo().setVisible(true);
            }
        });
    }
    
    /** Small CD class to hold our data */
    class CD {
        private String artist;
        private String title;
        
        public CD(String artist){
            this.artist = artist;
        }
        
        public void setTitle(String title){
            this.title = title;
        }
        
        public String toString(){
            return artist + " …
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You could, if you feel that is easier for you to logically work with. JList has it's own container (the list model) that you can put CDs into. The part from your loop in inventory will largely be replaced by code in a button that creates a new CD, reads the info from your text fields and sets the properties on the CD, and then adds it to the list model.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

What I would recommend is checking to make sure that all methods that are not called from an object using the . operator are declared as static . Otherwise the compiler may just, oh, gosh, not run the blasted thing. Some methods didn't have static in there; I couldn't tell whether or not they were called on their own, but you should keep an eye on that. Buena suerte.

That has no bearing on the issue he is having. When to use static methods instead of normal class methods is a separate design issue.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It is complaining because this line

cDJList = new JList(Object[] guicdInventory);

is not a valid parameter to the constructor - you don't need the Object[] part, just a variable that is an array of Object.

Keep in mind, if you pass in an object array, JList will use the value of toString() for that object in the list. You may have to override

public String toString()

in your CD class to have the name or other description appear in your list.

Also, if you haven't added any CDs to the array at the point you create the list, there won't be anything to display :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

James there is a limit to going off topic. The topic is _Parents_ and you people are talking about _Motherboards_ !!

Well... it does have "mother" in it at least...
:)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The main method is the most basic piece of any program. If you do not understand how to write it then I really have to wonder how you managed to write all of that GUI code yourself.

Anyway, that said, you have the signature for main correct but you have a semicolon at the end and no open brace. It should be:

public static void main(String[] args) {
   // your code to create the object here
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The attibutes inherent to the roll should go into CRoll. Maintenance tasks should go into separate classes such that collections of these tasks can be related to (or owned by) a CRoll instance. Maintenance tasks may be able to share an interface if you can find common ground between them, such as the info on Inspection and Grinding.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Your message already mentions the problem. Your main() method does not do anything. It needs to create the instance of the class and show it.