darkagn 315 Veteran Poster Featured Poster

Hi all,

I am trying to make a simple game of Craps in Java. My idea was to have a JFrame with an image of the Craps betting table as the background image and when the player clicks on a section of the table they can place or remove a bet on that part of the table.

My question is, when the user clicks, what is the best way to determine what part of the image has been clicked? Obviously I need a MouseListener to determine where in the JFrame the click has occurred, but how can I transfer this to the position on the image? I am not looking for code, just a plan of attack really, so any thoughts would be appreciated.

Thanks in advance for any help on this,
darkagn :)

darkagn 315 Veteran Poster Featured Poster

Hi Steph,

The Oracle forum can be found here:
http://www.daniweb.com/forums/forum129.html

The people that frequent that forum might not necessarily come to the CS one, so might be worthwhile reposting your question there if you still need help.

Regards,
d

darkagn 315 Veteran Poster Featured Poster

You can pass variables to the $_GET array in the action part of your form tag by changing the url to "bar.php?size=....". This will pass the parameter size to the $_GET array, accessed in your php code by $_GET["size"] . In a PHP url, anything after the .php? are variables for the $_GET array, separated by the ampersand (&) character. So a url that looks like this:
foo.php?size=1&name=Mike&goal=study&command=download
loads the page foo.bar with the $_GET having the following variables:

$_GET['size'] = 1;
$_GET['name'] = 'Mike';
$_GET['goal'] = 'study';
$_GET['command'] = 'download';

I should point out that while there is no limit to what you can pass to the $_GET array, it is visible in the browser url, so should never be used to pass sensitive information such as passwords to the browser.

I will leave it up to you to figure out what size should be set to based on what radio button is selected. A google search should be able to point you in the right direction.

HTH,
d :)

darkagn 315 Veteran Poster Featured Poster

Ok, so you will need three HTML <select> tags and an <input type='submit'> tag placed inside a <form> tag in your HTML page. In your PHP, you can use the $_POST array to retrieve posted data like so:

if( isset( $_POST[ "first_select" ]))
{
  $first_selection = $_POST[ "first_select" ];
  // assuming the name of your first <select> tag is "first_select"
}
else
{
  $first_select = false;
  // or some other default value
}

You will probably need to validate the data that has been posted, regular expressions are often useful for this purpose.

Have a go and if you have any more questions please don't hesitate to ask. :)

Good luck,
d

darkagn 315 Veteran Poster Featured Poster

Assuming the primary key is stored in a PHP variable, $key, then you can build your SQL query using double quotes:

$sql = "SELECT * FROM table1 WHERE ( SELECT COUNT(*) FROM table2 WHERE fbid = $key) > 150";
// run the query by passing $sql to your query handler
darkagn 315 Veteran Poster Featured Poster

A goto control structure? That is taking us back to the dim dark past... :P

In all seriousness, if php was heading toward object oriented development, I can't think why a goto would be needed. Is it going to be like the old days, ie goto line 2376? I think that would be particularly dangerous for a number of reasons. Or will it be used in a different way?

darkagn 315 Veteran Poster Featured Poster

No that shouldn't cause such a problem, just remember the rules when working with files:

1. Only give users access to files that you want them to have access to. Use permissions to restrict read/write/execute on files. I would suggest making sure that users can only read your location file except in very rare circumstances, and never let them delete it.
and 2. Don't forget to close the file handle when you are finished with it. Bad things happen when you don't clean up after yourself.

darkagn 315 Veteran Poster Featured Poster

I'll send it to you for $45000. Let the bidding begin :P

darkagn 315 Veteran Poster Featured Poster

I would use

DECIMAL(10,3)

This is a number with a total of 10 digits, up to 3 of which can be stored after the decimal. Adjust the 10 as needed, it is the default number used in the DECIMAL type in MySQL.

darkagn 315 Veteran Poster Featured Poster

You might want to invest in a third party WYSIWYG editor. There are lots out there, Google or another search engine might be a good place to start...

darkagn 315 Veteran Poster Featured Poster

Hint: Start at the bottom and work your way backwards.

darkagn 315 Veteran Poster Featured Poster

Oh yes, I forgot that StringTokenizer had been discouraged from use. I didn't realise that Java had a String.split method too, so thanks for the tip stephen84 :)

darkagn 315 Veteran Poster Featured Poster

This sounds like sorting an array rather than a queue. As you said, queues work on the FIFO format, so you can't sort a queue since you will lose track of which one should be removed next. Are you sure this is what your task requires?

darkagn 315 Veteran Poster Featured Poster

Yes, but you need to manipulate the string yourself. You will need to use a StringTokenizer to break the String up, and the Integer.parseInt method to work out the numbers (assuming floats and doubles are invalid). Have a go and see what you come up with, post back with your code if you need more help.

darkagn 315 Veteran Poster Featured Poster

Your question is not very specific. If you want to know how to create a String in Java, you do it like this:

String aString = "blah";

The String with name aString now contains the letters blah.

darkagn 315 Veteran Poster Featured Poster

What are you trying to achieve by making your JFrame undecorated? If you wish to remove the user's ability to resize the window, you can use the setResizable() method to stop them from doing this (which you have done). If you want to stop the user from closing the window, you can use the setDefaultCloseOperation() method to set the window to DO_NOTHING_ON_CLOSE. If you really want to remove the border, then I don't think you will be able to move the window, at least without some serious manipulation of the look and feel of your window.

darkagn 315 Veteran Poster Featured Poster

Hi ilokana and welcome to DaniWeb :)

I'm not sure exactly what you are trying to do here? Do you want to create a drop-down box that when the user selects an option it automatically redirects them to a selected link? Why do you not want a Submit button?

Regards,
darkagn

darkagn 315 Veteran Poster Featured Poster

Hi all,

I am currently writing a spell checker that needs to suggest corrections for a mis-spelled Suburb/Locality in a Post Code/Zip Code lookup site. All of the suburb names are stored in a database in the Postcodes table and I was wondering if I could use the Pspell library to do the spell check / suggestion based upon the entries in that table? From the examples I have seen, the library makes use of a dictionary file to compare words to, can it be used to compare to a result set from a database?

Any suggestions would be appreciated. :)

Thanks in advance,
darkagn

darkagn 315 Veteran Poster Featured Poster

Using your example, the following query should work:

-- get the required columns using aliases where necessary
SELECT e.id AS entry_id, sf.id AS sections_fields_id, sf.name AS value
-- from the entries table
FROM entries e
-- join to the section_fields table
JOIN sections_fields sf
-- describe how to join tables
ON e.section_id = sf.section_id
-- limit the returned results according to criteria?
WHERE e.id = 1 AND sf.id = 1

HTH :)

darkagn 315 Veteran Poster Featured Poster

The line

for(int i =0; i>15;i++)

is incorrect. It says, start at i=0, and while i>15 do the following code and add one to i. If i starts at 0 it is never greater than 15, so the code will never execute.

You have a similar error with the line

for(int j=0;j>10;j++)
darkagn 315 Veteran Poster Featured Poster

I'm sorry Aamit, but I am not sure what you are trying to achieve here. Do you want to add a column, change_id, to your table and have the existing rows have an auto-incrementing number assigned to the value in this column based on youngest to oldest? If that is the case, what will this field be used for?

darkagn 315 Veteran Poster Featured Poster

Something like this should work:

-- set where to insert
INSERT INTO Table_one (First_Name) 
-- select values to insert
SELECT Name FROM Table_Two
-- you may need to specify which ones from Table_two to insert
-- using a WHERE clause

HTH :)

darkagn 315 Veteran Poster Featured Poster

Hi AsinuS and welcome to DaniWeb :)

Can you post the query you are using to insert the xml? Also table information might help us to solve your problem too.

We'll start there (at the most basic possible problem) and work our way out...

darkagn 315 Veteran Poster Featured Poster

I would do something like this:

if ( is_set( $_POST[ "newName" ]))
{
  $displayName = $_POST[ "newName" ];
  // add quotes here
  $displayName = "'$displayName'";
} // otherwise $displayName is not set ie is NULL

//  ...
//UPDATE OLD MESSAGE
// don't insert quotes in $displayName here
// because it is either NULL or a string with quotes already
$query = " UPDATE messages SET NAME = $displayName, MESSAGE = '$displayMessage' WHERE ID = '$displayID'";
$result = mysql_query($query);

Please note that I haven't tested this code, but I think it *should* work ;)

darkagn 315 Veteran Poster Featured Poster

Can you post your query?

darkagn 315 Veteran Poster Featured Poster

This code will create a string called $msgbody, but what do you do with it to try to add it to an email?

darkagn 315 Veteran Poster Featured Poster

Your first line

$msbody = ;

doesn't do anything. What you want is this:

$msgbody = "Referred by = " . $referredby;
$msbody .= "<br>";
$msbody .= "Your Full Name = " . $fromname; 
// etc
darkagn 315 Veteran Poster Featured Poster

Really your question has many different answers depending on the individual. Personally I prefer Eclipse, but NetBeans is very popular. I used to use jEdit and I always liked it, but it wasn't a true IDE, just a text editor with a few plugins for java development.

darkagn 315 Veteran Poster Featured Poster

I think StringBuffer might be the other String__ class you were referring to. Both the StringBuilder and StringBuffer class are better at concatenation than the base String class. StringBuilder will out-perform StringBuffer (although both are highly efficient at concatenation) but note that StringBuilder does not guarantee synchronisation, meaning that you should only use it if it is being accessed by a single Thread. Multi-Threaded applications need to use StringBuffer, or control the synchronisation themselves.

darkagn 315 Veteran Poster Featured Poster

You can use a JOIN to do this. You need to select the rows from each table, then describe how rows are related. Such a query will look something like this:

-- select rows
select Products.ProductID, Products.Description, Products.Value, StockOnHand.QtyInStock
-- from each joined table
from Products
join StockOnHand
-- describe how rows are related
on Products.ProductID = StockOnHand.ProductID
-- limit the results according to selection criteria
where Products.Value > 10.00
-- set order
order by StockOnHand.QtyInStock
-- set grouping
group by Products.Description

This is just an example to show you the syntax, have a try with your particular tables and columns and see what you can come up with. :)

darkagn 315 Veteran Poster Featured Poster

The COUNT function will return the number of rows returned by the query which is what I think you are trying to do. The COUNT function requires a column to count as a parameter, so your query will look something like this:

select COUNT(name) as number_sold
from beats
where availability = 'Sold'
and p_staffid = 1;
CodeBoy101 commented: Exactly what I needed. +0
darkagn 315 Veteran Poster Featured Poster

As an aside, if you want to limit people to only use one instance of your class in an application, you can do something like this:

public class myClass {

  private static myClass instance = null;

  private myClass()
  {
    // do something when creating the instance
  }

  public static myClass getInstance()
  {
    if( instance == null )
    {
      instance = new myClass();
    }
    return instance;
  }
}

The Runtime class does something similar in order to limit the number of instances of Runtime objects to one.

darkagn 315 Veteran Poster Featured Poster

You need to use the static getRuntime() method in order to instantiate the Runtime object.

darkagn 315 Veteran Poster Featured Poster

Hi zoroman,

Sorry but we aren't allowed to just do your homework for you. Perhaps you could show us what you've tried or discuss how you think the problem should be tackled. We would love to help, but we need to see some effort first.

darkagn 315 Veteran Poster Featured Poster

Take a look at the Runtime class. You can use its exec method to run a ping and the resulting Process has methods to allow you to obtain the I/O/E streams. This allows you to interpret the results of your ping, but note that there are differences in the ping implementation in Windows and Linux (not sure about Cisco OS sorry).

Hope this gives you some direction,
darkagn

darkagn 315 Veteran Poster Featured Poster

I would have another table, related_wigets, with the following structure:

widgetid (number, PK, FK)
related_widgetid (number, PK, FK)

When someone wants to relate widget with widgetid = 1 to widget with widgetid = 2, do an insert like so:

insert into related_widgets (widgetid, related_widgetid) 
values (1, 2)

When you want a full list of which widgets are related to widget with widgetid = 3, the following query will give you a complete list:

select *  from related_widgets 
where widgetid = 3 or related_widgetid = 3

Hope this helps,
darkagn

darkagn 315 Veteran Poster Featured Poster

I think this may be to do with permissions on the folder. Your permissions are not the same as php's permissions. The fix depends on what server you are using, but in a Linux server you can use a chmod command on the directory to change the permissions. You need write access for the Other group of permissions (the second-last bit). Use the command

chmod 766

to assign full access to the directory's owner, read/write access to the owner's group and read/write access to other users (which includes php/www).

I'm not sure about a windows server sorry, maybe someone else can help if you are using a windows server.

darkagn 315 Veteran Poster Featured Poster

Yes, except that you don't have to define the code for Reptile::eat() because it is in the Animal class. If you wanted to change the way that the Reptile eats from the way that the Animal eats then you would need to redefine it. And of course you can use a call to parent::eat() like you can with any extending class if you want to extend the eat() method rather than simply overriding it.

All of this adds up to the fact that you can minimise the amount of code and simplify the code maintenance by using an abstract base class in a package of similar classes.

Venom Rush commented: Thanks, you really helped ;) +2
darkagn 315 Veteran Poster Featured Poster

The idea behind an abstract class is that you can define some common functionality of a set of similar classes, but leave other details up to the implementing (extending) classes. In a way they are similar to interfaces, except that you can actually implement some of the functions in the abstract class.

But what's the point, I hear you ask? Well, you only have to write the common code once, although you can do this in a concrete (non-abstract) base class too. But also you may not want other programmers to instantiate the base class, so this is where the real power of abstract classes come in.

Let me show an example to help illustrate my point. Imagine you are writing a program to classify all of the animals in a zoo. Animals can be classified into certain types, bird, reptile, mammal, insect, arachnid, fish, etc, and then down to their species such as dog, cat, parrot or kangaroo. The base class, Animal, can provide some of the common functionality to all of these. It might have a function called eat() which all animals do in a similar way and so the function is written out to describe the process of an animal eating. It might contain another function, walk(), but this one is abstract, since different animals will implement this in a different way. All subclasses of the Animal class will need to implement this method.

The major bonus of this is that somewhere in your …

darkagn 315 Veteran Poster Featured Poster

Should zipCode belong to the Individual class or the IndividualArray class? I think it is a value relating to the Individual, not the list of Individuals.

darkagn 315 Veteran Poster Featured Poster
$insertSQL = sprintf("INSERT INTO Bday (`Date`) VALUES ('%s')", 
                     GetSQLValueString($_POST['Date2'], "date"));

Note the single quotes around the %s. I think this should fix your problem.

darkagn 315 Veteran Poster Featured Poster

No 1 should be fairly straight forward using the $_GET array. You can set a variable in their response in the Insert screen, and retrieve it in the Update screen if it is set. (see the isset() function in the PHP doco for examples on how to do this). The PHP doco can be found at http://php.net/manual/en/index.php

No 2 sounds like you aren't logging out properly. Can you post your Login and Logout functions for us to look at?

darkagn 315 Veteran Poster Featured Poster

The problem here is that you can't see the fName parameter from the toString() method. This is because fName belongs to the Individual class, not the IndividualArray class. I think that you should remove lines 33-35 since you are outputting your list of Individuals one by one after that anyway.

darkagn 315 Veteran Poster Featured Poster

In MySQL, you need to enter a date in the format "YYYY-MM-DD", so with your three variables you can make the date string in that format using the date and mktime functions. Something like this should work:

// date needs format and timestamp
// mktime needs hours, minutes, seconds, month, day, year
$date = date( 'Y-m-d', mktime( 12, 0, 0, $month, $day, $year ));

Then you use the $date string that you have created to insert into the DATE field in your database.

darkagn 315 Veteran Poster Featured Poster

I think you would find it easier to read the input into a String and use the charAt() method to read each char in the String.

darkagn 315 Veteran Poster Featured Poster

Hi theausum,

Two things:

Firstly, please use code tags when posting code. It really does make it a lot easier to read.
Secondly, did you have a question?

darkagn 315 Veteran Poster Featured Poster

Oops, of course you are correct SOS. Sorry for the blunder, wasn't thinking! :$

darkagn 315 Veteran Poster Featured Poster

You are using the value "X" in the .equals(Object) method which expects an Object as a parameter. It would be better if you declared your "X" as a constant String or char and compared the variable mark to that instead.

darkagn 315 Veteran Poster Featured Poster

Are you sure about that? I thought it just added the value of the separate characters for each String, then compared those values. Which would not put them in alphabetical order. I'm not saying you're wrong, just curious.

No, the compareToIgnoreCase method's documentation in the API states that it compares the two strings "lexicographically", meaning that they are compared according to where they would be placed in a dictionary. The documentation also states that locales are ignored, but I'm not entirely sure what they mean by that, perhaps accented characters as seen in French or the umlaut in German are not considered?

darkagn 315 Veteran Poster Featured Poster

The String method compareToIgnoreCase should do the trick. For example:

int result = string1.compareToIgnoreCase(string2);
// here result < 0 if string1 > string2
// or result = 0 if string1 == string2
// or result > 0 if string1 < string2

That should give you a start anyway. Have a go and see what you can come up with.