Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Also, your calculation isn't keeping track of the remainder after the higher coins have been returned. If you have 0.70 in change, your current calcs would show 2 quarters, 7 dimes, 14 nickels, etc. I think you want to display 2 quarters, 2 dimes as the result.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Plenty of practice tests available on the net. Just search for them.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Rudy was out long ago - he just didn't realize it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you don't even have any idea how to start, you don't really have a project. You have a name of a project.

If you don't have any idea what you want to accomplish, how do you expect anyone to help you accomplish it?

It sounds like you need to flesh out exactly what you want to do and then come back with some concrete questions that someone might actually be able to answer.

(And "every1" isn't a word - please read the forum faq and rules regarding proper English)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

And what exactly is your question? You don't expect anyone to just answer the homework problem for you, do you?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Please don't start multiple threads for the exact same question.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

How are you trying to run it and what is the exact text of the message. Remember that you cannot run applets with the normal "java MyPaint" command.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No, with high taxes, you can pick only one.

Ah yes, gotta find a way to get a jab in about taxes of course. :yawn:

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

"The fear of the LORD is the beginning of knowledge: but fools despise wisdom and instruction." Proverbs 1 : 7

I would argue that fools mistake religion for knowledge and wisdom.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Completely uninteresting.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

StringTokenizer has been deprecated for years now, you should use String.split()

That post was from Feb 2004 :)

Also, the one that nate tacked on to this little piece of history should probably use StringBuilder instead of += for constructing the string.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

That isn't an applet. It's a JFrame. You cannot run a JFrame as an applet.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

..hope to wake up soon b/c 1982 sucks ass.

(No playstation or modern computers :-/)

We just had sticks and rocks to play with... and we liked it! Now get off my lawn!

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, that is because you are stuck right in the middle of things that Netbeans does to organize files in a project, which you do not yet understand, and you are trying to follow the simple notepad and command line tutorial. Either use the Hello World tutorial for Netbeans http://java.sun.com/docs/books/tutorial/getStarted/cupojava/netbeans.html or stick to the steps in the basic tutorial for Windows that you linked. Mixing the two of them is just going to cause you confusion at this point.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Are you using an IDE to create your files or just notepad? If you are using an IDE, it looks like it has placed a "package helloworldapp" statement at the top of your source file. Packages are basically directories to group sets of classes together. Because of that package statement, Java expects that class to reside in the "helloworldapp" directory. It would need to be run from the directory above "helloworldapp" with the following command:

java helloworldapp.HelloWorldApp
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Ok, it actually looks you may just have a case-sensitivity issue with your names. If the class is called HelloWorldApp, it must reside in a file of that exact case-sensitive name. You must use the same case-sensitive name when you run it. "helloworldapp" is not the same as "HelloWorldApp".

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Are you running that command from directory which contains that class? Is there a package declaration in that class?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This is a class path problem. The class path let's Java know where to locate classes for your file. Post the command that you are using to run the program and a bit of directory information on where that class file resides.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you are using Java 1.6, the Console class provides a mechanism for this:
http://java.sun.com/docs/books/tutorial/essential/io/cl.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If you have added println statement to verify str, start, and end then you should know exactly what string input is returning a -1 for which indexOf() call. You have all of the variables there leading to that error, so you just need to figure out why that particular string input is yielding the -1. Are you certain that the final value of "str" is not an empty line or one which has improper quotation marks?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Search these forums for "final project" and you will have plenty to read.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Did you read the api on indexOf() and the conditions under which it will return a -1? Have you added System.out.println() statements to verify your parameters to indexOf() and substring().

You keep posting "I can't figure it out", but do not say what you have tried to do to solve this on your own. There is a point to learning how to debug things like this for yourself and we have tried to guide you towards this as much as possible without simply giving you the answer.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Sorry, this is not a code warehouse for you.
Also, see the forum rules regarding "text speak" :
http://www.daniweb.com/forums/faq.php?faq=daniweb_policies#faq_keep_it_clean

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, if the Runnable has a method which Class A can call when appropriate, it can simply sleep while monitoring for whatever state Class A is expected to set.

For some general info, this article on thread messaging may be useful:
http://www.informit.com/articles/article.aspx?p=167821&rll=1

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Carefully read the API documention on the indexOf() method you are calling and the reason for the -1 should be quite clear. From there it is a matter of determining why that is the value you are receiving.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

String.indexOf throws a StringIndexOutOfBoundsException when either the index parameter is < 0 or > than the length of the String. Hence, make sure to check the indexes before sending them to the indexOf method.

indexOf() does not throw StringIndexOutOfBoundsException.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Also, consider you can use a switch in applyOperation()

switch (op){
    case '+':
        // stuff
        break;

    case '-':
        //stuff
        break;

}

Another possibility is to define your own Actions for each of those buttons

class PlusAction extends AbstractAction{
        public void actionPerformed(ActionEvent e) {
            System.out.println("do plus action");
        }
    }

and set that action on the button with

button2.setAction(new PlusAction());

(edit: You still really need to ditch the "button2", "button_3" variable names and make them "btnPlus" or "buttonPlus" or something. Meaningful variable names go a long way towards making your code easier to understand - not just for others, but also for yourself)

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You cannot declare a method within a method like that, which is what this line is trying to do

public void actionPerformed_Plus()
nljavaingineur commented: Promply helpful +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

And what is the question? Posting your assignment is not sufficient.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Have you looked up what StringIndexOutOfBounds means, the method call that is throwing it and which line it is occurring on? The stack trace will tell you the last two of those. This is just basic debugging that you need to learn to do on your own. The exception message even tells you the index value that was out of bounds and some adding some basic System.out.println() statements can help you know the string and indexes that are causing the problem.

If you continue to have difficulties with it, post back the code, the exact exception message, and exactly what you do not understand about it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Because your method signature takes a single parameter "ActionEvent e" and you are trying to call it with no parameters. There is no method signature actionPerformed_Plus() defined.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

They are scared of terrorists, taxes and foreigners.

And gays getting married, which just blows my mind. When ranked against some of the other issues facing the nation, same-sex marriage is about as far from relevant as you can get.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The last article I saw on the algae bed stuff said it has some very interesting potential, but the volume of algae beds required for full-scale plant operation would be enormous. I think it was many acres. I'll try to find the article link again when I get a few minutes to look for it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You may also want to consider using the Scanner class with regular expressions.

And once again I'll request:
Please use [ code ] tags to format code in your posts so indentation is preserved.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This check here

if ((some_other != null) && (some_other.getClass() == getClass()))

can be done with the instanceof operator

if (some_other instanceof Item)

. The null check is unnecessary because instanceof will return false if "some_other" is null. Note that you won't be able to use instanceof with generics though (i.e. instanceof List<T>) due to type erasure, but that isn't a concern for your Item class.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The problem is that here

if(itemCount == item.length)
Doll [] temp = new Doll[item.length * 2];

you are just declaring a variable - not performing any useful operation. That variable will go out of scope immediately after it's declaration. I think what you actually want is this block

private void cpyArray()
{
    if(itemCount == item.length){
        Doll[] temp = new Doll[item.length * 2];
        
        for(int i = 0; i < item.length; i++)
            temp [i] = item[i];
        item =temp;
    }
}

(And please use [ code ] tags whenever you post code to the forums.)

Edit: Also, consider that you can use System.arraycopy() or Arrays.copyOf() to copy arrays without having to loop and copy every element.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

JComboBox is very flexible in that you can put any object you like in the model. You don't mention what you mean exactly by "link it to the database", but if you need to do something like get an ID for a selected entry, a small TypeEntry object can be used

class TypeEntry{
    private int value;
    private String label;

    public TypeEntry(int id, String label){
        this.value = id;
        this.label = label;
    }
    public int getValue(){
        return value;
    }
    public String toString(){
        return label;
    }
}

and added to the combo box model like so

rs = stmt.executeQuery("SELECT Id,Label FROM SomeTable ORDER BY Id");
while (rs.next()){
    comboBox.addItem(new TypeEntry(rs.getInt(1),rs.getString(2).trim()));
}
rs.close();

The toString() value will be shown in the combo box and any other data you need from the selected entry can be obtained from the object returned by getSelectedItem().

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Please read Details carefully before your suggestion.

Your post does sound like you want to create it in c++. Don't berate others for your own failure to write something clearly.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

People...

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, which one has no context without the other? Does a listener have any useful function without a GUI? What about the GUI? It seems to me the GUI can exist without a listener, but it just won't do much until it has one. So you could create the GUI and then create the listener passing a reference to the GUI.

On the other hand, if your listener is really a dispatcher, which it kind of appears to be, it can exist and function without anything to pass message along to - it just ends up trying to send a message to an empty list until receivers register.

Consider also that maybe you don't really need those classes to be explicit singletons. They may only ever have one instance in the context of your app, but that doesn't mean it has to be enforced by the class design. Singletons can cause a lot of headaches down the road if you aren't absolutely certain of their singularity.

darkagn commented: Good explanation :) +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

hey can u send the time table code for me?????

my mail id is <removed>

????

plz if u ???????

That is not the purpose of these forums. Do your own homework.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No, it's not a warning - it's an error. Apparently they removed the compareTo(Object) signature from the String API.

You could either cast the elementAt() to String or explicitly call toString() on it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I altered your previous example a bit. Perhaps this may help

package threadTest;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.WindowConstants;


public class ThreadStopSample extends JFrame
  implements ActionListener{
    
    ExecutorService threadPool;
    Future task;
    
    // Constructor
    public ThreadStopSample(){
        // Create a frame with a button and a text field
        GridLayout gl =new GridLayout(2,1);
        this.getContentPane().setLayout(gl);
        JButton myButton = new JButton("Start/Stop Thread");
        myButton.addActionListener(this);
        this.getContentPane().add(myButton);
        this.getContentPane().add(new JTextField());
        
        threadPool = Executors.newCachedThreadPool();
    }
    
    public void actionPerformed(ActionEvent e){
        // submit new task or cancel current one
        if (task==null){
            task = submit(new MyTestThread(this));
        } else {
            boolean cancelled = task.cancel(true);
            System.out.println("cancelled="+cancelled);
            task=null;
        }
    }
    
    /**
     * submits a task so it can be executed
     *
     *@return Future reference to the task
     */
    public Future<?> submit(Runnable task) {
        return threadPool.submit(task);
    }
    
    class MyTestThread implements Runnable {
        
        ThreadStopSample parent;
        
        /** Creates a new instance of MyTestThread */
        public MyTestThread(ThreadStopSample instance ) {
            parent = instance;
        }
        
        public void run() {
            try {
                int i=0;
                while (true){
                    Thread.sleep(10);
                    parent.setTitle("i="+i);
                    i++;
                }
            } catch (InterruptedException ie){
                parent.setTitle("canceled");
                // be sure to interrupted status
                Thread.currentThread().interrupt();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
    
    public static void main(String[] args) {
        // Create an instance of the frame
        ThreadStopSample myWindow = new ThreadStopSample();
        // Ensure that the window can be closed
        // by pressing a little cross in the corner
        myWindow.setDefaultCloseOperation(
          WindowConstants.EXIT_ON_CLOSE);
        
        // Set the frame's size ang make it visible
        myWindow.setBounds(0,0,150, 100);
        myWindow.setVisible(true);
    }    
}
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

If your thread pool executor returns a reference to a Future task, you can cancel the task via Future.cancel(true) and gracefully handle the cancellation of your Runnable via the InterruptedException handler.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, the idiom that masijade mentioned is one way to handle it. It's recommended that the boolean flag be declared volatile (i.e. volatile boolean canceled=false; ).

Another way is use thread interruption. Here's a pretty good article on that:
http://www.ibm.com/developerworks/java/library/j-jtp05236.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

That may be the case. It would depend on what "myImage" is. The default cell renderer may not be able to deal with it. Have you tried adding a few strings to the model and see if that works properly?

If you are wanting to put images in a JList, this article might help: http://www.rgagnon.com/javadetails/java-0203.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I have no much experience in Java, and especially in ListModels. So, I have many questions in my mind,
and if you would be more informative and clear in your answers, I will get the point more easily.

Firstly, I have this method in myDynamicArray class:

@Override
    public void fireContentsChanged(Object data, int  first_index, int last_index){

    }

As you can see, there is no implementaion. Is this correct?

You do not need to override that method. It is there in AbstractListModel to handle notifying the JList of the change to the model. By overriding it, you are actually removing that functionality.

Secondly, this my constructor for the Jlist:

myDynamicArray myArray = new myDynamicArray();

ListModel model = myArray ;
    JList lstImage = new JList(model);

Is it defined correctly?

It's fine, though you could just use JList lstImage = new JList(myArray); . You don't need the ListModel model = myArray ; part because myDynamicArray extends AbstractListModel, which implements ListModel.

Thirdly, here is the addMethod of myDynamicArray and this method is called when adding new object to myArray:

public void addElement(myObject data){
        // The size is sufficient
         if ( ind < length ) {
             arr[ind] = data;
             ind++;     
             fireIntervalAdded(this, 0, ind);
             this.fireContentsChanged(this, 0, ind);
         } else {
             // Increase the size of the array
             myObject [] newArr = new myObject [length + 5];
             for ( int i=0;i<length;i++){
                 newArr[i] = arr[i];
             }             
             ind = length;
             length += 5;             
             arr = newArr; 

             arr[ind] = data;
             ind++;
             fireIntervalAdded(this, 0, ind);
             this.fireContentsChanged(this, 0, ind);
         }
     }

Is there …

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You simply change whichever one you need to. If addProgram() doesn't need a parameter, then leave it as is and make sure that you don't put a string parameter in when you call it. If it does need to take a string parameter, you need to declare that parameter in the method signature

public void addProgram(String program)
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

The error is occurring because you have tried to call addProgram(), which has no parameters defined, with a string parameter i.e. addProgram("some string"). You need to either change that call to have no parameter, or change the method to take a string parameter.