Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, you would initialize based on the number of rows.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Re-read that for() line. You have two unnecessary characters in it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

So post your code and actually ask a question. This isn't a homework completion service and no one is going to write detailed instructions on how to complete this.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Re-reading your post: Do you mean that the error is getting past your catch? I may have misunderstood you with the previous comment.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

> However, it doesn't work - the error message is generated for the empty set.

I assume you meant the error is not generated. An empty result doesn't throw an exception because it's a completely valid result - there simply are no records that match the query.

If your code needs to know that, you could either throw your own exception from the setQuery() method when the result is empty, or you could return a value from that method. It could return an int count of the records found or boolean to indicate at least one record was returned from that method.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Closing this thread since the poster has not returned in a month to clarify what he needs help with and this is not the place to solicit business offers.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You could code a static method for it in a utility class

public class Functions{
  public static float f(float x){
    return x*x*x+6*x;
  }
}

Anything you do is going to be a method call. You don't need to create any references to use the above, but then again you give up other flexibility with that.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can use those methods to set your component locations if you set your layout to null. If you move the component, you won't need to use the graphics methods.

If you want to use the graphics methods instead, you could make a small banner component that paints the moving text across the black background and use setFont() and setColor() to stylize the text.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

getString() returns the value of the column in the current row of the result set. This means that you already have a reference to the row or its location, so it is simply a matter of returning the value of the column as a String. Your iteration or access methods will need to maintain that reference to the current row.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

I think all of it was accumulated in the days where rep counted in the lounge as well.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Then you can implement it however you choose as long as it conforms to the documented behavior of the interface.

If you do not understand interface implementation, I don't see how you are going to be able to write your own JDBC driver.

Are you sure you aren't confusing "implementing an interface" with "using an interface"?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

He seems to be using this example code, which defines a "pickRand" class with a single method to get a random string from the array

class pickRand {
    public static String get (String[] array) {
        int rnd = generator.nextInt(array.length);
        return array[rnd];
    }
}

and he may have missed the part that says you have to create an instance of Random in your class

Random generator = new Random();

though there is no reason the author couldn't have just defined that 'generator' statically within his class.

There isn't even much reason to even make that a separate class for that - he could have just made it a method or in-lined the generator.nextInt() call with the array access.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You already have a section where you are updating the maxScore. You can update more than one thing in that if() block if you add some braces (which you should always use anyway).

You don't need to grab a previous string - you just need a new variable to hold the max score player name.

soccer13 commented: Helped me through all problems in my program +1
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Update a variable 'maxScorePlayer' whenever you update the 'maxScore' variable.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Are you writing a JDBC driver? If not, they you don't need to implement that interface. You use it to work with the results returned from a query.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Take a look at Reading From And Writing To A Socket with particular attention to the loop they use to read.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

> Where a new Contact gets created called con001. Wouldn't this then just create a new con001 contact over and over again? Isn't there some way to make the next contact object be called con002, then con003 etc?

Add them to an ArrayList as you create them. You don't need variables for each one.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It should only add the numbers in the line that you have passed it for that player. You will need to reset total to 0 between players.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No, you would need to use a JTextPane or JEditorPane for rich text like that. JTextArea only has a single style for the text.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Perhaps using while(parser.hasNextInt()) and parser.nextInt() .

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You haven't asked a question.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No, setHorizontalScrollBarPolicy() is a JScrollPane method, but your option pane doesn't have one.

You could wrap a customized JDialog pretty easily like this

import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class ScrollableDialog{
    JDialog dialog;
    JTextArea textArea;
    int dialogResult = JOptionPane.CANCEL_OPTION;
    
    public ScrollableDialog(Frame owner, String text){
        // create a modal dialog that will block until hidden
        dialog = new JDialog(owner, true);

        dialog.setLayout(new BorderLayout());

        textArea = new JTextArea(text);
        textArea.setLineWrap(true);
        
        JScrollPane scrollpane = new JScrollPane(textArea);

        dialog.add(scrollpane,BorderLayout.CENTER);
        
        JButton btnOk = new JButton("Ok");
        btnOk.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                // This will "close" the modal dialog and allow program
                // execution to continue.
                dialogResult = JOptionPane.OK_OPTION;
                dialog.setVisible(false);
                dialog.dispose();
            }
        });
        dialog.add(btnOk,BorderLayout.SOUTH);
        
        dialog.setSize(200,200);
    }
    
    public int showMessage(){
        // show the dialog - this will block until setVisible(false) occurs
        dialog.setVisible(true);
        // return whatever data is required
        return dialogResult;
    }
    
    public static void main(String[] args) {
        String bigText = "When in the Course of human events, " +
                "it becomes necessary for one people" +
                " to dissolve the political bands which have " +
                "connected them with another, and to" +
                " assume among the powers of the earth, the " +
                "separate and equal station to which " +
                "the Laws of Nature and of Nature's God entitle" +
                " them, a decent respect to the " +
                "opinions of mankind requires that they should" +
                " declare the causes which impel them" +
                " to the separation.";

        ScrollableDialog dialog …
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

No, you would need to implement your own custom dialog for that.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You've made quite a bit of progress with it. I would recommend one slight design modification that may help. I would move the run(Heat) method into the Heat class and put getWinners(int n) there as well, returning the top n Runners from the Heat.

Your Round class then just manages a collection of Heats. After you have run the Heats, you can select the winners from them however you wish and use those to create a new Round from those results.

Perhaps creating a Round constructor that accepted a List of Runners would be helpful. Your Round class can divide them into Heats however it wants, such as by last race time.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Take a look at the Space Invaders tutorial there. It is a 2D sprite game.

NewOrder commented: thanks EZZral +0
Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

This site has a few good tutorials: http://www.cokeandcode.com/

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

> I find some of the coding and syntax little intimidating, up until now I've just been clicking at Access buttons

You can certainly still use Access for the database. The table creation code translates pretty easily to your table creation wizard or design view. The SQL queries may require a bit more effort to translate, but the query designers in Access can be helpful when you're just getting started.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

My point was that you mis-wrote your function trace value sec2(1-1) + 2 * 1 - 1 is 1 + 2 * 1 - 1 which equals 2, not 1.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

See my previous post, which I think you may have cross-posted with.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Use WHERE lost_time is NULL instead of = NULL Sorry, I should have changed that when I copied your previous code to alter it.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

> which is 0 + 2*1 -1
No. It is 1 + 2*1 - 1 => 2

seq2(0) returns 1, not 0.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Can you post your getValueAt() code?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

In the comments on UPDATE, one guy mentions using the following work-around

UPDATE  abm_downtime set
lost_time = now()
where lost_time = null
order by ID desc limit 1

You could give that a try I suppose.

I'm assuming you aren't actually using now() for lost_time, right?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Yes, I found this buried in the manual

Currently, you cannot update a table and select from the same table in a subquery.

Very inconvenient.

Can you select the ID in a separate statement and then run your update?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can't sub-select from the table you are updating? Did you check your parenthesis to make sure it didn't just parse it incorrectly?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Perhaps something like

update yourTable set time_lost=theValue where ID=(select max(ID) from yourTable) and time_lost is null

I don't work with MySQL specifically so there may be a slight syntax variation.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You are probably right, but if he posted the exception and stack trace, people wouldn't have to guess nor trace his code and he may have gotten it sorted out much quicker.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Change your println statement to e.printStackTrace(); and it will tell you which line the error is occurring on.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

It also indicates which line that is occurring on. Look at that line and note which variables you are making method calls on. One of them is null and you need to figure out why it doesn't have a value.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Did you make any changes in your getColumnClass() method? What prompted the class cast exception?

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You might try changing this part of your model creation code

while (rs.next()) {
        Object[] record = new Object[colCount];
        for (int i = 0; i < colCount; i++) {
          record[i] = rs.getObject(i + 1);
        }
        cache.addElement(record);
      }

I'm not certain if you have an actual boolean coming from your rs.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You cannot simply make getColumnClass() return Boolean.class for that column because your data is a String value of "1" or "0". You need to store those values as booleans in your table model.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Hit "Edit", select all that code and click the "[code]" button to place it in code tags. Also state your question.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Post your code in code tags. Post specific questions or error messages.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You cannot understand how to use that method to append text to your JTextArea?? Are you kidding? What part of that is confusing? Perhaps we aren't understanding just what you're wanting to do.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Well, it looks like all of your columns are currently String, because you have built them from the ResultSet using Strings for every value.

You could change the method that builds your table model to read the data type from the metadata and create an object of the appropriate type as you fill in the data. You also would need to change your 'record' array to Object[] instead of String[].

Using rs.getObject() instead of getString() might be viable as well, but if you are using 0 and 1 to represent your boolean values, they will most likely be read as Char or Integer and the default renderer will not be a check box.

As you can see, the tricky part is to keep your QueryTableModel as generic as possible and still translate those columns to the desired data type. If you hard-code the Boolean column in a particular location, you've tied your model to a specific data set - which is not necessarily a problem, but it will obviously limit it's re-use.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Based on the minimal information that you provided, I guess you can start here: http://download.oracle.com/javase/tutorial/2d/index.html

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You probably need that method to return a Boolean object for the check box renderer.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

You can either explicitly return the class for that column, or you can make sure that getValueAt() always returns a value for that column. I assume it's a boolean for the checkbox, so it needs to return true or false instead of a null.

Ezzaral 2,714 Posting Sage Team Colleague Featured Poster

Set a color, however you want, then draw the shape. You can set a new color and draw another shape if you wish. The code you posted just draws one shape - there is no second ball.

You really should use a small class for the ball that contains it's coordinates and color. Store them in a List and loop through that list when you need to draw them.