Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You should be able to just setBorder(null)

ImageIcon cup = new ImageIcon("pics/pots.gif");
       JButton button1 = new JButton(cup);
  // button1.setBackground(false);
      [B]button1.setBorder(null);[/B]
      button1.setBorderPainted(false);
      button1.setPreferredSize(new Dimension(111,51));
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

^
lol, i guess it's too late...

hehe, yeah I guess so. I had to try though.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It worked! Thx a lot! =) Now I can input my name and age, then it say's if im too young or i'm ready to vote. =)

thanks for the help everyone!

No, no, no, NO! Read the other posts. You do NOT want to throw the exception from main(). Don't even consider that an option. Yes, I know that it worked but it is NOT a habit you want to get into.

Add a try{} catch () {} block around the code that is using the reader as other posters have indicated.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

or just add

throws IOException

underneath your main method declaration.

...
public static void main(String args[])
throws IOException {
String name;
...


that should work.

No, main really should not throw exceptions. How do you intend to handle an exception that is thrown beyond the scope of your execution?

The catch block should be placed within main() and handle the exception gracefully.

iamthwee commented: Non sugarcoated straight talking advice! +11
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Using Scanner to read the input would be easier and you wouldn't have to mess with the ioexception.
http://java.sun.com/javase/6/docs/api/java/util/Scanner.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Thank you for your reply. So what you are saying is that I can simply include the database program with the rest of the software and the database program does not have to be installed on the computer as a seperate program.
Do you know which one of these databases is more popular? I have worked with MySQL and Postgres but I have never even heard of H2 or MKoi. So I will probably need a lot of online support from other people.

Mckoi and H2 are both Java file-based DBs, so the DB is just a directory of files and the engine is a jar file that you include with your program. Both are very easy to learn to use from the documentation.

We are currently using Mckoi, but have a few speed issues with very large tables (300,000+ records) and development on it seems to have mostly died since last year. We've begun evaluating H2 and are liking it so far.

Apache Derby is another option you could look into. We cannot switch over to that right now because it has no support for a boolean data type and their SQL parser will not evaluate an int (or byte or whatever) as a boolean, so we would have to change too much code internally.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Hi...

By using java.util.regex.* or java.util.regex package an error msg as symbol can't be resolved is coming.I think it's not supported in WSAD 5.1.What might be the reason ?

From my searching, it looks like 5.1 uses java 1.3 by default, you need to switch this to java 1.4. This thread has some info:
http://www.webservertalk.com/message902279.html

Your development tool is 4 years out of date and you really should look into a more recent version.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It all depends on the nature of the app, but yes, many use a database to store information. The database choice depends on your application needs. If you need a central database for many client apps, take a look at Postgre SQL or MySQL. If each clients data is self-contained, a file-based DB like H2 or Mckoi is very easy to integrate, as you don't have to mess with a separate installation and setup of the database.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Look at the structure of your class and main() method and compare that with your other assignments which do run. Also, look at the brace structure of any if-else block. The problems should be reasily apparent to you.

This is about as basic as debugging can get and you need to spot the problems on your own to learn. I've already told you what the nature of the problem is, so all you have to do is look at those blocks.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Your braces and semicolons are out of place. Look through your if () else if () block and check them.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This is easily done with the java.util.regex package.

String temp="Vendor number modified from 12345 to 00056789";
Pattern pattern = Pattern.compile("Vendor number modified from (\\d+) to (\\d+)");
Matcher matcher = pattern.matcher(temp);
if (matcher.matches()){
    String fromNumber = matcher.group(1);
    String toNumber = matcher.group(2);
    System.out.println("from: "+fromNumber);
    System.out.println("to: "+toNumber);
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You are probably getting the java.lang.NoClassDefFoundError: java/lang/StringBuilder error because you compiled the servlet under 1.5 or above and your app server is running 1.4. StringBuilder was introduced in java 1.5.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, this is easily possible with JSP and Servlets. Please post the question over in the JSP forum, which is there for just such questions.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

hope i've made myself clear..please help guys

This is really a question that belongs in the JSP forum. You will need to read the pollId they clicked from the GET or POST request, place that variable in your query, and display the results. It is a very standard thing for web programming.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

* Get the path of the returned file and somehow turn it into a class name.

I think that is your best option, but there are a couple of considerations to keep in mind.
1) you can reliably know the base path to the classes they have to choose from and the package structure is intact from that base.
2) you know or can determine the type of object being created so you can properly cast the Object from newInstance().

Given those two caveats, this tiny example illustrates using the selected file to load the class. I used two different variations for the baseDir, one which was on my classpath at the time of execution and one which was not. Both worked fine.

JFileChooser chooser = new JFileChooser();
int result = chooser.showOpenDialog(null);
if (result==JFileChooser.APPROVE_OPTION){
    File f = chooser.getSelectedFile();
    //String baseDir = System.getProperty("user.dir")+"\\build\\classes\\";
    String baseDir = "C:\\TEMP\\build\\classes\\";
    String className = f.getPath().replace(baseDir,"").replace(".class","").replace("\\",".");
    try {
        Class c = Class.forName(className);
        c.newInstance().toString();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This will not be very easy to debug with just the code you posted, as there are several interacting classes here. If you do not have an IDE that will let you step through the code as it executes, then you will need to place assertions or System.out.println() statements at the various stages to verify what is being received and processed on the client and server side. I would recommend starting with testing what response the client is receiving. If that result is not correct then check how the server is processing the input. Good luck!

If you are getting specific exceptions or odd behavior you don't understand, post them back here and perhaps we can help.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Why do you need to specify the size? Why must it be a longblob instead of just blob? If you have the answer to the questions then you know what size to set. This really depends on the data that you are going to store. Perhaps you need to read the documentation on the blob data type in MySQL.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The MouseEvent getX() and getY() methods will return the coordinates relative to the source of the event. If your panel is not that source, you will have to compute the coordinates yourself by adding them to the coordinates of the source (which also has getX() and getY() methods) within that panel. It just depends on the layering of your components and which is the source of the mouse event. This tutorial has more info if you need it:
http://java.sun.com/docs/books/tutorial/uiswing/events/mousemotionlistener.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You don't have any output statements in there at all. You need to use print or echo (or some other appropriate stream output methods) if you want any output. What are you wanting to do with the data?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

For detailed information on object-oriented programming in Java, this free online book is a good resource:
http://www.smart2help.com/e-books/tij-3rd-edition/TIJ3.htm

It does not cover new things that have been added with 1.5 and 1.6, but it is still very relevant to the language basics.

For small code examples of all kinds of "how do I do this?" type questions, this can be helpful:
http://www.exampledepot.com/index.html

More tutorial links can be found here:
http://www.daniweb.com/forums/thread82784.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You will need to store the user id in the session when they log in and retrieve it as needed

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

Quick aside: Place code tags around code to maintain formatting. It really helps readability.

The part you'll need to change is

$insertSQL = sprintf("INSERT INTO messages (message) VALUES (%s)",
                       GetSQLValueString($_POST['textarea'], "text"));

I'm not certain how that table is structured, but you will need to add the user id something like this

$insertSQL = sprintf("INSERT INTO messages (userId, message) VALUES (%d,%s)", $userId, GetSQLValueString($_POST['textarea'], "text"));

$userId could be held in the session along with your other properties $_SESSION. You'll also need to make sure that the query which display the messages returns the user name along with the message and use that instead of the logged in user name from the session.

Does that clear it up a bit?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Still having problems with this...any ideas anyone?

Post the relevant code. Without that we can only speculate and offer generic suggestions.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I've tried setting the $loginuser name and session variables to the user id in the database. Obviously not the right thing to do.

Actually, I would store both the user name and the id in the session. Whatever statement that saves the post just needs to include the id. The query that shows posts just needs to display the name along side the comment, so pull all that info in a single query. If you are confused by that, post your code and we can figure out how to change it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If the login name is the id for the user in the database, then that's fine to keep it in the session while they are logged in. You will still need to write that value to the database with the post though. The page that displays posts should retrieve the name of the poster along with the post from the database.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Are you not storing the user id with the post? If you are then you just need to display the name associated with that id. The name (id) associated with a post should not have any dependency on whether a user is logged in.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

"Visual Basic using C#" is a very odd title, as those are 2 different languages, but yes, you will learn about GUI applications I'm sure.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ditch JBuilder 3.
There's no reason whatsoever to still use that dinosaur.

Definitely. It dates to JDK 1.1/1.2 I believe.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Thanks, but.. why?

Well, because you said you wanted a language to create GUIs with :) You could also use PHP, Python, or Perl if you want to use a scripting language instead of a compiled language. You asked an extremely open-ended question, so any suggestion here is going to be accordingly generic.

If you don't want to use C++, then C# and Java are the closest next in line to what you already know. Microsoft provides a free editor for C# and on the Java side Eclipse and Netbeans are two popular free editor choices.

In the end, you'll have to figure out what you are comfortable using for the task.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Java is always a free option for you.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

As masijade said, you can do that with an ActionListener, however I have to wonder why you are writing a Java program just for a login and then opening a web application. Why not simply login in to the web application?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You need to specify the full name of the driver in the Class.forName() call:

Class.forName("com.mysql.jdbc.Driver").newInstance();
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Hi I need help I´ve just installed apache 2.2.4 and php 5.2.3 and everything works fine until I want to load myql extension

I have configured the extensions dir apropiately but somehow the Apache donesnt recognize them

I really need your help

It is generally best not to tack new questions onto the end of solved posts, rather start a new thread for your question.

Your best bet for those configuration issues is to install an AMP package such as XAMPP or WAMPserver if you are working in Windows. Find a LAMP package if you are using Linux.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You are selecting one column but trying to read two.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Sorry, no personal experience parsing hex, but maybe this info could be helpful:
http://mindprod.com/jgloss/hex.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You probably need to add the menu frame to the desktop pane such as in this code fragment

protected void createFrame() {
    MyInternalFrame frame = new MyInternalFrame();
    frame.setVisible(true);
    desktop.add(frame);
    try {
        frame.setSelected(true);
    } catch (java.beans.PropertyVetoException e) {}
}

Is there a particular reason you need to use the JDesktopPane and internal frames, instead of standalone JFrames?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You might change the default 'any' value for houseplans on the form to ""

<option selected="selected" value="">All Types</option>

so that they are all consistent and try this

$plantypes = ($_POST['houseplans']) ? $_POST['houseplans']):'%';
$bed  = ($_POST['bedrooms']) ? $_POST['bedrooms'] : '%';
$bath = ($_POST['bathrooms']) ? $_POST['bathrooms'] : '%';
$garage  = ($_POST['garages']) ? $_POST['garages'] : '%';

. This will set the variable to its selected value if it's not null or '%' for the null case. Then change the query to

$query = sprintf("SELECT PLANNO, PLANTYPES, DESC, BED, BATH, GARAGE, FLOORS, URL, IMG FROM plans WHERE PLANTYPES like '%s' AND BED like '%s' AND BATH like '%s' AND GARAGE like '%s'",
   mysql_real_escape_string($plantypes),
   mysql_real_escape_string($bed),
   mysql_real_escape_string($bath),
   mysql_real_escape_string($garage));

The sprintf() function still needs the '%s' for the variable substitution. From the docs, it sounds like the LIKE '%' wildcard should work with numerics, but I have not verified that myself. It it does not, you will have to build the WHERE string dynamically by concatenating those pieces that have a value other than "" (which was "any").

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ah, the syntax error is because DESC is a reserved word, you'll have to escape that with `desc` I think. You will also need to handle the "any" cases as well, perhaps by changing the use of = to LIKE (i.e. BED LIKE '%') and use the % wildcard for the "any value" cases.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I would recommend changing your form method to 'post' instead of 'get' and then you just need to pull the variables in from the $_POST[] array and you should be good to go. I think you want to do this

//variables from submit form
$houseplans = $_POST['houseplans'];
$bedrooms  = $_POST['bedrooms'];
$bathrooms = $$_POST['bathrooms'];
$garages  = $_POST['garages'];

and change your sql parameters to use those variables.

If you want to stick with GET for your form method, just change the $_POST refs to $_GET.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Actually, making every method static and running the whole thing through main() is just making a procedural program and misses the whole point of OO. Main should only be used as an entry point to set up the needed class(es).

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Thanks for replying to my question. Adding a "try again" button is a good idea, but I'm restricted to a certain design consisting of : one text field, two labels and only one button. Thanks again!

That's fine. Keep a counter of the number of tries, increment when user hits your button to compare a guess, and when they hit five tries it's over. You really don't even need a loop for anything at all.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I assume you are wanting the user to get 5 guesses at the number before ending. This isn't really what your loop is doing though. It is evaluating the same input 5 times (or less if they got it right) and then exiting.

int n = Integer.parseInt(t.getText());

will not wait for input from the user line a Scanner.nextInt() would. It just reads that field each iteration and keeps going. You will need to move the loop up to a different method (like a "Try Again" button handler) that allows them to enter up to 5 guesses before begin disabled. You could leave the the compare code in your method if you like, but you will need the loop to be separate so that you only read new input when they hit the button (or press enter if you want to use an ActionListener on the test field).

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

So are you hinting that I could possibly use currCD to set this value, with little change since it is already coded and working?

I thought about trying something like that, when I started looking at putting key++ in my add button code, but was worried about using the same counter for two different things. Thought that might create some kind of problems somewhere.

You are only using it to set an item number property on the object. That won't affect your usage of currCD as the pointer to the current list position at all.
listModel.add() adds the item to the end of the list, thus the index of the last items increases by one automatically. You are just capturing that value and saving it to the item id property. You could set it to (currCD+1) if you don't want zero based item ids.

Since you are not using that value to access anything anyway, it doesn't matter what the number is as long as it's unique in the list. A simple int itemCounter and a setItemId(++itemCounter) would work just as well.

peter_budo commented: Nice explanation +5
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Keep in mind, you already set currCD to the last index of the list model after you add it - and that index position is unique.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I don't see anywhere that you have initialized an instance of your key generator, unless you have that elsewhere in the code. You'll have to create one before you can call it.

Using a separate class with an extra interface is a bit of overkill for what you are needing here, but it will work if you want to stick with that. I would change the variable names to something that makes sense to you, such as getKey() instead of give().

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ez-
That is not entirely true. I do not replace any code without thinking it through. The problem for me is that, besides here, I have absolutley NO instruction on how to do any of this. A month ago I did not even know what a method was...

My apologies for the particular choice of words.

Glad you got it to work. A couple of suggestions:

// SAVE        
        private void btnSaveActionPerformed(ActionEvent evt)
        {
            // use variable names that have meaning in your context
            File dataDir = new File("C:" + File.separator + "data");
                    
            try
            {
                if( !dataDir.exists() )// shorter expresion with ! operator
                {
                   dataDir.mkdir();// make directory
                   // toWork.createNewFile();  // create file (don't need)
                }
                if( !dataDir.canRead() ) 
                    System.out.println("Read Error.");
                if( !toWork.canWrite()) 
                    System.out.println("Write error.");
                }
                
                catch (Exception e){
                 // generally not good to catch exceptions and do nothing
                }   

                
            FileOutputStream out; // declare a file output object
            PrintStream p; // declare a print stream object
            
            try
                {
                // create a new file output stream
                // connected to "inventory.dat"
                // can use dataDir here and just append file name
                out = new FileOutputStream(dataDir + File.separator + "inventory.dat");
                
                // connect print stream to the output stream
                p = new PrintStream(out);
                
                p.println (listModel);
                p.close();
               }
               catch (Exception e)
                {
                  System.err.println ("Error writing to file");
                }    
                
        }// end SAVE

Have you looked at the output in your data file yet? It might not be what you expect because the entire listModel.toString() is being dumped to the println() method. You may want to …

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

OK, with the fileoutput stream I was able to write the file, but not create the directory.

Use a separate File object for the directory. Java treats files and directories both as File.

With the new File statement I am able to create the directory but not write the file.

Your code wrote to the console - just like you told it to.

System.out.println(listModel);

I assume you are working from a class example, but you are replacing crucial pieces with chunks of example code here with no thought to what they are actually doing.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

See comments in the code (prefixed Ez).
This should be a working version, but I just banged it out in a text editor real quick so any syntax errors are yours to enjoy. I also didn't bother changing a couple of things that would make it slightly more efficient (like holding on to the reference of the found CD instead of getting it again) because I didn't want to induce even more confusion over the mechanics.

//start at first cd
//currCD = 0;    // Ez: removed, this has nothing to do with the search

// compare
//JTextField f = searchField;  // Ez: also removed, superfluous
final String searchString = searchField.getText(); 

SwingUtilities.invokeLater( new Runnable() 
{ 
    public void run() 
    { 
        boolean matchFound=false;    // Ez: this is a simple boolean flag for whether match found
        for(int i = 0; i < listModel.getSize();  i++) 
        { 
            CdwArtist cdEntry = (CdwArtist)listModel.elementAt(i);
                    
            if(cdEntry.getName().equalsIgnoreCase(searchString))     // Ez: Yes, you were comparing the cdname field against the search field
            { 
                matchFound=true;
                currCD = i;
                break;
            }
        } 
        // Ez: All you have to do now is check the match flag
        if (matchFound) {
            Inventorylist.setSelectedIndex(i); 
            Inventorylist.scrollRectToVisible( Inventorylist.getCellBounds(i,i) );
        
            CdwArtist newCD = (CdwArtist) listModel.get( currCD );
    
            artistField.setText(newCD.getArtist());
            cdNameField.setText(newCD.getName());    
            itemField.setText(String.valueOf(newCD.getItemno()));
            nstockField.setText(String.valueOf(newCD.getNstock()));
            priceField.setText(formatter.format(newCD.getPrice()));
        }
        else
        {
             // Ez: No match
            JOptionPane.showMessageDialog(null,"No CD Match Found","TryAgain",JOptionPane.INFORMATION_MESSAGE); 
        } 
    } 
});
no1zson commented: Best poster out here. Paitence of 10 people. +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

sorry. :$

It is the only way I have found that I can make sense of most of this.
Until I see it down in code, and can see how information flows through what is written, see how the input and output works, then it is just words on the screen.

It is one of the reasons I have such problems with the API I think. I have not seen enough Java to even know how to structure things properly yet, the code frags help with my logic.

I know my stuff is not clean, or probably not even acceptable to most standards with now, but this is the most effective way I have found to learn.

That was only in reply to peter's apology :) With all the pieces of code flying around it's easy to see where he might have thought that was my code fragment.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

My appology then :)

hehe... no worries, there are a lot of code fragments floating around here.