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

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

:( 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

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 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

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

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

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

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
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Honestly? Google or Yahoo.

Sun's generic tutorial on networking can be found here:
http://java.sun.com/docs/books/tutorial/networking/index.html

For specific types of apps though, you're going to have to do some searching.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

By starting on GUI programming, you are venturing a lot deeper into OO programming then you've ever been before. Java has some extremely flexible APIs for visual components but they come at a cost of complexity.

The no class found is because you have used a variable you haven't defined (you mispelled it). Also, this line:

GuicdInventory guiceInentory = new GuicdInventory;

will not compile - no parenthesis.

The button to add new will not go into another class. It has to remain in the JFrame class. You will need the action listener to perform whatever code is needed to add the new CD.

no1zson commented: friendly and helpful, makes you learn. +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You have two options (well, a lot more than 2 actually, but here are two):
Move the code that manages your array into the CdTextFrame class.
Give the Inventory class methods that let you add, remove, and view the CDs and call those methods from your CdTextFrame class.

Instead of a loop using Scanner, you will need a button to Add CD. You will want a JList to display the names of the current CDs in the array. You could also add buttons to Edit or Remove a CD from the Inventory. The listeners for these buttons can act upon the array itself if you have it in the CdTextFrame class, or call methods on the Inventory if you wish to put them there.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

thanks that worked perfectly.

Glad to hear it. Things like that can be very confusing with differences in runtime settings.

With register_globals turned on, all variables from GET and POST are automatically available as a global variable and can be accessed as $variableName. When register_globals is off, you must retrieve the variable from $_GET[] or $_POST[] yourself to use it. The code that you were using from the book obviously had register_globals turned on.

iamthwee commented: very helpful +11
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Do you have "register_globals = Off" or is it on? The default is off I believe, which means you cannot access the offset with just $offset. You will need use:

$offset = $_GET['offset'];
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The compiler is warning that you are mixing float and double calculations, which affect precision. It you don't want to worry about figuring out how to apply casting in your math expression, just change the type of restock to float and assign it "0.05f". The "f" denotes that it is a float, instead of double which is the default for decimals that you type in as literals.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I do not see any structural problems there. You have overridden the method correctly. There are other issues with the code though and it will not compile as you have it posted. You have defined "restock" as an int, assigned it a double value in the constructor, and also left off the semicolon on the assignment.

You will want to make restock a float or double value for your math to work correctly.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

What does the 'next' link look like when you hover over it? Is the script name correct? Where is the code in your page that calls the browse() function? It may not be passing the correct parameters.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, it is trying to find a constructor that does not exist. The code the TheGathering posted defines an empty constructor (meaning no parameters) that can be called with "new CdwArtist()".

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

$header is assigned in a different php file, the file from which it is called.....this may be part of the problem, in that it's not recognizing it as an array after it's passed to the function definition in a separate file. but $header is initialized as such:

// HTML <TABLE> column headers
$header[0]["header"] = "Id";
$header[1]["header"] = "Network";
$header[2]["header"] = "Mask";
$header[3]["header"] = "Size";
$header[4]["header"] = "Type";
$header[5]["header"] = "Router Info";
$header[6]["header"] = "Description";
$header[7]["header"] = "Member Id";
$header[8]["header"] = "User";
$header[9]["header"] = "Assigned";

// query attributes to display in <TABLE> columns
$header[0]["attrib"] = "id";
$header[1]["attrib"] = "network";
$header[2]["attrib"] = "mask";
$header[3]["attrib"] = "size";
$header[4]["attrib"] = "type";
$header[5]["attrib"] = "router_info";
$header[6]["attrib"] = "description";
$header[7]["attrib"] = "member_id";
$header[8]["attrib"] = "user";
$header[9]["attrib"] = "assigned";

and you have an include for that file in your file with the foreach? I don't see a reason that $header would not be a valid parameter for the foreach, unless it's not been defined yet as that array.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

As I mentioned above, the constructor for CdwArtist is different. You have defined a constructor with the artist name parameter, so you must construct the object with that information. See comments I have added in your code below:

// begin display method 
    System.out.print("Enter up to 99 CD Names or STOP to Exit: "); 
    String nameInput = input.nextLine(); //read cd name 
    
    maxlength ++; 
    
     for(int i = 1; i < cds.length && !nameInput.equalsIgnoreCase("STOP"); i++)
     {// begin main While
      [B]cds[i] = new CdwArtist();   // This class does not have an empty constructor like this anymore. You changed it.[/B]
      cds[i].setName(nameInput);
      
      System.out.print("Enter CD Artist Name: "); // prompt for artist name
      CdwArtist artist = new CdwArtist(input.nextLine());  [B]// here you create with the correct constructor, but you don't use the object anywhere else.[/B]
                  
      System.out.print("Enter Price of this CD: "); // prompt for price
      cds[i].setPrice(input.nextFloat()); // price input from user. 
      while (cds[i].getPrice()<= 0) 
         {// begin while 
           System.out.print("Price Must Be Greater Than Zero. Enter Price: ");
            cds[i].setPrice(input.nextFloat()); // cd price loop from user.
          } // End while

I would recommend going back to your original class definition:

import java.util.*;

public class CdwArtist extends Compactdisk
{
 private String artist; // artist performing on cd
 
 // Artist constructor
 public CdwAartist()
 {
 artist = "";
 }
 
 // set value
 public void setCdArtist(String cdArtist)
     { 
     artist = cdArtist;
    }
        
    // return value
    public String getCdArtist()
    {
    return (artist);
    }
    

} //End Class

Then your code is simply this

... <snipped top part>...
    // begin display method 
    System.out.print("Enter up to …
no1zson commented: never fails to be helpful +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

i dont think so because both errors refer to the first line of the foreach statement.


foreach ($header as $element)

and the other one which is the same

foreach ($header as $element)

please help me this is annoying the shit outta me.

You don't show the assignment of $header. Are you sure that it is an array?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Use java.sql.Connection for your "con" variable type. Just change the import type and it will be fine.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Because that is what inheritance (subclassing) is meant for. The subclass extends the capability of the base class by adding extra functionality or giving specific functionality (overriding) behavior that is meant to be generic at the base class level.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

That will not put it into my artist name into the array.
I want to use some derivitive of
cds.setArtist();

If you have changed the definition of the array to CdwArtist cds[], the array now holds the new object type, which does not need the setArtist() call.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I'm not sure what you are using for a textbook in your course, but you might want to take a look at this free online book. It's an older edition, but most everything still applies.
Thinking in Java
http://www.smart2help.com/e-books/tij-3rd-edition/TIJ3.htm

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You are using the constructor in CdwArtist to set the artist when the object is created. Since you no longer have an empty constructor, CdwArtist(), you can't create one like that. You would need the following instead

CdwArtist artist = [B]new[/B] CdwArtist(input.nextLine());
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I have another meeting to go to now, I do not fully understand the use of (string in) and artist=in just yet, and I will still have to code my Inventory class, but a little reading this evening should set me up for that.
Thanks again guys, you always help get me back in the right direction.

The (String in) part is just the parameter declaration of the method signature. You are defining a String parameter named "in". You could call it whatever you like, it's just a variable for the parameter that you will use inside your method. Which leads to the "artist=in" part. You are setting "artist" equal to the parameter that was passed, "in". You could have called it "artistName" instead if you preferred. Then you would set "artist = artistName".

Make sense? It's merely a variable name for that parameter of type String.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It just declares a variable of type (class) Artist. You get "Cannot find symbol" because you do not have a class Artist. Your constructor should be

public CdwArtist(String in) {
   artist=in;
 }

since you have declared a String property "artist".

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, what TheGathering said. Perhaps if you called your new class CdExtended it would make a little more sense to you. CdExtended has all of the info of Compactdisk plus artist info. To use that extra info, you need to use the CdExtended object in your code instead of the base level class of Compactdisk.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Post the entire piece of code and use the code tags.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, your first post did not show any code to check for those entries and went straight to the mail() statement.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

westsiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiide loool people i don't know what you guys have against smoking peopl and i was lying about me being a smoker but 7/8 of my friends mixed of boys and girls are smokers and i don't mind i am a second hand smoker since i was 12 and i got nothing wrong with me so i think these doctors are bunch of liars

I think many would consider that a debatable statement. Your anecdotal evidence may be working against your argument.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

you would be amazed the amount of people ho would do something like that

some builders killed themselves near us by running a petrol generator indoors

Sadly, no, I would not be amazed. I never underestimate the capacity of people to get themselves killed doing foolish things.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I don't see anywhere that your code checks to see if there is anything in the error array and display it if needed. It just goes on to attempt to send the mail and it also doesn't check the return value of the mail function. Make sure you are actually displaying any errors in your error message array and you may want to try to echo your mail parameters prior to sending, to make sure those look ok to you. Capture the return value from mail() and check that as well.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

... and not do something dumb like have an indoor bbq

In general, not doing something dumb figures greatly into longevity.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You could do the whole site in Flash I suppose :P
... which of course would be really slow and irritating...