Help with code please, it wont run
Hi all can anyone tell me why this wont run please, thanks
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class SwingApplication extends JFrame
public SwingApplication()
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocation(300,200);
setSize(700,600);
JButton answerButton = new JButton("Answer");
JButton submit = new JButton("Submit");
JButton button = new JButton("Next Question");
JButton NextRecord = new JButton("Next Record");
JTextField answerText = new JTextField("");
JTextArea QuestionArea = new JTextArea("QuestionArea");
JPanel pane = new JPanel();
JLabel label1 = new JLabel ("Answer the following question");
JLabel mouseLabel = new JLabel();
JLabel lblpic1 = new JLabel();
lblpic1.setIcon(new ImageIcon("couple.jpg") );
submit.setToolTipText("Click to get solution");
pane.add(label1);
pane.add(button);
pane.add(answerText);
pane.add(answerButton);
pane.add(submit);
pane.add(NextRecord);
getContentPane().add(pane,BorderLayout.SOUTH);
getContentPane().add(label1,BorderLayout.NORTH);
getContentPane().add(lblpic1,BorderLayout.CENTER);
getContentPane().add(QuestionArea, BorderLayout.WEST);
public void mouseMoved(MouseEvent e)
mouseLabel.add("x = " + e.getX() + ", y = " + e.getY());
public static void main(String[] args)
new SwingApplication().setVisible(true);
}
this compiles, anyway:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class SwingApplication extends JFrame
JButton answerButton = new JButton("Answer");
JButton submit = new JButton("Submit");
JButton button = new JButton("Next Question");
JButton NextRecord = new JButton("Next Record");
JTextField answerText = new JTextField("");
JTextArea QuestionArea = new JTextArea("QuestionArea");
JPanel pane = new JPanel();
JLabel label1 = new JLabel ("Answer the following question");
JLabel mouseLabel = new JLabel();
JLabel lblpic1 = new JLabel();
public SwingApplication()
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocation(300,200);
setSize(700,600);
lblpic1.setIcon(new ImageIcon("couple.jpg") );
submit.setToolTipText("Click to get solution");
pane.add(label1);
pane.add(button);
pane.add(answerText);
pane.add(answerButton);
pane.add(submit);
pane.add(NextRecord);
getContentPane().add(pane,BorderLayout.SOUTH);
getContentPane().add(label1,BorderLayout.NORTH);
getContentPane().add(lblpic1,BorderLayout.CENTER);
getContentPane().add(QuestionArea, BorderLayout.WEST);
public void mouseMoved(MouseEvent e)
mouseLabel.setText("x = " + e.getX() + ", y = " + e.getY());
public static void main(String[] args)
new SwingApplication().setVisible(true);
}Learn about coding standards and styles. Yours is awful.
%
Similar Messages
-
Combo box and Check box..help with code please?
Here is my problem...i have a list of check boxes and according to which one is checked, i need combo boxes to populate different choices.
as an easy example im only using 2 check boxes and two combo boxes.
the check boxes are named Choice 1or2 with export values of 1 and 2
the Combo Boxes are named List A and List B..
both containing options that say you checked box 1 and you checked box 2
any help would be greatly appreciatedImplode wrote:
"Help with code please."
In the future, please use a meaningful subject. Given that you're posting here, it's kind of a given that you're looking for help with the code. The whole point of the subject is to give people a high level idea of what KIND of help with what KIND of code you need, so they can decide if they're interested and qualified to help.
Exception in thread "main" java.lang.NumberFormatException: For input string: "fgg"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at assignment1.Game.Start(Game.java:120)
at assignment1.RunGame.main(RunGame.java:18)This error message is telling you exactly what's wrong. At line 120 of Game.java, in the Start method (which should start with lowercase "s" to follow conventions, by the way), you're calling Integer.parseInt, but "fgg" is not a valid int. -
Borderless Window help with code please!
I am using Dreamweaver MX 2004.
I just cannot get my head round this Java code and would really appreciate some help or direction!
I want to make a nice little window to show a few lines of text, with a close button or X in the corner (not fussed). I have looked at lots of tutorials and produced numerous codes to use.
OK, fine I get that bit. My problem comes with placing the codes in the right places. I paste the HEAD portion in the head of the doc. The BODY in the body. BUT is this the doc I am going to call up with my few lines of text in, or the doc I am going to call from? Get what I mean? Also I want to call from a link and haven't had much luck with the line of code I put in the link box. I have tried lots ways and have just managed to confuse myself.
I am not asking for someone to do it for me and believe me I have tried to work this out for myself but it's not happening for me. Please can someone explain this to me in very plain English as I am obviously some sort of delinquent!
Thank youYes I am using HTML and Javascript. So Java and Javascript are not the same thing? Right ,OK ,well that has taught me something. Don't suppose you can help me with script on this forum then. Sorry!
-
Some Help with Code please?
Hi, Basicly i hope someone can help me with a small issue. Im
new to flash.
I found code which uses a switchboard to switch between a
broadcast to the swf player or client side.
I want to to have a single connection button(at broadcaster
side) that will cut the switcher and enable the broadcaster to
connect directly to the client.
Im not sure what exactly to change or add inthe current mains
code.
Please help. Thanks.
(the switcher has only one button[cut_btn] that switches a
stream in embedded video [prev_video] which is activated when a
broadcaster USERID is selected from a datagrid[broadcasterList_dg])
I want a single connect button in the broadcaster which will
do what the switch button does but cut out the clicking of a
datagrid and previewing basicly cut off the switcher
altogether.Doesnt matter ive figured it out.
-
Newbie - HELP WITH CODE PLEASE!
Hi guys,
I have recently started using flash as some of the guys i work with suggested that it would be useful...
I am currently designing a basic site in AS3 and am stuck with a bit of coding. I keep getting the error message:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at new_web_v1_fla::MainTimeline/frame141()
and having searched the net i cant find a solution. Here's my code:
stop();
function gohome(e:MouseEvent):void {
gotoAndStop("home");
back_btn1.addEventListener(MouseEvent.CLICK, gohome);
function goit(e:MouseEvent):void {
gotoAndStop("it");
it_btn.addEventListener(MouseEvent.CLICK, goit);
next_btn1.addEventListener(MouseEvent.CLICK, goit);
back_btn2.addEventListener(MouseEvent.CLICK, goit);
function goom(e:MouseEvent):void {
gotoAndStop("om");
om_btn.addEventListener(MouseEvent.CLICK, goom);
next_btn2.addEventListener(MouseEvent.CLICK, goom);
back_btn3.addEventListener(MouseEvent.CLICK, goom);
function gogd(e:MouseEvent):void {
gotoAndStop("gd");
gd_btn.addEventListener(MouseEvent.CLICK, gogd);
next_btn3.addEventListener(MouseEvent.CLICK, gogd);
back_btn4.addEventListener(MouseEvent.CLICK, gogd);
function gocu(e:MouseEvent):void {
gotoAndStop("cu");
cu_btn.addEventListener(MouseEvent.CLICK, gocu);
next_btn4.addEventListener(MouseEvent.CLICK, gocu);
I hope someone can help me out!
Thanks
JonThanks again for the advice, following your instructions i did use the // infornt of various bits of script.
My AS now looks like this and the buttons that have the as left in the script without // before them work fine, no errors:
stop();
function gohome(e:MouseEvent):void {
gotoAndStop("home");
//back_btn1.addEventListener(MouseEvent.CLICK, gohome);
function goit(e:MouseEvent):void {
gotoAndStop("it");
it_btn.addEventListener(MouseEvent.CLICK, goit);
next_btn1.addEventListener(MouseEvent.CLICK, goit);
//back_btn2.addEventListener(MouseEvent.CLICK, goit);
function goom(e:MouseEvent):void {
gotoAndStop("om");
om_btn.addEventListener(MouseEvent.CLICK, goom);
//next_btn2.addEventListener(MouseEvent.CLICK, goom);
//back_btn3.addEventListener(MouseEvent.CLICK, goom);
function gogd(e:MouseEvent):void {
gotoAndStop("gd");
gd_btn.addEventListener(MouseEvent.CLICK, gogd);
//next_btn3.addEventListener(MouseEvent.CLICK, gogd);
//back_btn4.addEventListener(MouseEvent.CLICK, gogd);
function gocu(e:MouseEvent):void {
gotoAndStop("cu");
cu_btn.addEventListener(MouseEvent.CLICK, gocu);
//next_btn4.addEventListener(MouseEvent.CLICK, gocu);
the question now is how do i get my other buttons back into the script and get the bloody thing to work?
ARRRGGGHHH! i am beginning to wish that i had never started! lol
Thanks
Jon -
Hi, I am new to Java and am trying to write a program for a class, but I can't seem to get it to work correctly.
The program is supposed to ask you to enter "A,B,C, or Q" and be case sensitive. If you enter A,B,C you get a message, if you enter Q it quits the program and if you enter anything else you are supposed to get an error message. It is supposed to keep looping the program until the user enters Q. We are supposed to use Do--While and If-Else loops.
Thanks in advance
Code Below that I am using (it at least compiles :) )
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class abcprogram
public static void main(String[] args)
String grade;
grade = JOptionPane.showInputDialog("Please enter A, B, C, or Q. Program is case sensitive");
do
if (grade.equals("A"))
JOptionPane.showInputDialog("Good Work");
else if (grade.equals("B"))
JOptionPane.showInputDialog("Try Harder");
else if (grade.equals("C"))
JOptionPane.showInputDialog("Did you study?");
else if (grade.equals("Q"))
System.exit(0);
else
JOptionPane.showInputDialog("You entered a wrong letter!");
}while (grade != "Q");
}One other thing: the while condidtion should read
while (!grade.equals("Q"))
Try it like this;-import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class abc {
public static void main(String[] args){
String grade, enter;
grade = JOptionPane.showInputDialog
("Please enter A, B, C, or Q. The program
he program is case sensitive");
do {
if (grade.equals("A")) grade =
)) grade = JOptionPane.showInputDialog
("Good Work.
("Good Work. (Enter Q to
("Good Work. (Enter Q to quit)");
else if (grade.equals("B")) grade =
)) grade = JOptionPane.showInputDialog
("Try
("Try Harder.
("Try Harder. (enter Q to
("Try Harder. (enter Q to quit)");
else if (grade.equals("C")) grade =
)) grade = JOptionPane.showInputDialog
("Did
("Did you
("Did you study? (Enter
("Did you study? (Enter Q to quit)");
else if (grade.equals("Q"))
uals("Q")) System.exit(0);
else JOptionPane.showInputDialog("You
ialog("You entered a wrong letter!");
while (grade != "Q");} -
I would really appreciate some help with my search & results page that is now throwing up the following error:
Warning: mysql_free_result() expects parameter 1 to be resource, null given in...... line (the line number refers to the following code:
mysql_free_result($RSsearchforsale);
mysql_free_result($RsSearchForSale2);
mysql_free_result($RsSearchForSale3);
mysql_free_result($RsSearchForSale4);
I am new to php and am setting up a dynamic site in Dreamweaver (thanks to the Missing Manual – very helpful). I apologise in advanced for my lengthy description of the problem (perhaps get yourself a drink before continuing!)
I have a Search page with 4 list menus where the user can select an option from ANY or ALL of the menus, if a menu is not selected the value posted to the results page will be 'zzz'.
On the results page I have 4 recordsets, all getting the correct results, only one recordset is required to run depending on how many of the menus from the search page have been selected and a test is run before executing the sql using a SWITCH statement checking how many of the menus had passed the 'zzz' values from the Search page if you see what I mean. The results page has Repeating Regions, Recordset Paging and Display Record Count. The exact result that I require are generated by this method.
THE PROBLEM, when a user makes a selection the first page of 10 results is fine, but the error message above is shown at the bottom of the page, AND when the user clicks NEXT to go to the next page of results THERE ARE NO RESULTS.
This is exactly what happens depending on how many menus selected and which recordset is used:
4 menus selected from Search: runs RSsearchforsale, results correct but 3 error messages on 1st page relating to mysql_free_result($RsSearchForSale2),mysql_free_result($RsSearchForSale3), & mysql_free_result($RsSearchForSale4). The display record count shows correct results found. NEXT page is empty of results and still shows the correct display record count as if it should be displaying the records, also has the same 3 error messages.
3 menus selected from Search: runs RsSearchForSale2, results correct but 3 error messages on 1st page relating to mysql_free_result($RSsearchforsale),mysql_free_result($RsSearchForSale3), & mysql_free_result($RsSearchForSale4). The display record count shows correct number of results. NEXT page shows results from the DEFAULT setting of the recordset and the Display record count reflects this new set of results. Also still shows the 3 mysql_free_results for RsSearchForSale2, 3 and 4.
2 menus selected from Search: runs RsSearchForSale3, results correct but 2 error messages on 1st page relating to mysql_free_result($RSsearchforsale) & mysql_free_result (RsSearchForSale4). The display record count is correct. NEXT page does exactly the same as described in above 3 menus selected.
1 menu selected from search: runs RsSearchForSale4, results correct but 1 error meaasge on 1st page, mysql_free_result($RSsearchforsale). Display record count is correct and again when NEXT page is selected does as described in above where 2 or 3 menus selected.
If you have gotten this far without falling asleep then thank you and well done! I have pasted my code below and I know its a lot to ask but please please can you give me an idea as to where or why I have gone wrong. I felt I was so close at perfecting this search and have been working on it for weeks now. I feel sure the problem is because I have 4 recordsets on the page but I could find no other way to get the exact results I wanted from the menus.
Looking forward to any help.
<?php require_once('Connections/propertypages.php'); ?>
<?php if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
return $theValue;
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_RSsearchforsale = 10;
$pageNum_RSsearchforsale = 0;
if (isset($_GET['pageNum_RSsearchforsale'])) {
$pageNum_RSsearchforsale = $_GET['pageNum_RSsearchforsale'];
$startRow_RSsearchforsale = $pageNum_RSsearchforsale * $maxRows_RSsearchforsale;
$varloc_RSsearchforsale = "mpl";
if (isset($_POST['location'])) {
$varloc_RSsearchforsale = $_POST['location'];
$vartype_RSsearchforsale = "vil";
if (isset($_POST['type'])) {
$vartype_RSsearchforsale = $_POST['type'];
$varprice_RSsearchforsale = "pr9";
if (isset($_POST['price'])) {
$varprice_RSsearchforsale = $_POST['price'];
$varbed_RSsearchforsale = "b5";
if (isset($_POST['beds'])) {
$varbed_RSsearchforsale = $_POST['beds'];
switch (true) {
case ($varloc_RSsearchforsale != 'zzz' && $vartype_RSsearchforsale != 'zzz' && $varprice_RSsearchforsale != 'zzz' && $varbed_RSsearchforsale != 'zzz'):
mysql_select_db($database_propertypages, $propertypages);
$query_RSsearchforsale = sprintf("SELECT DISTINCT trueprice,`desc`, `propid`, `bathrooms`, `photo1`, locationtable.loc, typetable.style, bedtable.`number` FROM detailstable JOIN locationtable ON detailstable.location=locationtable.locid JOIN typetable ON detailstable.type=typetable.typeid JOIN pricetable ON detailstable.price=pricetable.priceid JOIN bedtable ON detailstable.beds=bedtable.bedid WHERE location=%s AND price=%s AND type=%s AND beds=%s ORDER BY detailstable.trueprice ASC", GetSQLValueString($varloc_RSsearchforsale, "text"),GetSQLValueString($varprice_RSsearchforsale, "text"),GetSQLValueString($vartype_RSsearchforsale, "text"),GetSQLValueString($varbed_RSsearchforsale, "text"));
$query_limit_RSsearchforsale = sprintf("%s LIMIT %d, %d", $query_RSsearchforsale, $startRow_RSsearchforsale, $maxRows_RSsearchforsale);
$RSsearchforsale = mysql_query($query_limit_RSsearchforsale, $propertypages) or die(mysql_error());
$row_RSsearchforsale = mysql_fetch_assoc($RSsearchforsale);
if (isset($_GET['totalRows_RSsearchforsale'])) {
$totalRows_RSsearchforsale = $_GET['totalRows_RSsearchforsale'];
} else {
$all_RSsearchforsale = mysql_query($query_RSsearchforsale);
$totalRows_RSsearchforsale = mysql_num_rows($all_RSsearchforsale);
$totalPages_RSsearchforsale = ceil($totalRows_RSsearchforsale/$maxRows_RSsearchforsale)-1;
$queryString_RSsearchforsale = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_RSsearchforsale") == false &&
stristr($param, "totalRows_RSsearchforsale") == false) {
array_push($newParams, $param);
if (count($newParams) != 0) {
$queryString_RSsearchforsale = "&" . htmlentities(implode("&", $newParams));
$queryString_RSsearchforsale = sprintf("&totalRows_RSsearchforsale=%d%s", $totalRows_RSsearchforsale, $queryString_RSsearchforsale); } ?>
<?php require_once('Connections/propertypages.php'); ?>
<?php if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
return $theValue;
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_RsSearchForSale2 = 10;
$pageNum_RsSearchForSale2 = 0;
if (isset($_GET['pageNum_RsSearchForSale2'])) {
$pageNum_RsSearchForSale2 = $_GET['pageNum_RsSearchForSale2'];
$startRow_RsSearchForSale2 = $pageNum_RsSearchForSale2 * $maxRows_RsSearchForSale2;
$varloc2_RsSearchForSale2 = "mpl";
if (isset($_POST['location'])) {
$varloc2_RsSearchForSale2 = $_POST['location'];
$varprice2_RsSearchForSale2 = "p9";
if (isset($_POST['price'])) {
$varprice2_RsSearchForSale2 = $_POST['price'];
$vartype2_RsSearchForSale2 = "vil";
if (isset($_POST['type'])) {
$vartype2_RsSearchForSale2 = $_POST['type'];
$varbed2_RsSearchForSale2 = "b5";
if (isset($_POST['beds'])) {
$varbed2_RsSearchForSale2 = $_POST['beds'];
switch (true) {
case ($varloc2_RsSearchForSale2 == 'zzz'):
case ($varprice2_RsSearchForSale2 == 'zzz'):
case ($vartype2_RsSearchForSale2 == 'zzz'):
case ($varbed2_RsSearchForSale2 == 'zzz'):
mysql_select_db($database_propertypages, $propertypages);
$query_RsSearchForSale2 = sprintf("SELECT DISTINCT trueprice,`desc`, `propid`, `bathrooms`, `photo1`, locationtable.loc, typetable.style, bedtable.`number` FROM detailstable JOIN locationtable ON detailstable.location=locationtable.locid JOIN typetable ON detailstable.type=typetable.typeid JOIN pricetable ON detailstable.price=pricetable.priceid JOIN bedtable ON detailstable.beds=bedtable.bedid WHERE (location=%s AND price=%s AND type=%s) OR (location=%s AND price=%s AND beds=%s) OR (location=%s AND type=%s AND beds=%s) OR (price=%s AND type=%s AND beds=%s) ORDER BY detailstable.trueprice ASC", GetSQLValueString($varloc2_RsSearchForSale2, "text"),GetSQLValueString($varprice2_RsSearchForSale2, "text"),GetSQLValueString($vartype2_RsSearchForSale2, "text"),GetSQLValueString($varloc2_RsSearchForSale2, "text"),GetSQLValueString($varprice2_RsSearchForSale2, "text"),GetSQLValueString($varbed2_RsSearchForSale2, "text"),GetSQLValueString($varloc2_RsSearchForSale2, "text"),GetSQLValueString($vartype2_RsSearchForSale2, "text"),GetSQLValueString($varbed2_RsSearchForSale2, "text"),GetSQLValueString($varprice2_RsSearchForSale2, "text"),GetSQLValueString($vartype2_RsSearchForSale2, "text"),GetSQLValueString($varbed2_RsSearchForSale2, "text"));
$query_limit_RsSearchForSale2 = sprintf("%s LIMIT %d, %d", $query_RsSearchForSale2, $startRow_RsSearchForSale2, $maxRows_RsSearchForSale2);
$RsSearchForSale2 = mysql_query($query_limit_RsSearchForSale2, $propertypages) or die(mysql_error());
$row_RsSearchForSale2 = mysql_fetch_assoc($RsSearchForSale2);
if (isset($_GET['totalRows_RsSearchForSale2'])) {
$totalRows_RsSearchForSale2 = $_GET['totalRows_RsSearchForSale2'];
} else {
$all_RsSearchForSale2 = mysql_query($query_RsSearchForSale2);
$totalRows_RsSearchForSale2 = mysql_num_rows($all_RsSearchForSale2);
$totalPages_RsSearchForSale2 = ceil($totalRows_RsSearchForSale2/$maxRows_RsSearchForSale2)-1;
$queryString_RsSearchForSale2 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_RsSearchForSale2") == false &&
stristr($param, "totalRows_RsSearchForSale2") == false) {
array_push($newParams, $param);
if (count($newParams) != 0) {
$queryString_RsSearchForSale2 = "&" . htmlentities(implode("&", $newParams));
$queryString_RsSearchForSale2 = sprintf("&totalRows_RsSearchForSale2=%d%s", $totalRows_RsSearchForSale2, $queryString_RsSearchForSale2);
}?>
<?php require_once('Connections/propertypages.php'); ?>
<?php if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
return $theValue;
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_RsSearchForSale3 = 10;
$pageNum_RsSearchForSale3 = 0;
if (isset($_GET['pageNum_RsSearchForSale3'])) {
$pageNum_RsSearchForSale3 = $_GET['pageNum_RsSearchForSale3'];
$startRow_RsSearchForSale3 = $pageNum_RsSearchForSale3 * $maxRows_RsSearchForSale3;
$varloc3_RsSearchForSale3 = "mpl";
if (isset($_POST['location'])) {
$varloc3_RsSearchForSale3 = $_POST['location'];
$varprice3_RsSearchForSale3 = "p9";
if (isset($_POST['price'])) {
$varprice3_RsSearchForSale3 = $_POST['price'];
$vartype3_RsSearchForSale3 = "vil";
if (isset($_POST['type'])) {
$vartype3_RsSearchForSale3 = $_POST['type'];
$varbed3_RsSearchForSale3 = "b5";
if (isset($_POST['beds'])) {
$varbed3_RsSearchForSale3 = $_POST['beds'];
switch (true) {
case ($varloc3_RsSearchForSale3 == 'zzz' && $varprice3_RsSearchForSale3 == 'zzz'):
case ($varprice3_RsSearchForSale3 == 'zzz' && $vartype3_RsSearchForSale3 == 'zzz'):
case ($vartype3_RsSearchForSale3 == 'zzz' && $varbed3_RsSearchForSale3 == 'zzz' ):
case ($varbed3_RsSearchForSale3 == 'zzz' && $varloc3_RsSearchForSale3 == 'zzz'):
case ($varloc3_RsSearchForSale3 == 'zzz' && $vartype3_RsSearchForSale3 == 'zzz'):
case ($varprice3_RsSearchForSale3 == 'zzz' && $varbed3_RsSearchForSale3 == 'zzz'):
mysql_select_db($database_propertypages, $propertypages);
$query_RsSearchForSale3 = sprintf("SELECT DISTINCT trueprice,`desc`, `propid`, `bathrooms`, `photo1`, locationtable.loc, typetable.style, bedtable.`number` FROM detailstable JOIN locationtable ON detailstable.location=locationtable.locid JOIN typetable ON detailstable.type=typetable.typeid JOIN pricetable ON detailstable.price=pricetable.priceid JOIN bedtable ON detailstable.beds=bedtable.bedid WHERE (location=%s AND price=%s) OR (location=%s AND type=%s) OR (location=%s AND beds=%s) OR ( type=%s AND beds=%s) OR (price=%s AND type=%s) OR (price=%s AND beds=%s) ORDER BY detailstable.trueprice ASC", GetSQLValueString($varloc3_RsSearchForSale3, "text"),GetSQLValueString($varprice3_RsSearchForSale3, "text"),GetSQLValueString($varloc3_RsSearchForSale3, "text"),GetSQLValueString($vartype3_RsSearchForSale3, "text"),GetSQLValueString($varloc3_RsSearchForSale3, "text"),GetSQLValueString($varbed3_RsSearchForSale3, "text"),GetSQLValueString($vartype3_RsSearchForSale3, "text"),GetSQLValueString($varbed3_RsSearchForSale3, "text"),GetSQLValueString($varprice3_RsSearchForSale3, "text"),GetSQLValueString($vartype3_RsSearchForSale3, "text"),GetSQLValueString($varprice3_RsSearchForSale3, "text"),GetSQLValueString($varbed3_RsSearchForSale3, "text"));
$query_limit_RsSearchForSale3 = sprintf("%s LIMIT %d, %d", $query_RsSearchForSale3, $startRow_RsSearchForSale3, $maxRows_RsSearchForSale3);
$RsSearchForSale3 = mysql_query($query_limit_RsSearchForSale3, $propertypages) or die(mysql_error());
$row_RsSearchForSale3 = mysql_fetch_assoc($RsSearchForSale3);
if (isset($_GET['totalRows_RsSearchForSale3'])) {
$totalRows_RsSearchForSale3 = $_GET['totalRows_RsSearchForSale3'];
} else {
$all_RsSearchForSale3 = mysql_query($query_RsSearchForSale3);
$totalRows_RsSearchForSale3 = mysql_num_rows($all_RsSearchForSale3);
$totalPages_RsSearchForSale3 = ceil($totalRows_RsSearchForSale3/$maxRows_RsSearchForSale3)-1;
$queryString_RsSearchForSale3 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_RsSearchForSale3") == false &&
stristr($param, "totalRows_RsSearchForSale3") == false) {
array_push($newParams, $param);
if (count($newParams) != 0) {
$queryString_RsSearchForSale3 = "&" . htmlentities(implode("&", $newParams));
$queryString_RsSearchForSale3 = sprintf("&totalRows_RsSearchForSale3=%d%s", $totalRows_RsSearchForSale3, $queryString_RsSearchForSale3);
} ?>
<?php require_once('Connections/propertypages.php'); ?>
<?php if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
return $theValue;
$currentPage = $_SERVER["PHP_SELF"];
$maxRows_RsSearchForSale4 = 10;
$pageNum_RsSearchForSale4 = 0;
if (isset($_GET['pageNum_RsSearchForSale4'])) {
$pageNum_RsSearchForSale4 = $_GET['pageNum_RsSearchForSale4'];
$startRow_RsSearchForSale4 = $pageNum_RsSearchForSale4 * $maxRows_RsSearchForSale4;
$varloc4_RsSearchForSale4 = "mpl";
if (isset($_POST['location'])) {
$varloc4_RsSearchForSale4 = $_POST['location'];
$vartype4_RsSearchForSale4 = "vil";
if (isset($_POST['type'])) {
$vartype4_RsSearchForSale4 = $_POST['type'];
$varprice4_RsSearchForSale4 = "p9";
if (isset($_POST['price'])) {
$varprice4_RsSearchForSale4 = $_POST['price'];
$varbed4_RsSearchForSale4 = "b5";
if (isset($_POST['beds'])) {
$varbed4_RsSearchForSale4 = $_POST['beds'];
switch (true) {
case ($varloc4_RsSearchForSale4 == 'zzz' && $vartype4_RsSearchForSale4 =='zzz' && $varprice4_RsSearchForSale4 == 'zzz'):
case ($varloc4_RsSearchForSale4 == 'zzz' && $varprice4_RsSearchForSale4 =='zzz' && $varbed4_RsSearchForSale4 == 'zzz'):
case ($varloc4_RsSearchForSale4 == 'zzz' && $varbed4_RsSearchForSale4 =='zzz' && $vartype4_RsSearchForSale4 == 'zzz'):
case ($varbed4_RsSearchForSale4 == 'zzz' && $vartype4_RsSearchForSale4 =='zzz' && $varprice4_RsSearchForSale4 == 'zzz'):
mysql_select_db($database_propertypages, $propertypages);
$query_RsSearchForSale4 = sprintf("SELECT DISTINCT trueprice,`desc`, `propid`, `bathrooms`, `photo1`, locationtable.loc, typetable.style, bedtable.`number` FROM detailstable JOIN locationtable ON detailstable.location=locationtable.locid JOIN typetable ON detailstable.type=typetable.typeid JOIN pricetable ON detailstable.price=pricetable.priceid JOIN bedtable ON detailstable.beds=bedtable.bedid WHERE location=%s OR price=%s OR type=%s OR beds=%s ORDER BY detailstable.trueprice ASC", GetSQLValueString($varloc4_RsSearchForSale4, "text"),GetSQLValueString($varprice4_RsSearchForSale4, "text"),GetSQLValueString($vartype4_RsSearchForSale4, "text"),GetSQLValueString($varbed4_RsSearchForSale4, "text"));
$query_limit_RsSearchForSale4 = sprintf("%s LIMIT %d, %d", $query_RsSearchForSale4, $startRow_RsSearchForSale4, $maxRows_RsSearchForSale4);
$RsSearchForSale4 = mysql_query($query_limit_RsSearchForSale4, $propertypages) or die(mysql_error());
$row_RsSearchForSale4 = mysql_fetch_assoc($RsSearchForSale4);
if (isset($_GET['totalRows_RsSearchForSale4'])) {
$totalRows_RsSearchForSale4 = $_GET['totalRows_RsSearchForSale4'];
} else {
$all_RsSearchForSale4 = mysql_query($query_RsSearchForSale4);
$totalRows_RsSearchForSale4 = mysql_num_rows($all_RsSearchForSale4);
$totalPages_RsSearchForSale4 = ceil($totalRows_RsSearchForSale4/$maxRows_RsSearchForSale4)-1;
$queryString_RsSearchForSale4 = "";
if (!empty($_SERVER['QUERY_STRING'])) {
$params = explode("&", $_SERVER['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_RsSearchForSale4") == false &&
stristr($param, "totalRows_RsSearchForSale4") == false) {
array_push($newParams, $param);
if (count($newParams) != 0) {
$queryString_RsSearchForSale4 = "&" . htmlentities(implode("&", $newParams));
$queryString_RsSearchForSale4 = sprintf("&totalRows_RsSearchForSale4=%d%s", $totalRows_RsSearchForSale4, $queryString_RsSearchForSale4);
}?>Hi David,
Thank you for your reply and patience, we are getting closer in spite of me!
Of course i needed to change the name of the recordset, i did that the first time i did it (when i got the error), the when i re did it i forgot, in my defense i was also trying to get a full understanding of the code using the W3Schools php reference and writing by the side of the code on a piece of paper what it meant in English.
Anyway after re doing the code correctly it still displayed all the records of my database but i realised that was because i was POSTING from the search form and when i changed it to the GET method I now get results when all 4 list menus are selected from and the paging works. After reading about the POST / GET method i chose the POST option, is the GET method a better option in my circumstance?
On my site now if the user selects from 1,2 or 3 of the menus rather than selecting the relevant records it displays the NO RESULT page, I would like my users to be able to select from all of the menus or ANY combination of the menus and find exact results for their search, for example if they only select a location and a price i want it display all records that match that location and price with any number of bedrooms and any Type of property: Perhaps this is due to how my list menus are set up, for each menu the first Item label is Location (or Beds or Type or Price) and the value i have left blank which i believe means that it will use the item label as the value, the second Item label for all menus is Any and again the value has been left blank. All other item labels have values relevant to database records.
I do look forward to your reply and cannot thank you enough for following this through with me, please continue to bare with me just a little more,
best regards
Tessimon
Date: Wed, 11 Nov 2009 06:56:24 -0700
From: [email protected]
To: [email protected]
Subject: Help with message please: Warning: mysql_free_result() expects parameter 1 to be resource, null given in...... line
You're not adding the WHERE clause to the SQL query. My example code uses $query_search. You need to change that variable to match the name of your recordset, i.e. $query_RSsearchforsale.
Moreover, the WHERE clause needs to go before ORDER BY.
$query_RSsearchforsale = "SELECT trueprice,`desc`, `propid`, `bathrooms`, `location`, `type`, `price`, `beds`, `photo1`, locationtable.loc, typetable.style, bedtable.`number` FROM detailstable JOIN locationtable ON detailstable.location=locationtable.locid JOIN typetable ON detailstable.type=typetable.typeid JOIN pricetable ON detailstable.price=pricetable.priceid JOIN bedtable ON detailstable.beds=bedtable.bedid ";
// Set a flag to indicate whether the query has a WHERE clause
$where = false;
// Loop through the associatiave array of expected search values
foreach ($expected as $var => $type) {
if (isset($_GET[$var])) {
$value = trim(urldecode($_GET[$var]));
if (!empty($value)) {
// Check if the value begins with > or <
// If so, use it as the operator, and extract the value
if ($value[0] == '>' || $value[0] == '<') {
$operator = $value[0];
$value = ltrim(substr($value, 1));
} elseif (strtolower($type) != 'like') {
$operator = '=';
// Check if the WHERE clause has been added yet
if ($where) {
$query_RSsearchforsale .= ' AND ';
} else {
$query_RSsearchforsale .= ' WHERE ';
$where = true;
// Build the SQL query using the right operator and data type
$type = strtolower($type);
switch($type) {
case 'like':
$query_RSsearchforsale .= "`$var` LIKE " . GetSQLValueString('%' .
$value . '%', "text");
break;
case 'int':
case 'double':
case 'date':
$query_RSsearchforsale .= "`$var` $operator " .
GetSQLValueString($value, "$type");
break;
default:
$query_RSsearchforsale .= "`$var` = " . GetSQLValueString($value,
"$type");
$query_RSsearchforsale .= ' ORDER BY detailstable.trueprice ASC';
> -
I have need help with something Please respond Quickly :)
I have need help with something Please respond Quickly ok so i have the linksys wrt54g Version 2.2 and i upgraded the firmware to V4.21.4 from this site http://homesupport.cisco.com/en-us/wireless/lbc/WRT54G and i clicked V2.2 for the router. So after i upgraded i lost internet ability i can't use the internet so i had to downgrade back to V4.21.1 but i want the things that newer update sloves. Please Help. Everything thing says DNS error? aka Modem.
$$Cgibbons$$Ya i tried that i tried restoring and redoing everything when i downgrade back to .1 it works fine though?
$$Cgibbons$$ -
Hi I got an email from itunes saying that my pre order was ready and when I click on the link from my ipad it takes me to the itunes store app and then it doesn't do anything help with this please .
<Link Edited By Host>Thanks for your advice, I went to the apple shop today for a face to face meeting with a tech and he checked everything and could not figure out why I was having this problem so we decided to give up on that account and create a whole new one for me using a different email address.
Now I can download apps on both my iPhone and ipad2.
If anyone is reading this in Brisbane Australia go to the Chermside apple shop and ask for Wade. He was fantastic!
Jan -
Itunes istallation freezes at 'Publishing Product Information'. Can anyone help with this please?
You need more memory. 4 GB is not enough:
1.12 GB Page-outs
[killed] com.apple.CallHistoryPluginHelper.plist
[killed] com.apple.CallHistorySyncHelper.plist
[killed] com.apple.cmfsyncagent.plist
[killed] com.apple.coreservices.appleid.authentication.plist
[killed] com.apple.sbd.plist
[killed] com.apple.security.cloudkeychainproxy.plist
[killed] com.apple.telephonyutilities.callservicesd.plist
7 processes killed due to memory pressure
Problem System Launch Daemons: ℹ️
[killed] com.apple.ctkd.plist
[killed] com.apple.icloud.findmydeviced.plist
[killed] com.apple.softwareupdate_download_service.plist
[killed] com.apple.wdhelper.plist
4 processes killed due to memory pressure -
Hi,
I'm new to java, i'm creating java analog clock application. but i'm getting so many errors. i still try to figur out what are those. can someone please help me with this code. Thank you
here is my code
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.text.*;
import javax.swing.*;
//The main class
public class AnalogClock extends JFrame
// Initialize all the variables
SimpleDateFormat f_s = new SimpleDateFormat ("ss", Locale.getDefault());
SimpleDateFormat f_m = new SimpleDateFormat ("mm", Locale.getDefault());
SimpleDateFormat f_h = new SimpleDateFormat ("hh", Locale.getDefault());
SimpleDateFormat standard = new SimpleDateFormat ("HH:mm:ss", Locale.getDefault());
int xs, ys, xm, ym, xh, yh, s, xcenter, ycenter, m, h, x, y, mouse_x, mouse_y;
String temp;
Dimension d;
Date now;
Thread thr = null;
Image im;
Boolean M = false;
Graphics gIm;
Dimension dIm;
int sx, sy, sx2, sy2;
Color digital = Color.blue, hour = Color.blue, minute = Color.yellow,
second = Color.green, circle = Color.red, hours = Color.blue, mute_logo = Color.green;
// paint(): the main part of the program
public void paint(Graphics g)
d = getSize();
xcenter = d.width/2;
ycenter = d.height/2;
x = d.width;
y = d.height;
if(im == null)
im = createImage(x, y);
gIm = im.getGraphics();
dIm = new Dimension(x, y);
// Get the current timestamp
now = new Date();
// Get the seconds
temp = f_s.format(now);
s = Integer.parseInt(temp);
temp = f_m.format(now);
m = Integer.parseInt(temp);
temp = f_h.format(now);
h = Integer.parseInt(temp);
// Calculate all the positions of the hands
xs = (int) (Math.cos(s * Math.PI / 30 - Math.PI / 2) * 45 + xcenter);
ys = (int) (Math.sin(s * Math.PI / 30 - Math.PI / 2) * 45 + ycenter);
xm = (int) (Math.cos(m * Math.PI / 30 - Math.PI / 2) * 40 + xcenter);
ym = (int) (Math.sin(m * Math.PI / 30 - Math.PI / 2) * 40 + ycenter);
xh = (int) (Math.cos((h * 30 + m / 2) * Math.PI / 180 - Math.PI / 2) * 30 + xcenter);
yh = (int) (Math.sin((h * 30 + m / 2) * Math.PI / 180 - Math.PI / 2) * 30 + ycenter);
// Refresh the image
gIm.setColor(getBackground());
gIm.fillRect(0, 0, dIm.width, dIm.height);
// Draw the circle of the clock
gIm.setColor(circle);
gIm.drawOval(0, 0, d.width-1, d.height-1);
gIm.setColor(hours);
// Draw the stripes of the hours
for(int i = 0;i<12;i++)
sx = (int) (Math.cos((i * 30) * Math.PI / 180 - Math.PI / 2) * 47 + xcenter);
sy = (int) (Math.sin((i * 30) * Math.PI / 180 - Math.PI / 2) * 47 + xcenter);
sx2 = (int) (Math.cos((i * 30) * Math.PI / 180 - Math.PI / 2) * 49 + xcenter);
sy2 = (int) (Math.sin((i * 30) * Math.PI / 180 - Math.PI / 2) * 49 + xcenter);
gIm.drawLine(sx, sy, sx2, sy2);
// Draw the time on the top of the clock
gIm.setColor(digital);
gIm.drawString(standard.format(now), 25, 30);
// Draw the mute logo
Mute m = new Mute(M, gIm);
// Draw the hands
// Seconds
gIm.setColor(second);
gIm.drawLine(xcenter, ycenter, xs, ys);
// Minutes
gIm.setColor(minute);
gIm.drawLine(xcenter, ycenter-1, xm, ym);
gIm.drawLine(xcenter-1, ycenter, xm, ym);
// Hour
gIm.setColor(hour);
gIm.drawLine(xcenter, ycenter-1, xh, yh);
gIm.drawLine(xcenter-1, ycenter, xh, yh);
// Paint the generated image on the screen
if(im != null)
g.drawImage(im, 0, 0, null);
if(M == false)
play(getCodeBase(), "Sound/Click.wav");
public void update(Graphics g)
paint(g);
class Mute
Mute(Boolean mute, Graphics g)
g.setColor(mute_logo);
Polygon p = new Polygon();
p.addPoint(1, 7);
p.addPoint(6, 2);
p.addPoint(6, 12);
g.fillPolygon(p);
g.drawLine(7, 5, 7, 9);
g.drawLine(9, 4, 9, 10);
g.drawLine(11, 3, 11, 11);
if(mute == true)
g.drawLine(13, 3, 1, 11);
/* // All the mouse events
public void mousePressed(MouseEvent evt)
mouse_x = evt.getX();
mouse_y = evt.getY();
if(mouse_x <= 11 && mouse_x >= 1 && mouse_y <= 12 && mouse_y >= 2)
if(M == true)
M = false;
} else {
M = true;
repaint();
public void mouseReleased(MouseEvent evt){}
public void mouseEntered(MouseEvent evt){}
public void mouseExited(MouseEvent evt){}
public void mouseClicked(MouseEvent evt){}
}There is a gross misconception among the new and learning programmers that a lot of code is good and once you put that last close scope in place that things are wonderful because you have all the code down...
Please repeat this: NO, short debugged runs and incremental builds are better.
As a matter of fact, that is so important, go back and say it again and again until it really truly sinks in.
This concept is really pounded into your soul when you program in assembler--probably an ailment of the new generation of programmers, they never have had to do assembler or machine coding--but any time you get more than about 20 lines of code that hasn't been checked for bugs, you should start thinking... "Oh, do I really have the skills and patience to go back and debug (yes, actually use the debugger to step through it all.) that big of mess?" The biggest project is just like eating an elephant, you do it one small bite at a time over as long a time as it takes--you don't cook half the elephant and sit down and expect to eat it in one meal; neither do you sit down and decide to code a whole program and then debug it. You just don't have the skill to do it.
When you modify someone else's code, the same is true--small changes and debug as you change. Making all the changes you want, then debugging just runs into a huge error file of related problems that are basically indiscernible from each other because many of them are probably related.
Most of the request for "Help, I cannot get this to run." Also contain the words: "I just finished coding..." That statement in and of itself is one of the great flawed concepts that anyone can have--coding is complete when you have an acceptable release candidate, and then only until you decide or are asked to make further changes.
Work in small blocks of code and incrementally build a project--your frustration levels will be much less. And as you gain skill, increase the size of the code blocks (I had a friend in college that never had 5 consecutive lines of code compile--ever! He works for MS now.) and get to know your debugger. Your debugger is your friend, if you've not been introduced to your debugger, then get acquainted soon! Like maybe before you even try to cut another piece of code.
On the other side of things... cheer up, we've all been there and learned the lessons... some lessons just come harder than others... make your life less frustrating, it's a lot more fun and enjoyable. -
Why can't I get this extension to show up after I download it, help with code?
Is there an error in the source code somwhere, here is the url https://addons.mozilla.org/en-US/firefox/addon/wisecampus-1/. I created this extension with the app builder where it generates a zip and you modify it to what you want. I made very little changes, I just would like to have a button on the toolbar that launches the site when clicked. If someone with more experience could take a look at the source code and possibly help me get this up and running it would be greatly appreciated. Thanks all!
Not really a Firefox user support issue. I am not am add-on developer, but I think I found your problem. ''Can't show the actual css code from that file, this forum software would try to execute it instead of displaying the code.''
In the '''overlay.css''' file the '''''wcextension-toolbar-button - list-style-image''''' shows the '''''url''''' as http://www.wisecampusbooks.com/images/WC_icon2.jpg . Shouldn't it point to the '''toolbar-button.png''' image in the \chrome\skin\ folder instead?
I can see the image from that URL when the toolbar button is sitting in the Customize Palette, but the image disappears when the button is moved to a Toolbar. I think that using a web based image in the UI is a security fault, which Firefox is blocking. Something like that could potentially be used to "track" a user or to count how often that button is clicked.
''BTW'' the Add-ons support forum is here: <br />
https://forums.mozilla.org/addons/ <br />
or you could post here, if you need additional help <br />
http://forums.mozillazine.org/viewforum.php?f=53&sid=554d097b5d69110d4859bd054051b9b2 -
Hi everybody,
I designed a calculator, and I need help with the rest of the scientific actions. I know I need to use the different Math methods, but what exactly? Also, it needs to work as an applet and application, and in the applet, the buttons don't appear in order, how can I fix that?
I will really appreciate your help with this program, I need to finish it ASAP. Please e-mail me at [email protected].
Below is the code for the calcualtor.
Thanks in advance,
-Maria
// calculator
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
public class calculator extends JApplet implements
ActionListener
private JButton one, two, three, four, five, six, seven,
eight, nine, zero, dec, eq, plus, minus, mult, div, clear,
mem, mrc, sin, cos, tan, asin, acos, atan, x2, sqrt, exp, pi, percent;
private JLabel output, blank;
private Container container;
private String operation;
private double number1, number2, result;
private boolean clear = false;
//GUI
public void init()
container = getContentPane();
//Title
//super("Calculator");
JPanel container = new JPanel();
container.setLayout( new FlowLayout( FlowLayout.CENTER
output = new JLabel("");
output.setBorder(new MatteBorder(2,2,2,2,Color.gray));
output.setPreferredSize(new Dimension(1,26));
getContentPane().setBackground(Color.white);
getContentPane().add( "North",output );
getContentPane().add( "Center",container );
//blank
blank = new JLabel( " " );
container.add( blank );
//clear
clear = new JButton( "CE" );
clear.addActionListener(this);
container.add( clear );
//seven
seven = new JButton( "7" );
seven.addActionListener(this);
container.add( seven );
//eight
eight = new JButton( "8" );
eight.addActionListener(this);
container.add( eight );
//nine
nine = new JButton( "9" );
nine.addActionListener(this);
container.add( nine );
//div
div = new JButton( "/" );
div.addActionListener(this);
container.add( div );
//four
four = new JButton( "4" );
four.addActionListener(this);
container.add( four );
//five
five = new JButton( "5" );
five.addActionListener(this);
container.add( five );
//six
six = new JButton( "6" );
six.addActionListener(this);
container.add( six );
//mult
mult = new JButton( "*" );
mult.addActionListener(this);
container.add( mult );
//one
one = new JButton( "1" );
one.addActionListener(this);
container.add( one );
//two
two = new JButton( "2" );
two.addActionListener(this);
container.add( two );
//three
three = new JButton( "3" );
three.addActionListener(this);
container.add( three );
//minus
minus = new JButton( "-" );
minus.addActionListener(this);
container.add( minus );
//zero
zero = new JButton( "0" );
zero.addActionListener(this);
container.add( zero );
//dec
dec = new JButton( "." );
dec.addActionListener(this);
container.add( dec );
//plus
plus = new JButton( "+" );
plus.addActionListener(this);
container.add( plus );
//mem
mem = new JButton( "MEM" );
mem.addActionListener(this);
container.add( mem );
//mrc
mrc = new JButton( "MRC" );
mrc.addActionListener(this);
container.add( mrc );
//sin
sin = new JButton( "SIN" );
sin.addActionListener(this);
container.add( sin );
//cos
cos = new JButton( "COS" );
cos.addActionListener(this);
container.add( cos );
//tan
tan = new JButton( "TAN" );
tan.addActionListener(this);
container.add( tan );
//asin
asin = new JButton( "ASIN" );
asin.addActionListener(this);
container.add( asin );
//acos
acos = new JButton( "ACOS" );
cos.addActionListener(this);
container.add( cos );
//atan
atan = new JButton( "ATAN" );
atan.addActionListener(this);
container.add( atan );
//x2
x2 = new JButton( "X2" );
x2.addActionListener(this);
container.add( x2 );
//sqrt
sqrt = new JButton( "SQRT" );
sqrt.addActionListener(this);
container.add( sqrt );
//exp
exp = new JButton( "EXP" );
exp.addActionListener(this);
container.add( exp );
//pi
pi = new JButton( "PI" );
pi.addActionListener(this);
container.add( pi );
//percent
percent = new JButton( "%" );
percent.addActionListener(this);
container.add( percent );
//eq
eq = new JButton( "=" );
eq.addActionListener(this);
container.add( eq );
//Set size and visible
setSize( 190, 285 );
setVisible( true );
public static void main(String args[]){
//execute applet as application
//applet's window
JFrame applicationWindow = new JFrame("calculator");
applicationWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//applet instance
calculator appletObject = new calculator();
//init and start methods
appletObject.init();
appletObject.start();
} // end main
public void actionPerformed(ActionEvent ae)
JButton but = ( JButton )ae.getSource();
//dec action
if( but.getText() == "." )
//if dec is pressed, first check to make shure there
is not already a decimal
String temp = output.getText();
if( temp.indexOf( '.' ) == -1 )
output.setText( output.getText() + but.getText() );
//clear action
else if( but.getText() == "CE" )
output.setText( "" );
operation = "";
number1 = 0.0;
number2 = 0.0;
//plus action
else if( but.getText() == "+" )
operation = "+";
number1 = Double.parseDouble( output.getText() );
clear = true;
//output.setText( "" );
//minus action
else if( but.getText() == "-" )
operation = "-";
number1 = Double.parseDouble( output.getText() );
clear = true;
//output.setText( "" );
//mult action
else if( but.getText() == "*" )
operation = "*";
number1 = Double.parseDouble( output.getText() );
clear = true;
//output.setText( "" );
//div action
else if( but.getText() == "/" )
operation = "/";
number1 = Double.parseDouble( output.getText() );
clear = true;
//output.setText( "" );
//eq action
else if( but.getText() == "=" )
number2 = Double.parseDouble( output.getText() );
if( operation == "+" )
result = number1 + number2;
else if( operation == "-" )
result = number1 - number2;
else if( operation == "*" )
result = number1 * number2;
else if( operation == "/" )
result = number1 / number2;
//output result
output.setText( String.valueOf( result ) );
clear = true;
operation = "";
//default action
else
if( clear == true )
output.setText( "" );
clear = false;
output.setText( output.getText() + but.getText() );Multiple post:
http://forum.java.sun.com/thread.jsp?forum=31&thread=474370&tstart=0&trange=30 -
Demo application with code: please
Hi all
does anyone have demo application with code in JSF, please.Hi,
You'll find it in ..jsf-1_1\samples.
The guess number application is simple and may help you.
Regards.
Cedric -
package student;
import wrabble.*;
public final class Board implements IBoard
public Board()
setBoardSize(15);
public void clearBoard()
for(int i = 0; i < tiles.length; i++)
for(int j = 0; j < tiles.length; j++)
tiles[i][j] = null;
public Tile getTile(int i, int j)
return tiles[i][j];
public boolean setTile(int i, int j, Tile tile)
if(i >= 0 && j >= 0 && i <= 14 && j <= 14)
tiles[i][j] = tile;
return true;
else
return false;
public Multiplier getMultiplier(int i, int j)
return multipliers[i][j];
public void setMultiplier(int i, int j, Multiplier multiplier)
multipliers[i][j] = multiplier;
public int getBoardSize()
return tiles.length;
public void setBoardSize(int i)
tiles = new Tile[i];
multipliers = new Multiplier[i][i];
public String[] getWords()
return new String[0];
Tile tiles[][];
Multiplier multipliers[][];
Can someone please help me comment this code, so I can fully understand what it does?
ThanksUmm... I meant proper commenting like you do with code:
package student;
import wrabble.*;
public final class Board implements IBoard
// Set the board size to 15 x 15
public Board()
setBoardSize(15);
// What to do when the Reset button is pressed
public void clearBoard()
// Clear and reset everything
for(int i = 0; i < tiles.length; i=i+1)
for(int j = 0; j < tiles.length; j=j+1)
tiles[i][j] = null;
public Tile getTile(int i, int j)
return tiles[i][j];
public boolean setTile(int i, int j, Tile tile)
if(i >= 0 && j >= 0 && i <= 14 && j <= 14)
tiles[i][j] = tile;
return true;
else
return false;
public Multiplier getMultiplier(int i, int j)
return multipliers[i][j];
public void setMultiplier(int i, int j, Multiplier multiplier)
multipliers[i][j] = multiplier;
public int getBoardSize()
return tiles.length;
public void setBoardSize(int i)
tiles = new Tile[i];
multipliers = new Multiplier[i][i];
public String[] getWords()
return new String[0];
Tile tiles[][];
Multiplier multipliers[][];
I have started so far...
Maybe you are looking for
-
Am I the only one who has a problem trying to complete the O'Reilly Gettining Started with Flex3 PDF
This is the first time i am trying to understand any and everyhign flex. So i am trying to go through the pdf which is recommended to get acquainted with the program. One issue i see is that the pdf leaves out details right from the star. The next
-
Create a report based on sample data!
Hello all, I would like to get some helps for creating a report based on the following table data in the database: Class | Name | Student ======================================= 1 | Algebra
-
Query not showing any results - Urgent
Hi all, I am running a query on the project dates (0PS_C05), although there is data in the cube , the query says no applicable data found, although there is no filter for the object ( Origin - 0DATE_SRCE ) in the query definition , but when the query
-
New system & iLife installation, how to recuperate published iWeb Sites ?
Hi I had to reinstall my system and recuperated my old files. But iWeb opens as a new application and my older published Websites made with iWeb do not appear. Where or hoe do I go about to recuperate them? Thanks Yve
-
An error occurred during the initialization of the view manager - Web IC
We just upgraded our CRM Dev system from 4.0 to 5.0. We've already done this once on our Sandbox. However, in our Dev environment, I execute CRM_IC. Select my profile and then get an exception. An error occurred during the initialization of the vi