Jump to content

diego

Members
  • Content Count

    21
  • Joined

  • Last visited

Community Reputation

0 Neutral

About diego

  • Rank
    Newbie
  1. Any help with this please? I've managed to get the first part done but struggling with the second?Thanks.
  2. HiI am totally new to java and have been running through a few excersises and am stuck with the wording behind this. I have the basic idea down but can't seem to get from instructions to actually implementing the code. Here's what I'm trying to do,1. Invoke the Factory static method createCRCList() to obtain the collection of CRC objects.I have 3 java files. Only two are necessary here. Both codes are listed below. I'm supposed to invoke the method from Factory.java into the GUI.java file and I'm not sure what to do. It seems like a single line of code but I'm not sure what it is or where to put it?2. Create a button with an action listener for all the objects. I've created buttons before but never linked up up with object so I'm hoping someone can give me a kinda 'blank' code for it so I can learn the method behind it. Here's the specs a. get the corresponding CRC object, b. get its name and create a new JButton labelled with that name, c. make the CRC object be the listener for the button, d. add the button to the Box, e. add a 10-pixel strut to the Box, in order to separate each button from the next.Factory.java import java.util.*;/** * Provides a static method to construct a list of CRC cards. * The class cannot be instantiated */public class Factory { /* This class cannot be instantiated */ private Factory() {} /** * Creates a list of CRC cards. * @return the list of CRC cards. */ public static List createCRCList() { List list = new ArrayList(); CRC course = new CRC("Course", "Defines the name and structure of a course.\n\n" + "Comprises one or more stages.", new ArrayList()); CRC stage = new CRC("Stage", "One stage of a course.\n\n" + "Comprises a number of modules\n\n" + "Maintains a record of students registered\n" + "on the stage of the course.", new ArrayList()); CRC module = new CRC("Module", "Defines the name of a module,\n" + "its purpose and learning outcomes.", new ArrayList()); CRC student = new CRC("Student", "Defines the name and id of a student.", new ArrayList()); CRC academic = new CRC("Academic", "Defines the name of an academic.\n\n" + "Maintains a record of personal tutees\n" + "(students).\n\n" + "Maintains a record of the modules\n" + "for which the academic is responsible.", new ArrayList()); course.getCollaborators().add(stage); stage.getCollaborators().add(module); stage.getCollaborators().add(student); academic.getCollaborators().add(student); academic.getCollaborators().add(module); list.add(course); list.add(stage); list.add(module); list.add(student); list.add(academic); return list; }} GUI.java package crc;import javax.swing.*;/** * Provides a window containing a list of buttons, one for each CRC card. * * @author Tahir Malik * @version 15/05/2009 */public class GUI { /** * Creates and displays a window containing a list of buttons, * one for each CRC card */ public GUI() { Box buttonList = Box.createVerticalBox(); buttonList.add(Box.createVerticalStrut(10)); // add your code here and remove this comment line } /** * main method */ public static void main(String[] args) { GUI gui = new GUI(); }} Thanks for your help, it may seem really easy but as a total beginner this is highly appreciated.
  3. I'm working on the sort functions, gonna be difficult but I think I can get that done. Thanks.I'm having real problems getting my head around the formulas though. Is there any other spreadsheet like feature that I can add instead of formulas. Hoping for something more advanced then what I currently have?Thanks.
  4. Thanks for your help. I've changed everything around and now using a more robust AJAX system. The theory behind everything you've posted me helped me so much! I've not got an add/remove/edit feature installed. I wanna move on to sorting the data by clicking the header and most improtantly carrying out the basic excel formulas on it so addition/substraction/etc.How would that be possible?Thanks.
  5. I've created the delete.php file below but still have the same problem of nothing happening when I press the delete button? I checked the database and all the entries are still there? <html><title>Malik's Gym</title><body background="backgrounda.PNG"><?php$con = mysql_connect("localhost","tmalik2","England");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("tmalik2", $con);$sql="DELETE FROM Malik (ID)VALUES('$_POST[id]')";if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }echo "";mysql_close($con)?><center><FORM METHOD="LINK" ACTION="http://samp.inf.brad.ac.uk:59237/MG.php"><INPUT TYPE="submit" VALUE="Return to database"></FORM></center></body></html><font color="#38ACEC"><b>New Member has been added to the database</b></font> Thanks.
  6. Thanks for the reply.I've added it in as a script, just like i did when I used the tablecloth.js file which works perfectly and I'm still getting the same problem. I can click on the delete button but nothing happens? <html><head><title>Malik's Gym</title><script src="selectuser.js"></script><link href="tablecloth/tablecloth.css" rel="stylesheet" type="text/css" media="screen" /><script type="text/javascript" src="tablecloth/tablecloth.js"></script><script type="text/javascript" src="delete_record.js"></script></head><body background="backgrounda.PNG"><h2 align="center"><b><u><font size="8" face="COMIC SANS MS" font color="#38ACEC">Malik's Gym</font></b></u></h2><form><font color="#38ACEC"><b>Search:</b></font><select name="users" onchange="showUser(this.value)"><option value="1">Tahir Malik</option><option value="2">Khalid Mahmood</option><option value="3">Amanda Murphy</option><option value="4">Pep Messoud</option><option value="5">Nabeela Din</option></select></form><p><center><div id="txtHint"><?php$con = mysql_connect('localhost', 'tmalik2', '*****');if (!$con){die('Could not connect: ' . mysql_error());}mysql_select_db("tmalik2", $con);$sql="SELECT * FROM Malik";$result = mysql_query($sql);echo "<table border='1'><tr><th>ID</th><th>Name</th><th>######</th><th>Age</th><th>Address</th><th>Post Code</th><th>Contact Number</th><th>Member Type</th></tr>";while($row = mysql_fetch_array($result)){echo "<tr>";echo '<td><a href="java script:void(0);" onclick="delete_record(' . $row['ID'] . ');">Delete</a></td>';echo "<td>" . $row['Name'] . "</td>";echo "<td>" . $row['######'] . "</td>";echo "<td>" . $row['Age'] . "</td>";echo "<td>" . $row['Address'] . "</td>";echo "<td>" . $row['Post_Code'] . "</td>";echo "<td>" . $row['Contact_Number'] . "</td>";echo "<td>" . $row['Member_Type'] . "</td>";echo "</tr>";}echo "</table>";?></div></center></p><center><FORM METHOD="LINK" ACTION="http://samp.inf.brad.ac.uk:59237/add.php"><INPUT TYPE="submit" VALUE="Add Member"></FORM></center></body></html> delete_record.js function delete_record(id){ xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return; } var url="delete.php?id=" + id; xmlHttp.onreadystatechange=function () { // check for response, delete row from html table, etc }; xmlHttp.open("GET",url,true); xmlHttp.send(null);} Not sure what's wrong because that should work really.
  7. Thanks for the reply. That was it, such a silly mistake!!Now instead of having ID's in my ID field I've got a delete button. It doesn't do anything though? I've added the function code in and get that blank screen again. I'm looking through the code and seeing if I've messed it up again but I may be placing it in the wrong place? <html><head><title>Malik's Gym</title><script src="selectuser.js"></script><link href="tablecloth/tablecloth.css" rel="stylesheet" type="text/css" media="screen" /><script type="text/javascript" src="tablecloth/tablecloth.js"></script></head><body background="backgrounda.PNG"><h2 align="center"><b><u><font size="8" face="COMIC SANS MS" font color="#38ACEC">Malik's Gym</font></b></u></h2><form><font color="#38ACEC"><b>Search:</b></font><select name="users" onchange="showUser(this.value)"><option value="1">Tahir Malik</option><option value="2">Khalid Mahmood</option><option value="3">Amanda Murphy</option><option value="4">Pep Messoud</option><option value="5">Nabeela Din</option></select></form><p><center><div id="txtHint"><?php$con = mysql_connect('localhost', 'tmalik2', '*****');if (!$con){die('Could not connect: ' . mysql_error());}mysql_select_db("tmalik2", $con);[b]function delete_record(id){ xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return; } var url="delete.php?id=" + id; xmlHttp.onreadystatechange=function () { // check for response, delete row from html table, etc }; xmlHttp.open("GET",url,true); xmlHttp.send(null);}[/b]$sql="SELECT * FROM Malik";$result = mysql_query($sql);echo "<table border='1'><tr><th>ID</th><th>Name</th><th>######</th><th>Age</th><th>Address</th><th>Post Code</th><th>Contact Number</th><th>Member Type</th></tr>";while($row = mysql_fetch_array($result)){echo "<tr>";echo '<td><a href="java script:void(0);" onclick="delete_record(' . $row['ID'] . ');">Delete</a></td>';echo "<td>" . $row['Name'] . "</td>";echo "<td>" . $row['######'] . "</td>";echo "<td>" . $row['Age'] . "</td>";echo "<td>" . $row['Address'] . "</td>";echo "<td>" . $row['Post_Code'] . "</td>";echo "<td>" . $row['Contact_Number'] . "</td>";echo "<td>" . $row['Member_Type'] . "</td>";echo "</tr>";}echo "</table>";?></div></center></p><center><FORM METHOD="LINK" ACTION="http://samp.inf.brad.ac.uk:59237/add.php"><INPUT TYPE="submit" VALUE="Add Member"></FORM></center></body></html> As always thanks for your help!
  8. I've ammended that in the code. I tried adding that to the top of my code and the screen went blank again so took it out. I'm getting the same error using this code. The screen goes blank. If I take out the following line from the code;echo "<td>"<a href="java script:void(0);" onclick="delete_record(' . $row['ID'] . ');">Delete</a>"</td>"; and revert back to the code before I added anything to do with the delete feature and it loads up like normal so it looks like the problems here. The code I'm using is below;MG.php <html><head><title>Malik's Gym</title><script src="selectuser.js"></script><link href="tablecloth/tablecloth.css" rel="stylesheet" type="text/css" media="screen" /><script type="text/javascript" src="tablecloth/tablecloth.js"></script></head><body background="backgrounda.PNG">function delete_record(id){ xmlHttp=GetXmlHttpObject(); if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return; } var url="delete.php?id=" + id; xmlHttp.onreadystatechange=function () { // check for response, delete row from html table, etc }; xmlHttp.open("GET",url,true); xmlHttp.send(null);}<h2 align="center"><b><u><font size="8" face="COMIC SANS MS" font color="#38ACEC">Malik's Gym</font></b></u></h2><form><font color="#38ACEC"><b>Search:</b></font><select name="users" onchange="showUser(this.value)"><option value="1">Tahir Malik</option><option value="2">Khalid Mahmood</option><option value="3">Amanda Murphy</option><option value="4">Pep Messoud</option><option value="5">Nabeela Din</option></select></form><p><center><div id="txtHint"><?php$con = mysql_connect('localhost', 'tmalik2', '*****');if (!$con){die('Could not connect: ' . mysql_error());}mysql_select_db("tmalik2", $con);$sql="SELECT * FROM Malik";$result = mysql_query($sql);echo "<table border='1'><tr><th>ID</th><th>Name</th><th>######</th><th>Age</th><th>Address</th><th>Post Code</th><th>Contact Number</th><th>Member Type</th></tr>";while($row = mysql_fetch_array($result)){echo "<tr>";echo "<td>"<a href="java script:void(0);" onclick="delete_record(' . $row['ID'] . ');">Delete</a>"</td>";echo "<td>" . $row['Name'] . "</td>";echo "<td>" . $row['######'] . "</td>";echo "<td>" . $row['Age'] . "</td>";echo "<td>" . $row['Address'] . "</td>";echo "<td>" . $row['Post_Code'] . "</td>";echo "<td>" . $row['Contact_Number'] . "</td>";echo "<td>" . $row['Member_Type'] . "</td>";echo "</tr>";}echo "</table>";?></div></center></p><center><FORM METHOD="LINK" ACTION="http://samp.inf.brad.ac.uk:59237/add.php"><INPUT TYPE="submit" VALUE="Add Member"></FORM></center></body></html> Thanks for your help!
  9. Here's my code; <html><head><title>Malik's Gym</title><script src="selectuser.js"></script><link href="tablecloth/tablecloth.css" rel="stylesheet" type="text/css" media="screen" /><script type="text/javascript" src="tablecloth/tablecloth.js"></script></head><body background="backgrounda.PNG"><h2 align="center"><b><u><font size="8" face="COMIC SANS MS" font color="#38ACEC">Malik's Gym</font></b></u></h2><form><font color="#38ACEC"><b>Search:</b></font><select name="users" onchange="showUser(this.value)"><option value="1">Tahir Malik</option><option value="2">Khalid Mahmood</option><option value="3">Amanda Murphy</option><option value="4">Pep Messoud</option><option value="5">Nabeela Din</option></select></form><p><center><div id="txtHint"><?php$con = mysql_connect('localhost', 'tmalik2', '*****');if (!$con){die('Could not connect: ' . mysql_error());}mysql_select_db("tmalik2", $con);$sql="SELECT * FROM Malik";$result = mysql_query($sql);echo <table><tr><th>ID</th><th>Name</th><th>######</th><th>Age</th><th>Address</th><th>Post Code</th><th>Contact Number</th><th>Member Type</th></tr>";while($row = mysql_fetch_array($result)){echo "<tr>";echo "<td>" . <a href="java script:void(0);" onclick="delete_record(' . $row['ID']. ');">Delete</a></td>';echo "<td>" . <a href="java script:void(0);" onclick="delete_record(' . $row['Name']. ');">Delete</a></td>';;echo "<td>" . <a href="java script:void(0);" onclick="delete_record(' . $row['######']. ');">Delete</a></td>';echo "<td>" . <a href="java script:void(0);" onclick="delete_record(' . $row['Age']. ');">Delete</a></td>';echo "<td>" . <a href="java script:void(0);" onclick="delete_record(' . $row['Address']. ');">Delete</a></td>';echo "<td>" . <a href="java script:void(0);" onclick="delete_record(' . $row['Post_Code']. ');">Delete</a></td>';echo "<td>" . <a href="java script:void(0);" onclick="delete_record(' . $row['Contact_Number']. ');">Delete</a></td>';echo "<td>" . <a href="java script:void(0);" onclick="delete_record(' . $row['Member_Type']. ');">Delete</a></td>';echo "</tr>";}echo "</table>";?></div></center></p><center><FORM METHOD="LINK" ACTION="http://samp.inf.brad.ac.uk:59237/add.php"><INPUT TYPE="submit" VALUE="Add Member"></FORM></center></body></html> From what I can see there's no 'delete_record' to call so is that why nothing is showing up? The screen is blank when I load it up. It's a .php file. Am I right in thinking I'll have to create a delete_record.js file that carries out the deleting? I have very little knowledge in this so is there a script I can get or an example bit of code? If this isn't the problem what is?Thanks for your help!!
  10. Isn't that the same thing? It looks like the code on the page you linked to is using checkboxes to identify which rows to delete. Another common way is to print a delete link for each row then you just click the link for the row you want to delete. All you need to tell PHP is the ID of the row you want to delete, so you'll need a way to save the ID. For a regular link, you would just put the ID in the link:<a href="delete.php?id=10">I meant a specific entry not row so like the one listed above. Main reason I didn't wanna do this is because after I've added an entry the database updates straight away and when I return to the page the new entry will be there but I don't think there's a way for a whole new delete button to be created for the new entry to appear automatically as you add records? My javascript knowledge is very basic so I hope I'm getting this right. the javascript function delete_record should be created in a seperate JS file but what would that file entail?Then I would create a php page just like the add function and create the above delete feature next to each entry and have that linked up so it would remove entries from the database and the html table?Also, would this above have a new delete button create for new entries added after I finish coding? If not how do I go about this?Thank you so much for the help, without your input I wouldn't be getting anywhere here!!EDIT:I've been trying to create a sort function for the table but I can't seem to get it working at all. I've ran through like 4-5 test tables and they all work fine with the test data but in my table I can't seem to do it. The code from the table is as follows; Now each sort function that I used (js files) needed me to add the script in the head and add something in the bolded area above. As soon as I add anything into that area my screen shows up blank. What am I doing wrong?
  11. Hi again,I used the POST variable and created an add button so that aspect of the database is working fine. The problem I'm having now is creating a delete feature. At the moment its just a html table with an add button at the bottom. What I want is something like the following;http://viralpatel.net/blogs/2009/03/dynami...javascript.htmlI've tried adapting the code there to fit my coding but can't seem to do it. What would be the best way to go about doing such a thing and are there any tutorials that I can follow?I know how to create a delete button that will delete a specific row, need one that deletes a row that the user chooses to on the HTML page.Thanks for any help!
  12. Yep, that was the problem. Works fine now. Now I've just got to make this table as spreadsheet like as possible. Thanks for all your help so far, I'm going to move onto looking at the stuff you told me about and hopefully if I run into some problems I can get some help here.Thanks again!
  13. Thanks for the help. I used the code you provided and edited it to match my system but I get the following error? Here's the code;<html><head><title>Malik's Gym</title><script src="selectuser.js"></script></head><body background="background.PNG"><h2 align="center"><b><u><font size="8" face="Georgia, Arial" font color="blue">Malik's Gym</font></b></u></h2><form> <font color="blue"><b>Search:</b></font><select name="users" onchange="showUser(this.value)"><option value="1">Tahir Malik</option><option value="2">Khalid Mahmood</option><option value="3">Amanda Murphy</option><option value="4">Pep Messoud</option><option value="5">Nabeela Din</option></select></form><p><center><div id="txtHint"><?php$con = mysql_connect('localhost', 'tmalik2', 'England');if (!$con){die('Could not connect: ' . mysql_error());}mysql_select_db("tmalik2", $con);$sql="SELECT * FROM Malik";$result = mysql_query($sql);echo "<table border='1'><tr><th>Name</th><th>######</th><th>Age</th><th>Address</th><th>Post Code</th><th>Contact Number</th><th>Member Type</th></tr>";while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['Name'] . "</td>"; echo "<td>" . $row['######'] . "</td>"; echo "<td>" . $row['Age'] . "</td>"; echo "<td>" . $row['Address'] . "</td>"; echo "<td>" . $row['Post_Code'] . "</td>"; echo "<td>" . $row['Contact_Number'] . "</td>"; echo "<td>" . $row['Member_Type'] . "</td>"; echo "</tr>"; }echo "</table>";?></div></center></p></body></html> The error quoted above just appears where the phrase "user info will appear" used to be. I've tried out the code as it's own file and it works fine. I've tried a few other ways using w3school tutorials to show the table and when I add the table as a seperate php file it works fine but when I try adding it the way you've put it in the error quoted above always appears. Any ideas? Thanks/ I'll get cracking on that straight away.
  14. Where would you suggest putting the code in? I tried replacing the code I've gotten with the new one and nothing showed up. Is there a way I can get the full table to show up instead of the "user info will be listed here". My full code is at the bottom of the post. How about a feature to add an entry through the HTML page that will update the database? And similarly remove the data? Is there a tutotiral or something for that? Thanks.<?phperror_reporting(E_ALL);ini_set('error_log', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'error.log');ini_set('html_errors', 0);ini_set('log_errors', 1);ini_set('display_errors', 0);$q=$_GET["q"];$con = mysql_connect('localhost', 'tmalik2', '*****');if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("tmalik2", $con);$sql="SELECT * FROM Malik WHERE id = '".$q."'";$result = mysql_query($sql);echo "<table border='1'><tr><th>Firstname</th><th>Lastname</th><th>Age</th><th>Hometown</th><th>Job</th></tr>";while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['FirstName'] . "</td>"; echo "<td>" . $row['LastName'] . "</td>"; echo "<td>" . $row['Age'] . "</td>"; echo "<td>" . $row['Hometown'] . "</td>"; echo "<td>" . $row['Job'] . "</td>"; echo "</tr>"; }echo "</table>";mysql_close($con);?> var xmlHttpfunction showHint(str){if (str.length==0) { document.getElementById("txtHint").innerHTML=""; return; }xmlHttp=GetXmlHttpObject();if (xmlHttp==null) { alert ("Your browser does not support AJAX!"); return; } var url="gethint.php";url=url+"?q="+str;url=url+"&sid="+Math.random();xmlHttp.onreadystatechange=stateChanged;xmlHttp.open("GET",url,true);xmlHttp.send(null);} function stateChanged() { if (xmlHttp.readyState==4){ document.getElementById("txtHint").innerHTML=xmlHttp.responseText;}}function GetXmlHttpObject(){var xmlHttp=null;try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); }catch (e) { // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } }return xmlHttp;} <html><head><title>Malik's Gym</title><script src="selectuser.js"></script></head><body background="background.PNG"><h2 align="center"><b><u><font size="8" face="Georgia, Arial" font color="blue">Malik's Gym</font></b></u></h2><form> <font color="blue"><b>Search:</b></font><select name="users" onchange="showUser(this.value)"><option value="1">Peter Griffin</option><option value="2">Lois Griffin</option><option value="3">Glenn Quagmire</option><option value="4">Joseph Swanson</option></select></form><p><center><div id="txtHint"><b>User info will be listed here.</b></div></center></p></body></html> Thanks for any help!
  15. You can just have a PHP script to output the records in the database, it doesn't need to come through AJAX. The PHP script right now is producing partial HTML, you can change it to produce the entire page.Thanks for the reply. I now understand the theory behind this as in change it so instead of bringing about the single entry I can bring them all. What I'm not sure is how to go about that. Currently I'm using the ID to bring a seperate entry but there isn't anything in the table that I could bring every entry up? What kind of code will be needed for this? What I'm hoping to achieve is have the page load up with all the entries at the start and then I can go through the drop down box to limit the search. I've been reading through a load of tutorials all day and I can't seem to get my head around it at all. I think it may be to complex for someone with as little knowledge of coding. Is there any simpler tutorials out there for just creating an editble HTML table?Thanks for your help, it is really appreciated!
×
×
  • Create New...