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

This code opens and reads a line into $line until there are no more lines:

<?php
  $fp = fopen('file.csv', 'r');
  while (!feof($fp)) {
    $line = fgetcsv($fp, 4096);
    echo $line; // do whatever you need here
  }
  fclose($fp);
?>

file_get() can be used as well, to load each line into an array, if you prefer to work with it like that.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Small sample on storing a value in session:

<?php
  session_start();
  echo 'Sessions activated.<br />';
  $_SESSION['version'] = phpversion();
  echo 'Session data written.<br />';
  echo "Session data read: {$_SESSION['version']}.";
?>

Tutorial on sessions can be found here:
http://www.goodphptutorials.com/track/66

I don't think you will want to store the query itself in the session. That could be a lot of data for the server to serialize and deserialize. Just store enough info to requery as needed. You may want to up your result per page to 10 if the query is somewhat expensive to perform.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Is there mentioned how to read second row onwards or any particular row onwards from csv file? I try look at that wrbsite but couldn't find it.

Right in the middle of the table of contents there is a link to the section "Working with CSV".

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You will need to forward those values along in your GET requests (the Next/Previous links) or you can store them in $_SESSION[] to have them persist. Session is probably the easiest bet.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Here's a tutorial that should get you there:
http://www.goodphptutorials.com/track/62

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you want to interact with the Yahoo server, you will need to use HTTP over sockets. There are many tutorials for this available online, including this one from Sun:
http://java.sun.com/docs/books/tutorial/networking/index.html

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

A simple Google search "Eclipse create WAR file" yields your result immediately:
http://www.java-tips.org/other-api-tips/eclipse/how-to-make-war-file-in-eclipse.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I recommend Scanner highly. This will work nicely if:
a. you replace the commas w/spaces and use nextInt() b. you keep the commas, use next() , and set up an elaborate system to trim the commas out of the String s made and convert said String s to ints
I'd go with "a".

You can set the delimeter to any pattern you wish with the useDelimeter() method. You don't need to convert anything prior to scanning.

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

I believe Apache will let you map any extension you wish to a given mime type, but off the top of my head I can't recall which file it is in. Check the docs on mapping mime types.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Before you criticize someone, you should walk a mile in his shoes. In that way when you do, you would be a mile away and you would have his shoes.

That is very wise advice.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you are using MySQL, in a query you can use the DATE_FORMAT() function http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format
to change the display format of a date. I don't believe you can change the format that the date is stored in though.

If it's a different database you'll have to check the docs. Most DBs have some function that does the same.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Is that not exactly the same as your browse() function here:
http://www.daniweb.com/forums/post406611-7.html


You would need to set the ROWS define to 3 instead of 20, but it seems the same to me.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

the actual code from the book didnt have register_globals turned on, but i think that is the default setting for the vbersion on php that i'm using. that is a config file setting, right?

Yes, it's a setting in your php.ini file.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Absolutely not.
If you don't learn the language, it's syntax and APIs, and always have to look up each and every command as soon as you don't have a tool to do it all for you, you don't know anything.

If you can't read and understand a stacktrace or compiler error, you are utterly useless as a programmer.

If you can't handle frustration and keep functioning regardless, you're utterly useless in any job or any part of life for that matter.
You're instead a spoiled little brat who isn't used to maybe not getting his way once in a while, who starts whining and sulking at the slightest setback instead of facing up to the challenge and overcoming it.

Ok, I'm not trying to say that knowing the API and being able to read a stack trace is useless. What I specifically meant is that I think having tools to help with such things makes it faster to learn with less frustration.

Certainly there is enough information in a trace to know the source of an error, but tools can help you locate the specific code that is causing the error faster and focus on understanding why it is occurring and fixing it.

It's great to know much of the API by heart, but in an application of much size at all, unless you happen to have a photographic memory (I don't, I'm sorry, perhaps that makes me useless as you seem to indicate) you are …

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

Did you read either of the links I supplied? To view in browser, you need to set up an applet tag in an HTML page and then open that page.

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

I think that it's safe to assume that since this guy hasn't even found an IDE yet, he's not going to be working on projects that comprise several hundred class files without spending serious time learning. ;)

Ok, you have a point there :)

I just find those feature to be very handy and code completion and jdk debugger can even benefit a beginner in the learning process. Memorizing API functions and trying to decipher exception messages from a text stack trace only slow down the process of learning the language and how to use it effectively. Some would say "bah, that's all part of the trials a beginner must face!", but I don't think that necessarily enhances learning - it just creates frustration.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Beginner is expected/supposed to learn befor he should get some help with code completition. Many of students at my university failed subject because for once they been using NetBeans at university pc's but couldn't get them running at home/laptops (I will not comment on that). Secondly most labs been done on Unix system with instalation of Java on it.
Personaly I prefer to do it the way as I do, because I'm in charge of coding (hopefully), I have certain habbits while writing and I do not want IDE to automaticaly closing bracklets, providing code completition, trashing my hardisk with tons of new un-necessary folder structors and do other silly things.

That's understandable for learning and is ok for small projects of a few files. Once you start hammering code all day, every day, on a project that comprises several hundred class files though, code completion, jdk debugger, and refactoring become immensely productive :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can either use the AppletViewer as described here:
http://java.sun.com/javase/6/docs/technotes/tools/windows/appletviewer.html

or create an HTML page and place an Applet tag in it to run the applet in your browser:
http://java.sun.com/docs/books/tutorial/deployment/applet/html.html

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

The light (free) edition of JCreator lacks code completion, JDK debugger, and refactoring tools though, which are huge time savers. Granted, Eclipse and Netbeans, while perhaps more complicated for a beginner, offer a fuller feature set from a free IDE.

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

Thinking in Java, 3rd Ed.
http://www.smart2help.com/e-books/tij-3rd-edition/TIJ3.htm

This is another site that is extremely helpful for tiny code fragments to get you started when you are coding something from part of the API that you haven't used before:
http://www.exampledepot.com/index.html
(keep in mind that it's java 1.4 code, so newer things are probably not in there)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I assume you mean IDE when you say compiler, since those are what you listed. I've never used BlueJ, so I can't comment on that one. Eclipse and Netbeans are both good IDEs and are free. There are many commercial ones out there, but I doubt they add enough value over Eclipse or Netbeans to really bother with. We use Netbeans here at work and have always been happy with it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Your fly is unzipped.

iamthwee commented: Deep and thought provoking +12
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

They are doing the same thing. However, one is a constructor and the other is a method. Constructors are used when the object is created. Methods are used after the object is created. If you wanted to create a CdwArtist object with the the artist name already set, you would use the constructor. If you did not know the artist name at the time of creation, you can use the empty constructor to create the object and then call the method to set the artist name later. Multiple constructors allow for flexibility in how an object is initialized upon creation.

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

Just another note: I would recommend B just calling a method on A to handle the state change. That way A can handle it's own internal behavior as needed and B won't be mucking around in the guts of another class.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Just have B and C take a reference to A (the frame) in their constructors. The JPanel components already have a method to getParent(), but it's easier to just pass the reference so you don't have to worry about container nesting and finding the right parent. Your action listener on B can then handle what is shown in A easily.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

hi, my name is Reece, i have learnt, javascript, css, php, xhtml, html and loads of graphic stuff. Im 14 and my teacher said for me to learn asp, but im sure there is no difference, is there??

I'd recommend going on to Java or C# personally. No reason to stick solely to web programming is there?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

> Well, except for that very last person - they would probably still have one eye...
You the overlook the possibility of simultaneous eye stabbing.

It is certainly possible :)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

you can switch between PHP4 and 5 on the fly
it has perl + php
has phpmyadmin
nice interface for configuring services
can be run from a memory stick to show clients
nice security wizard
no major bugs

Thanks for the info. Will keep that in mind.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

"An eye for an eye makes the whole world blind."

Well, except for that very last person - they would probably still have one eye...

harinath_2007 commented: awesome logic... +0
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Take a look at "reCaptcha". It's a pretty neat service and they have a plugin for PHP.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Use XAMPP instead of WAMP. In my opinion its better

What do you find better about XAMPP? Just curious, as I've only used Wampserver.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Try adding the following to your constructor:

public LoggerClass(){ 
           BasicConfigurator.configure();

  myLayout = new SimpleLayout();
  myAppender = new ConsoleAppender(myLayout);

  myLogger.addAppender( myAppender );
    
}

If you want a file appender, you can add one of those like this

try{
    RollingFileAppender fileAppender = new RollingFileAppender(new PatternLayout("%d: %m:  %l " + System.getProperty("line.separator") ), System.getProperty("user.dir") + java.io.File.separator +"application.log");  // can change the pattern and file location to whatever you need
    fileAppender.setMaxBackupIndex(1);
    fileAppender.setMaximumFileSize(1000000L);
    fileAppender.setThreshold(Priority.WARN); // if you want to set a threshold.
    myLogger.addAppender(fileAppender);
    myLogger.info("Started Rolling File Appender");

} catch (Exception ex){
  /* whatever you need here */
}
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

Glad you got it working :)

(I went to high school in Broken Arrow btw... )