Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

See comments bolded in the code:

I finaly got my buttons to work and now I have added 3 more buttons which are not working and I added them the same way the other buttons that are working were added. the code compiles and runs with no errors but the 3 new buttons are not working the way I need them to. I think that its the action listener that is not workinng right.
here is what I have so far:

import java.awt.*;
import java.awt.event.*;
import java.text.NumberFormat; // used to format currency
import javax.swing.*;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
 
class InventoryMain extends Frame implements ActionListener
{
    CD[] product;
    JTextField[] fields;
    NumberFormat nf;
    JButton jbtAdd, jbtFirst, jbtPrev, jbtNext, jbtLast, jbtDelete, jbtModify;
    JLabel label; // logo   
    JPanel buttonJPanel; // panel to hold buttons
    String nameText;
    JComboBox combo;
    private int index; 
    int i; // varialbe for looping
    double total = 0; // variable for total inventory   
    static int dispProd = 0; // variable for actionEvents   
    static JTextArea textArea;
    static int addProd = 0;
    static int deleteProd = 0;
    static int modifyProd = 0;
    public static void main(String[] args) 
    {
           
       
        try 
        {
            UIManager.setLookAndFeel(
                    "com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        } 
        catch (Exception e) 
        {
            System.err.println(e.getClass().getName() + ": " + e.getMessage());
        }
        InventoryMain test = new InventoryMain();
        test.initCD();
        test.showGUI();
        test.populateFields(0);
    }
  
   
    
    public void initCD() {
        //Create an array    
        product = new CD[10];
     
        //fill in the classes
        product[0] = new CD( 1, "Crowbar" , 20.00, 10, "00722"); …
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Expanding that path and selecting it should do it if that is the node that you are building the TreePath from.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Are you wanting to highlight the parent of the file node or the file node itself? Your code should be selecting (and highlighting) the last node of the path you specified. Are you certain the path extends all the way to the node you are wanting to select and isn't the path to the parent component?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

java -cp ./mckoi1.0.3/mckoidb.jar; EmbeddedDatabaseDemo is the command I used. How can the same command produce syntax error on computer and work on the other?
My computer must be possesed. I will try a different computer and post back.

You can actually do away with the "./" altogether and just use "mckoi1.0.3/mckoidb.jar", but really I can't see any reason why the command would be balking and printing the usage.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

code in login page is:

header("Location: index.php?$page");

how do i get the data from the variable in index page after redirect from login page

You mean the $page value? Or some other variable? If you mean $page (which I assume is a name-value pair like "var=someValue", if not then you aren't sending it correctly) then in index.php you can read it from the request as $var=$_GET['var']; If this is not what you are asking about, please reply with a little bit more detail on the question.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Acutally, this is line 8:

$interest = ($balance x 6) / 100;

and you need to use * for multiplication instead of 'x'.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Hrmm, not sure what the trouble there is then. I recreated that exact path situation(for the jar) and a copy of your class and ran it here with no problems.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

javac -cp./mckoi1.0.3/mckoidb.jar ./EmbeddedDatabaseDemo.java

Compiles fine. But
java -cp /mckoi1.0.3/mckoidb.jar; EmbeddedDatabaseDemo
is not working. It prints out the java usage file as
if my synatax were incorrect. Can you see what I am
doing wrong?

Try java -cp ./mckoi1.0.3/mckoidb.jar; EmbeddedDatabaseDemo I think you need the "." in front of the path entry if you are referring to a relative folder. I assume you have the jar in a folder /mckoi under whatever directory your class is in?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You don't mention what OS you are using, but most of them have a way from the command line to pipe the output of a program to another source, such as a text file. On windows this can be done like

SomeProgram > Output.txt

to write the output of SomeProgram to the file Output.txt. This might be the easiest way to get the output (unless you need to process it as it is running).

Then it is a simple matter of reading the file and using something like Scanner or java.util.regex or String.split to pull out the fields you need.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Your connection code works just fine for me. I believe you still don't have the class path quite right. You said you used -cp with the javac command, but what about when you run it with the java command? Try

java -cp /mckoi1.0.3/mckoidb.jar; EmbeddedDatabaseDemo

You may have to alter that classpath to match your jar location if I inferred it incorrectly.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ah, ok, sorry I misunderstood you. Class path is all you need to specify to tell your app where to find those files. Class path is merely a list of locations to look for classes that it needs to import. If those are not in the default Java jar files, you need to specify them with either a %CLASSPATH% environment variable, via the -cp switch on the command line, or by listing them in the Class-Path entry in the jar manifest file.

More info on class path can be found here:
http://java.sun.com/j2se/1.3/docs/tooldocs/win32/classpath.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I'm realy interested how this work also. Never did it before....
Would you mind Ezzaral to elaborate on the question? How exactly you point your application toward this JAR file?

If you are asking about the executable jar file, the jar file is the application. In Windows you can just double-click it to run (not sure how other OS handle that) or you can run it with java -jar MyApp.jar .

The main class of the application is specified in the jar manifest file by a property called Main-Class. This is the class that contains the main() method to execute when the app is run.

The classpath for other dependencies outside of your own jar file, such as third-party jar file libraries your app needs, is specified by the Class-Path entry in the manifest.

The manifest allows you to specify pretty much all of the info Java needs to run your program with the exception of command line options. Those you would still need to set in a batch file or shortcut to execute the program.

You can package up the entire app directory stucture in a single zip file such as the following

/MyApp.jar
/RunMyApp.bat (if you need to set switches on the java command)
/config.xml
/images/(any image resources here if you need them)
/lib/(other jar files your app depends on like JDBC dirvers,etc)

More info here if you need it:
http://java.sun.com/docs/books/tutorial/deployment/jar/index.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, there are other ways to deploy your app. See the following:
http://java.sun.com/docs/books/tutorial/deployment/index.html

In particular, I would recommend an executable jar file.

A lib folder is nothing more than a folder named "lib" in your application root directory where third-party libraries are placed. It's just a common convention.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You will have to distribute the database jar file with your app. It can simply reside in a /lib folder. You definitely do not need to add it to the JDK folder.

As far as the classpath, it is not uncommon at all to have a batch program that sets the desired classpath prior to launching the program. If you are distributing your app as an executable jar file, the files in your lib folder can be added to the Class-Path property in your manifest.mf file. If that is done, you won't even need to set the classpath prior to execution.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

echo "<a href='index.htm?pic=$num1'>Link text</a>";

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

First off, please use code tags around any code that you post. See the announcement at the top of the forum for more info.

Now to your question, did you run that with the Applet Viewer? Applets are not executed from the command line like a regular java class.

http://java.sun.com/applets/
http://java.sun.com/docs/books/tutorial/deployment/applet/appletsonlyindex.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

"visualization java tools"? Do you mean the graphics APIs? Please describe what you are wanting to do a little bit more.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You will want to use Calendar (or perhaps specifically GregorianCalendar) class for that. This site has a lot of info on using it: http://mindprod.com/jgloss/calendar.html
Adding time (days, weeks, months, whatever) is a simple matter of using the add() method or the roll() method depending on your needs. Calendar now = Calendar.getInstance(); will give you a locale-specific instance of a Calendar set to the current date and time.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, peter_budo's explanation is exactly what I was suggesting.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Is this for 2D or 3D?

3D with OpenGL (JOGL bindings in particular), though you can certainly do 2D work with OpenGL as well.

Edit: The NeHe tutorials have code portings for many different languages available at the bottom of each lesson, so those are not specific to JOGL (which are for Java).

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Agreed, it is gross and perhaps a health code violation, but I don't believe that is a misdemeanor. I'm sure Officer Salty-Burger will be hearing quite a lot over this one.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, he was right in arresting her - it was a-salt.
:P

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Here are a couple of tutorials:
http://blogoscoped.com/archive/2004_06_23_index.html

http://www.devnewz.com/devnewz-3-20041221UsingPHPCURLLibrarytoScrapetheInternet.html

It's just a matter of obtaing the HTML from a request and parsing out the data you need.

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

Well, you can use

long startTime = System.nanoTime();
   // ... the code being measured ...
   long estimatedTime = System.nanoTime() - startTime;

if you really think you need better than millisecond resolution.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I can't see why you need to avoid split, but Scanner and java.util.regex are other options for parsing your input.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Why not simply return the empty array from the function? It's easier to work with than a null or an exception.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you keep a pointer to the current record int currentIndex; then moving within your array is trivial. You just increment the index as needed and populate the fields based on that index.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

"Ambition is like a frog sitting on a Venus Flytrap. The flytrap can bite and bite, but it won't bother the frog because it only has little tiny plant teeth. But some other stuff could happen and it could be like ambition."
- Jack Handy

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, you would probably have better luck asking this over in the javascript forum, as this one is just Java.

From the php standpoint though, here is a simple login form and verification for a small site I put together for a local grayhound group. Maybe it will help you along:
File: index.php

<html>
<title>Greyhound Adoptions</title>
<LINK REL="StyleSheet" HREF="default.css" TYPE="text/css">
<body>
<center>
<h1>Greyhound Adoptions</h1><BR>
<form action='loginck.php' method=post>
<table border='0' cellspacing='0' cellpadding='0' align=center>
<tr id='cat'>
<tr><td><font face='verdana, arial, helvetica' size='2' align='center'>  Login ID    </font></td> 
    <td align='center'><font face='verdana, arial, helvetica' size='2'><input type ='text' name='userid' ></font></td>
</tr>

<tr><td><font face='verdana, arial, helvetica' size='2' align='center'>  Password</font></td> 
    <td align='center'><font face='verdana, arial, helvetica' size='2'><input type ='password' class='bginput' name='password' ></font></td>
</tr>

<tr><td colspan='2' align='center'><font face='verdana, arial, helvetica' size='2' align='center'>
  <input type='submit' value='Submit'> <input type='reset' value='Reset'></font></td> 
</tr>
<tr> <td colspan='2' align='center'><font face='verdana, arial, helvetica' size='2' align='center'> </font></td> </tr>

</table>
</form>
</center>
</body>
</html>

File: loginck.php

<?php
session_start();
include "dbConn.php";

$userid = $_POST['userid'];
$password = $_POST['password'];

$userid=mysql_real_escape_string($userid);
$password=mysql_real_escape_string($password);

$password = md5($password);

if($rec=mysql_fetch_array(mysql_query("SELECT * FROM users WHERE name='$userid' AND pwd = '$password'"))){
    if(($rec['name']==$userid)&&($rec['pwd']==$password)){
        $_SESSION['id']=session_id();
        $_SESSION['userId']=$userid; 

        header("Location: viewDogs.php");
    }
}
else {

    session_unset();
    echo "<font face='Verdana' size='2' color=red>Wrong Login. Use your correct Userid and Password and Try <br><center><input type='button' value='Retry' onClick='history.go(-1)'></center>";
    session_destroy();
}
?>
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

Well, im hoping to apply that logic to another program (picture), and i think it would be much more efficient if only the cursor were redrawn, and the rest were left alone. As it is right now, each stock price is an object, and they all have to be redrawn along with the bands, and the volume, and everything else.

Ah, ok, yes that is a bit more to render. The offscreen image may work pretty well for you then. For complex lines, you may also want to look at using drawPolyline() from prebuilt x[] and y[] coord arrays. That made a big difference for us on a few of our many-lined graphs here.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This would be your code with an offscreen image for the line

public class graphWriter extends JPanel {
    private int
      markerX = 0,
      markerY = 0,
      width = 0,
      height = 0;
    
    Image bufImage = null;
    
    public graphWriter() {
        addMouseMotionListener(
          new MouseMotionListener() {
            public void mouseDragged(MouseEvent e) {
            }
            
            public void mouseMoved(MouseEvent e) {
                //Get coordinates of the mouse
                markerX = e.getX();
                markerY = e.getY();
                repaint();
            }
        }
        );        
    }
    
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        if (bufImage==null){
            bufImage = createImage(getWidth(), getHeight());
            Graphics gBuf = bufImage.getGraphics();
            //Draw line
            gBuf.drawLine(0, 0, getWidth(), getHeight());
        }

        //Get width and height of current clip
        width  = (int)g.getClipBounds().getWidth();
        height = (int)(g.getClipBounds().getHeight());
        
        //Draw line
        g.drawImage(bufImage,0,0,this);
        
        //Draw two lines, one horizontal, and one vertical to create the cursor
        g.drawLine(markerX, 0, markerX, height);
        g.drawLine(0, markerY, width, markerY);
    }
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

A good free online book can be found here:
http://www.smart2help.com/e-books/tij-3rd-edition/TIJ3.htm

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

So would creating a buffered image and painting the cursor on top of that be like creating a layer on top of an image in Photoshop, and drawing on the new layer?

Thanks.

Yes, somewhat like that. It allows you to draw to an offscreen image and then render that image to the screen. In your case the line would be the image and your paint code would drawImage() and then draw your lines.
http://java.sun.com/docs/books/tutorial/2d/images/index.html

In your case though, I don't think you will really gain anything with the extra trouble. Keeping a BufferedImage offscreen is helpful if you have a very complex image that you don't want to have the expense of regenerating with each paint. Your line drawing doesn't really have that issue here.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You really don't need to. Just be sure that you are doing expensive calculations and such outside of the paint() method and only painting the results. Paint will be called any time the OS needs to update the screen (ie moving, resizing, etc) so try to keep it as lean as possible. If you want to play with buffered image painting, that is one way to keep a copy of what you have already drawn and then draw over it as needed, but for your small example I don't think you need to do that.

You may also want to consider overriding paintComponent() of your JPanel instead of paint(), since paint also paints the borders and child components. paintComponent() is more narrowed to the area you are wanting to render.

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

From the NeHe Gamedev tutorials (http://nehe.gamedev.net/), this jogl port of Lesson 5 has some mouse-based movement code. That might be enough to get you going in the right direction:
http://nehe.gamedev.net/data/lessons/jogl/lesson05.jar

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This forum is to discuss game programming, not cheating.

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

You are very close, it wasn't a homework assignment, but the question was asked by my teacher in my Civics class... she asked what we thought about it and then she told us what she thought. She said that democracy isn't the best form of government, but it is better than most. And some said that dictatorships were more efficient. I tended to agree that democracy was the best form, with a federal government.

You keep throwing "best" and "most efficient" around interchangeably, but they are not the same at all. Your question asked about efficiency.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
b = new JButton("First"); // first button
       b.addActionListener(this);
       b = new JButton("Previous"); // previous button
       b.addActionListener(this);
       b = new JButton("Next"); // next button
       b.addActionListener(this);

Still does not do anything. You are assigning "b" instances of new buttons (replacing the previous each time I might add), but the buttons that are getting added to the panel are being created in showGUI(). You need to add the action listener to the button that is being added to the panel. Also, your current action listener implementation is picking up the combo box index. Each button will need to have its own action to perform.

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

You actually define the buttons twice, once in the initCD() method and then again in showGUI(), but you do not add any ActionListeners (or Actions, both are valid) to be executed when the buttons are pressed.
How To Use Actions

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

@ ezzeral

fade to black as in the rolling stones?
"...i see a raptor and i see it all in black..."?

No, "Fade To Black" from Metallica. You are thinking "Paint It Black" by the Rolling Stones (which is also a good song though)
"I see a red door and I want it painted black..." (no raptors in there :) )

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This site has good tutorials for 2D and 3D rendering for Java games:
http://www.cokeandcode.com/tutorials

This site has links to other 2D and 3D graphics tutorials that are not in a gaming context:
http://www.freeprogrammingresources.com/java-graphics-tutorial.html