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.

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 appreciated

    Implode 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 you

    Yes 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!

  • Need some help with code.. No idea what's wrong! I'm new..(J2ME related)

    Hey there,
    I've just started programming J2ME using Netbeans using the java mobility pack, trying to create a program which interacts with a php webserver..
    I created some code which accessed my php script on my server and returned the contents of the page back, and successfully got it working. However, i did a bit of treaking, and then tried to remove it all.. and now my code won't work. I've been examining it for a good hour and can't seem to find the error! It's annoying me pretty badly.. I'm not liking J2ME already.
    Could someone please look at my code and help me out? I really really want to get this working..
    * VisualMidlet.java
    * Created on 26 October 2007, 19:37
    import java.io.*;
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    * @author Will
    public class VisualMidlet extends MIDlet{
    /** Creates a new instance of VisualMidlet */
    private Display display;
    private Command Submit;
    private Command okCommand2;
    private Command Submit1;
    private Form Form1;
    private StringItem stringItem1;
    String url = "http://people.bath.ac.uk/wal20/testGET.php?type=3";
    public VisualMidlet() {
    System.out.println("initialized");
    display = Display.getDisplay(this);
    Connect();
    public void startApp() {
    public void Connect(){
    try {getViaStreamConnection(url);}
    catch (IOException e) {
    System.out.println("IOException " + e);
    e.printStackTrace();
    public void getViaStreamConnection(String url) throws IOException {
    StreamConnection streamConnection = null; //declares a stream connection
    InputStream inputStream = null; // declares an input Stream
    StringBuffer b = new StringBuffer();
    TextBox textBox = null;
    try {
    System.out.println("Establishing stream");
    streamConnection = (StreamConnection)Connector.open(url);
    System.out.println("Stream established");
    inputStream = streamConnection.openInputStream();
    int ch;
    while((ch = inputStream.read()) != -1) {
    b.append((char) ch);
    textBox = new TextBox("Simple URL Fetch", b.toString(), 1024, 0);
    } finally {
    if(inputStream != null) {
    inputStream.close();
    if(streamConnection != null) {
    streamConnection.close();
    display.setCurrent(textBox);
    public void pauseApp() {   }
    public void destroyApp(boolean unconditional) {  }
    /** This method initializes UI of the application.
    private void initialize() {                     
    getDisplay().setCurrent(get_Form1());
    * This method should return an instance of the display.
    public Display getDisplay() {                        
    return Display.getDisplay(this);
    * This method should exit the midlet.
    public void exitMIDlet() {                        
    getDisplay().setCurrent(null);
    destroyApp(true);
    notifyDestroyed();
    /** This method returns instance for Submit component and should be called instead of accessing Submit field directly.
    * @return Instance for Submit component
    public Command get_Submit() {
    if (Submit == null) {                     
    // Insert pre-init code here
    Submit = new Command("Submit", Command.OK, 1);
    // Insert post-init code here
    return Submit;
    /** This method returns instance for okCommand2 component and should be called instead of accessing okCommand2 field directly.
    * @return Instance for okCommand2 component
    public Command get_okCommand2() {
    if (okCommand2 == null) {                     
    // Insert pre-init code here
    okCommand2 = new Command("Ok", Command.OK, 1);
    // Insert post-init code here
    return okCommand2;
    /** This method returns instance for Submit1 component and should be called instead of accessing Submit1 field directly.
    * @return Instance for Submit1 component
    public Command get_Submit1() {
    if (Submit1 == null) {                      
    // Insert pre-init code here
    Submit1 = new Command("Submit", Command.OK, 1);
    // Insert post-init code here
    return Submit1;
    /** This method returns instance for Form1 component and should be called instead of accessing Form1 field directly.
    * @return Instance for Form1 component
    public Form get_Form1() {
    if (Form1 == null) {                     
    // Insert pre-init code here
    Form1 = new Form(null, new Item[] {get_stringItem1()});
    // Insert post-init code here
    return Form1;
    /** This method returns instance for stringItem1 component and should be called instead of accessing stringItem1 field directly.
    * @return Instance for stringItem1 component
    the code for the php script is:
    <?php
    $response = "Hello";
    if (isset($_GET)) {
    switch ($_GET["type"]) {
    case 1: $response = "Good Morning"; break;
    case 2: $response = "Good Afternoon"; break;
    case 3: $response = "Good Evening"; break;
    default: $response = "Hello"; break;
    echo $response;
    ?>
    I would be grateful for any reply
    Thank you in advance
    -Will

    sorry! i'll repost the code in code format
    * VisualMidlet.java
    * Created on 26 October 2007, 19:37
    import java.io.*;
    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    * @author Will
    public class VisualMidlet extends MIDlet{
    /** Creates a new instance of VisualMidlet */
    private Display display;
    private Command Submit;
    private Command okCommand2;
    private Command Submit1;
    private Form Form1;
    private StringItem stringItem1;
    String url = "http://people.bath.ac.uk/wal20/testGET.php?type=3";
    public VisualMidlet() {
    System.out.println("initialized");
    display = Display.getDisplay(this);
    Connect();
    public void startApp() {
    public void Connect(){
    try {getViaStreamConnection(url);}
    catch (IOException e) {
    System.out.println("IOException " + e);
    e.printStackTrace();
    public void getViaStreamConnection(String url) throws IOException {
    StreamConnection streamConnection = null; //declares a stream connection
    InputStream inputStream = null; // declares an input Stream
    StringBuffer b = new StringBuffer();
    TextBox textBox = null;
    try {
    System.out.println("Establishing stream");
    streamConnection = (StreamConnection)Connector.open(url);
    System.out.println("Stream established");
    inputStream = streamConnection.openInputStream();
    int ch;
    while((ch = inputStream.read()) != -1) {
    b.append((char) ch);
    textBox = new TextBox("Simple URL Fetch", b.toString(), 1024, 0);
    } finally {
    if(inputStream != null) {
    inputStream.close();
    if(streamConnection != null) {
    streamConnection.close();
    display.setCurrent(textBox);
    public void pauseApp() { }
    public void destroyApp(boolean unconditional) { }
    /** This method initializes UI of the application.
    private void initialize() {
    getDisplay().setCurrent(get_Form1());
    * This method should return an instance of the display.
    public Display getDisplay() {
    return Display.getDisplay(this);
    * This method should exit the midlet.
    public void exitMIDlet() {
    getDisplay().setCurrent(null);
    destroyApp(true);
    notifyDestroyed();
    /** This method returns instance for Submit component and should be called instead of accessing Submit field directly.
    * @return Instance for Submit component
    public Command get_Submit() {
    if (Submit == null) {
    // Insert pre-init code here
    Submit = new Command("Submit", Command.OK, 1);
    // Insert post-init code here
    return Submit;
    /** This method returns instance for okCommand2 component and should be called instead of accessing okCommand2 field directly.
    * @return Instance for okCommand2 component
    public Command get_okCommand2() {
    if (okCommand2 == null) {
    // Insert pre-init code here
    okCommand2 = new Command("Ok", Command.OK, 1);
    // Insert post-init code here
    return okCommand2;
    /** This method returns instance for Submit1 component and should be called instead of accessing Submit1 field directly.
    * @return Instance for Submit1 component
    public Command get_Submit1() {
    if (Submit1 == null) {
    // Insert pre-init code here
    Submit1 = new Command("Submit", Command.OK, 1);
    // Insert post-init code here
    return Submit1;
    /** This method returns instance for Form1 component and should be called instead of accessing Form1 field directly.
    * @return Instance for Form1 component
    public Form get_Form1() {
    if (Form1 == null) {
    // Insert pre-init code here
    Form1 = new Form(null, new Item[] {get_stringItem1()});
    // Insert post-init code here
    return Form1;
    /** This method returns instance for stringItem1 component and should be called instead of accessing stringItem1 field directly.
    * @return Instance for stringItem1 component
    }

  • 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
    Jon

    Thanks 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

  • Would like some help with hashmaps please :)

    Map<Integer, Double> probabilities = new HashMap<Integer, Double>();When i try to use the above code in a foreach loop
    for (Map.Entry<Integer, Double> entry : probabilities)i get this error
    Foreach not applicable to expressionCould anyone please enlighten me on what is wrong with that and maybe suggest another way of running through the HashMap.
    THANKS!

    for (Map.Entry<Integer, Double> entry : probabilities.entrySet())

  • Can I get some help with this please

    I got the following error messages from java after running my code.
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 66
         at Graph.ChainingHashTable.get(ChainingHashTable.java:76)
         at Graph.Vertex.isNeighbor(Vertex.java:123)
         at Graph.LinkedGraph.addEdge(LinkedGraph.java:42)
         at Graph.Traversals.main(Traversals.java:311)
    The following is my code
    Traversal.java
    package Graph;
    public class Traversals implements Callback<Vertex>
        public void visit( Vertex data )
            System.out.println( data.getName() );
         * Perform a breadth first traversal of the vertices in the given graph
         * starting at the specified node. The call back object is used to process
         * each node as it appears in the traversal.
         * @param g the graph to traverse
         * @param start the vertex where the traversal will start
         * @param cb the object that processes vertices.
        public void BFSTraverse( Graph g, Vertex start, Callback<Vertex> cb )
            Queue<Vertex> waiting = new LinkedQueue<Vertex>(); // Queue of waiting
                                                                // vertices
            // Ensure the graph has no marked vertices
            List<Vertex> vertices = g.getVertices();
            for( vertices.first(); vertices.isOnList(); vertices.next() )
                vertices.get().setTag( false );
            // Put the start vertex in the work queue
            waiting.enqueue( start );
            // While there are waiting vertices
            while( !waiting.empty() )
                // Get the next Vertex
                Vertex curVertex = waiting.front();
                waiting.dequeue();
                // If this Vertex hasn't been processed yet
                if( !curVertex.getTag() )
                    cb.visit( curVertex ); // Process the vertex
                    curVertex.setTag( true ); // Mark it as visited
                    // Put its unmarked neighbors into the work queue
                    List<Vertex> neighbors = curVertex.getNeighbors();
                    for( neighbors.first(); neighbors.isOnList(); neighbors.next() )
                        Vertex cur = neighbors.get();
                        if( !cur.getTag() )
                            waiting.enqueue( cur );
         * Use Kruskal's algorithm to create a minimum spanning tree for the given
         * graph. The MST is returned in the form of a graph.
         * @param g the graph from which to generate the MST
         * @return a graph containing the the vertices of g and the the edges
         *         nesseary to form a minimum spanning tree.
        public Graph kruskalMST( Graph g )
            // Where the MST will be stored
            Graph mst = new LinkedGraph();
            // All the vertices in the graph
            List<Vertex> vertices = g.getVertices();
            // List of Vertex Sets
            List<Set<String>> vertexSets = new LinkedList();
            // Add the vertices in the original graph to mst
            // and create the vertex sets at the same time
            for( vertices.first(); vertices.isOnList(); vertices.next() )
                String curName = vertices.get().getName();
                Set<String> curSet = null; // new ArrayBasedSet<Vertex>();
                // Add the name of the current vertex to its set and then
                // add the set to the list that contains the vertex sets
                curSet.add( curName );
                vertexSets.add( curSet );
                // Add the current vertex to the MST graph
                mst.addVertex( curName );
            // Put the edges into a heap which effectively sorts them
            Heap<Edge> edges = new ArrayBasedHeap<Edge>();
            List<Edge> allEdges = g.getEdges();
            for( allEdges.first(); allEdges.isOnList(); allEdges.next() )
                edges.insertHeapNode( allEdges.get() );
            // Setup is complete - run the algorithm
            // There is more than one set left in the list vertex sets
            while( vertexSets.size() > 1 )
                // Get the smallest edge
                Edge cur = edges.getSmallest();
                // Find the sets where these vertices are located
                int sourcePos = findSet( vertexSets, cur.getSource().getName() );
                int destPos = findSet( vertexSets, cur.getDest().getName() );
                // If the vertices are in different sets - add the edge to
                // the MST
                if( sourcePos != destPos )
                    Set<String> sourceSet = vertexSets.get( sourcePos );
                    Set<String> destSet = vertexSets.get( destPos );
                    // Add the edge to the MST
                    mst.addEdge( cur.getSource().getName(),
                            cur.getDest().getName(), cur.getCost() );
                    // Merge the sets
                    sourceSet.union( destSet );
                    vertexSets.remove( destPos );
            // The MST can be read from this graph
            return mst;
         * Return the position of the first set in the list that contains the
         * specified name.
         * @param vertexSets a list of sets to search.
         * @param name the name being searched for.
         * @return the position of the first set in the list that contains the name
         *         or -1 if the name cannot be found.
        private int findSet( List<Set<String>> vertexSets, String name )
            int retVal = -1;
            // Step through the list and examine each set. Stop when you
            // find a set with the name or we fall off the list
            for( int i = 0; retVal == -1 && i < vertexSets.size(); i = i + 1 )
                Set curSet = vertexSets.get( i );
                // Does the current set contain the name we are looking for?
                if( curSet.contains( name ) )
                    retVal = i;
            // Return the position of the set
            return retVal;
         * Perform Dijkstra's Shortest Path algorithm on the given graph, starting
         * at the given vertex.
         * @param g the Graph to traverse.
         * @param name the name of the vertex where the traversal starts.
         * @return an array containing vertex path costs.
        public int[] dijkstraSP( Graph g, String name )
            // The names of the vertices for which the shortest
            // path is not known
            Set<String> u = new ArrayBasedSet<String>();
            // The names of the vertices for which the shortest
            // path is known
            Set<String> s = new ArrayBasedSet<String>();
            // Put the vertices in an array to make things easier
            List<Vertex> vertices = g.getVertices();
            Vertex v[] = new Vertex[ vertices.size() ];
            for( int i = 0; i < vertices.size(); i++ )
                v[ i ] = vertices.get( i );
            // The starting vertex
            Vertex start = g.getVertex( name );
            // The lowest costs seen so far
            int c[] = new int[ v.length ];
            // Temporary edge used by the program
            Edge curEdge = null;
            // Sort the vertices by name so that the costs will
            // appear in order by name
            Heap<String> names = new ArrayBasedHeap<String>();
            // Build the heap
            for( int i = 0; i < v.length; i = i + 1 )
                names.insertHeapNode( v[ i ].getName() );
            // Read out the values
            for( int i = 0; !names.empty(); i = i + 1 )
                v[ i ] = g.getVertex( names.getSmallest() );
            // We "know" the shortest path to the source
            s.add( name );
            // For each vertex, compute the starting cost
            for( int i = 0; i < v.length; i = i + 1 )
                // If this isn't the start node
                if( !v[ i ].getName().equals( name ) )
                    // Put it in the unknown set
                    u.add( v[ i ].getName() );
                    // Compute the initial cost to reach this Vertex
                    curEdge = start.getEdge( v[ i ].getName() );
                    if( curEdge != null )
                        c[ i ] = curEdge.getCost();
                    else
                        // This Vertex is currently unreachable
                        c[ i ] = Integer.MAX_VALUE;
                else
                    // It costs 0 to get to the start vertex
                    c[ i ] = 0;
            // Set is complete - run the algorithm until all of
            // the paths are known
            while( !u.isEmpty() )
                // Find the position of the lowest-cost unknown node
                int min = Integer.MAX_VALUE;
                int minPos = -1;
                for( int i = 0; minPos == -1 && i < c.length; i = i + 1 )
                    if( c[ i ] < min && u.contains( v[ i ].getName() ) )
                        min = c[ i ];
                        minPos = i;
                // We know the shortest path to the vertex
                s.add( v[ minPos ].getName() );
                u.remove( v[ minPos ].getName() );
                // Update the costs based
                for( int i = 0; i < c.length; i = i + 1 )
                    // Get the edge between the new shortest and the
                    // current node in the array
                    curEdge = v[ minPos ].getEdge( v[ i ].getName() );
                    // If there is an edge
                    if( curEdge != null )
                        // If going through the new node is better than
                        // what has been seen update the cost
                        if( c[ i ] > c[ minPos ] + curEdge.getCost() )
                            c[ i ] = c[ minPos ] + curEdge.getCost();
            return c;
        public static void main( String args[] )
            Traversals t = new Traversals();
            Graph g = new LinkedGraph();
            g.addVertex( "A" );
            g.addVertex( "B" );
            g.addVertex( "C" );
            g.addVertex( "D" );
            g.addVertex( "E" );
            g.addVertex( "F" );
            g.addEdge( "A", "B", 5 );             <--------------------------------------------------------------------------------------------Line 311
            g.addEdge( "A", "D", 9 );
            g.addEdge( "A", "C", 10 );
            g.addEdge( "B", "A", 5 );
            g.addEdge( "B", "D", 4 );
            g.addEdge( "C", "A", 10 );
            g.addEdge( "C", "D", 13 );
            g.addEdge( "C", "E", 14 );
            g.addEdge( "D", "B", 4 );
            g.addEdge( "D", "A", 9 );
            g.addEdge( "D", "C", 13 );
            g.addEdge( "D", "E", 7 );
            g.addEdge( "D", "F", 8 );
            g.addEdge( "E", "C", 14 );
            g.addEdge( "E", "D", 7 );
            g.addEdge( "E", "F", 2 );
            g.addEdge( "F", "D", 8 );
            g.addEdge( "F", "E", 2 );
            int costs[] = t.dijkstraSP( g, "A" );
            for( int i = 0; i < costs.length; i = i + 1 )
                System.out.println( costs[ i ] );
    }

    ChainingHashTable.java
    package Graph;
    * An implementation of a HashTable using chaining for collision resolution.
    * Javadoc comments for methods specified in the Table interface have been
    * omitted.
    * This code assumes that the preconditions stated in the comments are true when
    * a method is invoked and therefore does not check the preconditions.
    public class ChainingHashTable<K, V> implements Table<K, V>
        private List<Tuple<K, V>> hashTable[]; // The hashtable
        int size; // The size of the hash table
         * Create a new hash table.
         * @param cardinality the number of elements in the domain.
        public ChainingHashTable( int cardinality )
            // Note that the cast is necessary because you cannot
            // create generic arrays in Java. This statement will
            // generate a compiler warning.
            hashTable = (LinkedList<Tuple<K, V>>[]) new LinkedList[ cardinality ];
            size = 0;
        public void put( K key, V value )
            int bucket = key.hashCode();
            // Do we need to create a new list for this bucket?
            if( hashTable[ bucket ] == null )
                hashTable[ bucket ] = new LinkedList<Tuple<K, V>>();
            hashTable[ bucket ].add( new Tuple<K, V>( key, value ) );
            size = size + 1;
        public void remove( K key )
            int bucket = key.hashCode();
            List<Tuple<K, V>> chain = hashTable[ bucket ];
            boolean found = false;
            // Is there a chain to search?
            if( chain != null )
                // Step through the chain until we fall off the end or
                // find the tuple to delete
                chain.first();
                while( !found && chain.isOnList() )
                    // If this tuple has the key we are looking for
                    // delete it and stop the loop
                    if( chain.get().getKey().equals( key ) )
                        chain.remove();
                        found = true;
                    else
                        chain.next();
        public V get( K key )
            int bucket = key.hashCode();
            List<Tuple<K, V>> chain = hashTable[ bucket ];     <----------------------------------------------------------------Line 76
            V retVal = null;
            // Is there a chain to search?
            if( chain != null )
                // Step through the chain until we find the element or
                // run out of list.
                for( chain.first(); retVal == null && chain.isOnList(); chain
                        .next() )
                    // If this tuple has the key we are looking for,
                    // extract the value
                    if( chain.get().getKey().equals( key ) )
                        retVal = chain.get().getValue();
            return retVal;
        public boolean isEmpty()
            return size == 0;
        public int size()
            return size;
        public int cardinality()
            return hashTable.length;
        public List<K> getKeys()
            List<Tuple<K, V>> chain;
            List<K> keys = new LinkedList<K>();
            // Go through each chain and create a list that contains all
            // of the keys in the table
            for( int i = 0; i < hashTable.length; i++ )
                if( hashTable[ i ] != null )
                    chain = hashTable[ i ];
                    for( chain.first(); chain.isOnList(); chain.next() )
                        keys.add( chain.get().getKey() );
            return keys;
        public List<V> getValues()
            List<Tuple<K, V>> chain;
            List<V> values = new LinkedList<V>();
            // Go through each chain and create a list that contains all
            // of the keys in the table
            for( int i = 0; i < hashTable.length; i++ )
                if( hashTable[ i ] != null )
                    chain = hashTable[ i ];
                    for( chain.first(); chain.isOnList(); chain.next() )
                        values.add( chain.get().getValue() );
            return values;
         * Return a string representation of this hash table.
         * @return a string representation of this hash table.
        public String toString()
            StringBuffer hashAsString = new StringBuffer( "" );
            List chain = null;
            for( int i = 0; i < hashTable.length; i = i + 1 )
                hashAsString.append( "h[" + i + "]==" );
                if( hashTable[ i ] != null )
                    chain = hashTable[ i ];
                    for( chain.first(); chain.isOnList(); chain.next() )
                        hashAsString.append( " " + chain.get() );
                hashAsString.append( "\n" );
            return hashAsString.toString();
    } // ChainingHashTable

  • Help with code please

    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");}

  • 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.
    %

  • Please I need some help with a table

    Hi All
    I need some help with a table.
    My table needs to hold prices that the user can update.
    Also has a total of the column.
    my question is if the user adds in a new price how can i pick up the value they have just entered and then add it to the total which will be the last row in the table?
    I have a loop that gets all the values of the column, so I can get the total but it is when the user adds in a new value that I need some help with.
    I have tried using but as I need to set the toal with something like total
        totalTable.setValueAt(total, totalTable.getRowCount()-1,1); I end up with an infinite loop.
    Can any one please advise on some way I can get this to work ?
    Thanks for reading
    Craig

    Hi there camickr
    thanks for the help the other day
    this is my full code....
    package printing;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.print.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import java.text.DecimalFormat;
    public class tablePanel
        extends JDialog  implements Printable {
      BorderLayout borderLayout1 = new BorderLayout();
      private boolean printing = false;
      private Dialog1 dialog;
      JPanel jPanel = new JPanel();
      JTable table;
      JScrollPane scrollPane1 = new JScrollPane();
      DefaultTableModel model;
      private String[] columnNames = {
      private Object[][] data;
      private String selectTotal;
      private double total;
      public tablePanel(Dialog1 dp) {
        dp = dialog;
        try {
          jbInit();
        catch (Exception exception) {
          exception.printStackTrace();
      public tablePanel() {
        try {
          jbInit();
        catch (Exception exception) {
          exception.printStackTrace();
      private void jbInit() throws Exception {
        jPanel.setLayout(borderLayout1);
        scrollPane1.setBounds(new Rectangle(260, 168, 0, 0));
        this.add(jPanel);
        jPanel.add(scrollPane1, java.awt.BorderLayout.CENTER);
        scrollPane1.getViewport().add(table);
        jPanel.setOpaque(true);
        newTable();
        addToModel();
        addRows();
        setTotal();
    public static void main(String[] args) {
      tablePanel tablePanel = new  tablePanel();
      tablePanel.pack();
      tablePanel.setVisible(true);
    public void setTotal() {
      total = 0;
      int i = table.getRowCount();
      for (i = 0; i < table.getRowCount(); i++) {
        String name = (String) table.getValueAt(i, 1);
        if (!"".equals(name)) {
          if (i != table.getRowCount() - 1) {
            double dt = Double.parseDouble(name);
            total = total + dt;
      String str = Double.toString(total);
      table.setValueAt(str, table.getRowCount() - 1, 1);
      super.repaint();
      public void newTable() {
        model = new DefaultTableModel(data, columnNames) {
        table = new JTable() {
          public Component prepareRenderer(TableCellRenderer renderer,
                                           int row, int col) {
            Component c = super.prepareRenderer(renderer, row, col);
            if (printing) {
              c.setBackground(getBackground());
            else {
              if (row % 2 == 1 && !isCellSelected(row, col)) {
                c.setBackground(getBackground());
              else {
                c.setBackground(new Color(227, 239, 250));
              if (isCellSelected(row, col)) {
                c.setBackground(new Color(190, 220, 250));
            return c;
        table.addMouseListener(new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
            if (e.getClickCount() == 1) {
              if (table.getSelectedColumn() == 1) {
       table.setTableHeader(null);
        table.setModel(model);
        scrollPane1.getViewport().add(table);
        table.getColumnModel().getColumn(1).setCellRenderer(new TableRenderDollar());
      public void addToModel() {
        Object[] data = {
            "Price", "5800"};
        model.addRow(data);
      public void addRows() {
        int rows = 20;
        for (int i = 0; i < rows; i++) {
          Object[] data = {
          model.addRow(data);
      public void printOut() {
        PrinterJob pj = PrinterJob.getPrinterJob();
        pj.setPrintable(tablePanel.this);
        pj.printDialog();
        try {
          pj.print();
        catch (Exception PrintException) {}
      public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException {
        Graphics2D g2 = (Graphics2D) g;
        g2.setColor(Color.black);
        int fontHeight = g2.getFontMetrics().getHeight();
        int fontDesent = g2.getFontMetrics().getDescent();
        //leave room for page number
        double pageHeight = pageFormat.getImageableHeight() - fontHeight;
        double pageWidth =  pageFormat.getImageableWidth();
        double tableWidth = (double) table.getColumnModel().getTotalColumnWidth();
        double scale = 1;
        if (tableWidth >= pageWidth) {
          scale = pageWidth / tableWidth;
        double headerHeightOnPage = 16.0;
        //double headerHeightOnPage = table.getTableHeader().getHeight() * scale;
        //System.out.println("this is the hedder heigth   " + headerHeightOnPage);
        double tableWidthOnPage = tableWidth * scale;
        double oneRowHeight = (table.getRowHeight() +  table.getRowMargin()) * scale;
        int numRowsOnAPage = (int) ( (pageHeight - headerHeightOnPage) / oneRowHeight);
        double pageHeightForTable = oneRowHeight *numRowsOnAPage;
        int totalNumPages = (int) Math.ceil( ( (double) table.getRowCount()) / numRowsOnAPage);
        if (pageIndex >= totalNumPages) {
          return NO_SUCH_PAGE;
        g2.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
    //bottom center
        g2.drawString("Page: " + (pageIndex + 1 + " of " + totalNumPages),  (int) pageWidth / 2 - 35, (int) (pageHeight + fontHeight - fontDesent));
        g2.translate(0f, headerHeightOnPage);
        g2.translate(0f, -pageIndex * pageHeightForTable);
        //If this piece of the table is smaller
        //than the size available,
        //clip to the appropriate bounds.
        if (pageIndex + 1 == totalNumPages) {
          int lastRowPrinted =
              numRowsOnAPage * pageIndex;
          int numRowsLeft =
              table.getRowCount()
              - lastRowPrinted;
          g2.setClip(0,
                     (int) (pageHeightForTable * pageIndex),
                     (int) Math.ceil(tableWidthOnPage),
                     (int) Math.ceil(oneRowHeight *
                                     numRowsLeft));
        //else clip to the entire area available.
        else {
          g2.setClip(0,
                     (int) (pageHeightForTable * pageIndex),
                     (int) Math.ceil(tableWidthOnPage),
                     (int) Math.ceil(pageHeightForTable));
        g2.scale(scale, scale);
        printing = true;
        try {
        table.paint(g2);
        finally {
          printing = false;
        //tableView.paint(g2);
        g2.scale(1 / scale, 1 / scale);
        g2.translate(0f, pageIndex * pageHeightForTable);
        g2.translate(0f, -headerHeightOnPage);
        g2.setClip(0, 0,
                   (int) Math.ceil(tableWidthOnPage),
                   (int) Math.ceil(headerHeightOnPage));
        g2.scale(scale, scale);
        //table.getTableHeader().paint(g2);
        //paint header at top
        return Printable.PAGE_EXISTS;
    class TableRenderDollar extends DefaultTableCellRenderer{
        public Component getTableCellRendererComponent(
          JTable table,
          Object value,
          boolean isSelected,
          boolean isFocused,
          int row, int column) {
            setHorizontalAlignment(SwingConstants.RIGHT);
          Component component = super.getTableCellRendererComponent(
            table,
            value,
            isSelected,
            isFocused,
            row,
            column);
            if( value == null || value .equals("")){
              ( (JLabel) component).setText("");
            }else{
              double number = 0.0;
              number = new Double(value.toString()).doubleValue();
              DecimalFormat df = new DecimalFormat(",##0.00");
              ( (JLabel) component).setText(df.format(number));
          return component;
    }

  • I NEED SOME HELP WITH UPDATING MY IPOD TOUCH PLEASE

    i need some help with my ipod the version is 3.1.3 and every time I'm trying to update it says it can not be restored then it says unknown error so i need some help updating my ipod to version 4.2

    If you mean you're trying to update your ios go to settings/general/software update. then you should see the latest ios just tap it and it will automatically update your ipod. If you're trying to restore your ipod (as it's not quite clear in your query) try doing it through itunes instead of on the device itself

  • Help with message please:  Warning: mysql_free_result() expects parameter 1 to be resource, null given in...... line

    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';
    >

  • Need some help with threads...

    Hello all,
    I am working on a project at work, and I am not the best programmer in the world. I have been trying to get my head around this for a couple of days and just cannot get it to work.
    I am writing an instrumentation control program that will have three threads. One is the GUI, one will receive control information and set up the hardware, and one will check the hardware status and report it to the GUI periodically. I plan on using the invokeLater() method to communicate the status to the GUI and change the status display in the GUI. Communication from the GUI to the controller thread and from the status thread to the controller thread I had planned on being piped input/output stream as appropriate. I have a control class and a status class that need to be communicated over these piped streams. In some trial code I have been unable to wrap the piped input/output streams with object input/output streams. I really need some help with this. Here is the main thread code:
    package playingwiththreads1;
    import java.io.*;*
    *public class PlayingWithThreads1 {*
    public static void main(String[] args) {*
    * PipedOutputStream outputPipe = new PipedOutputStream();*
    * ObjectOutputStream oos = null;*
    * ReceiverThread rt = new ReceiverThread(outputPipe);*
    // Start the thread -- First try*
    * Thread t = new Thread(rt);*
    t.start();*
    // Wrap the output pipe with an ObjectOutputStream*
    try*
    oos = new ObjectOutputStream(outputPipe);*
    catch (IOException e)*
    System.out.println(e);*
    // Start the thread -- Second try*
    //Thread t = new Thread(rt);*
    //t.start();*
    /** Send an object over the pipe. In reality this object will be a
    class that contains control or status information */
    try
    if (!oos.equals(null))
    oos.writeObject(new String ("Test"));
    catch (IOException e)
    try
    Thread.sleep(5000);
    catch (InterruptedException e)
    I read somewhere that it matters where you start the thread relative to where you wrap piped streams with the object streams. So, I tried the two places I felt were obvious to start the thread. These are noted in the comments. Here is the code for the thread.
    package playingwiththreads1;
    import java.io.*;
    public class ReceiverThread implements Runnable {
    private PipedInputStream inputPipe = new PipedInputStream();
    private ObjectInputStream inputObject;
    ReceiverThread (PipedOutputStream outputPipe)
    System.out.println("Thread initialization - start");
    try
    inputPipe.connect(outputPipe);
    inputObject = new ObjectInputStream(inputPipe);
    catch (IOException e)
    System.out.println(e);
    System.out.println("Thread initialization - complete");
    public void run()
    System.out.println("Thread started");
    try
    if (inputObject.available() > 0)
    System.out.println(inputObject.read());
    catch (IOException e)
    System.out.println(e);
    Through testing I have determined that no matter where I start the thread, the thread never gets past the "inputObject = new ObjectInputStream(inputPipe);" assignment.
    Could someone please help me with this? There are other ways for me to write this program, but this is the one that I would like to make work.
    Many thanks in advance,
    Rob Hix
    Edited by: RobertHix on Oct 6, 2009 3:54 AM

    Thanks for the help, but that did not work. I tried flushing the ObjectOutputStream and it is still hanging when initializing the thread.
    Here is a better look at the code since I was helped to figure out how to insert it:
    The main method:
    package playingwiththreads1;
    import java.io.*;
    public class PlayingWithThreads1 {
        public static void main(String[] args) {
            PipedOutputStream outputPipe = new PipedOutputStream();
            ObjectOutputStream oos = null;
            ReceiverThread rt = new ReceiverThread(outputPipe);
            // Start the thread -- First try
            //Thread t = new Thread(rt);
            //t.start();
            // Wrap the output pipe with an ObjectOutputStream
            try
                oos = new ObjectOutputStream(outputPipe);
                oos.flush();
            catch (IOException e)
                System.out.println(e);
            // Start the thread -- Second try
            Thread t = new Thread(rt);
            t.start();
            /* Send an object over the pipe.  In reality this object will be a
             * class that contains control or status information */
            try
                if (!oos.equals(null))
                    oos.writeObject(new String ("Test"));
                    oos.flush();
            catch (IOException e)
                System.out.pringln(e);
            try
                Thread.sleep(5000);
            catch (InterruptedException e)
    }The thread code:
    package playingwiththreads1;
    import java.io.*;
    public class ReceiverThread implements Runnable {
        private PipedInputStream inputPipe = new PipedInputStream();
        private ObjectInputStream inputObject;
        ReceiverThread (PipedOutputStream outputPipe)
            System.out.println("Thread initialization - start");
            try
                inputPipe.connect(outputPipe);
                inputObject = new ObjectInputStream(inputPipe);
            catch (IOException e)
                System.out.println(e);
            System.out.println("Thread initialization - complete");
        public void run()
            System.out.println("Thread started");
            try
                if (inputObject.available() > 0)
                    System.out.println(inputObject.read());
            catch (IOException e)
                System.out.println(e);
    }Does anyone else have and ideas?

  • Need some help with a task, constructors.

    Hi there, I've got this task here, and I was wondering if someone could help me out. I wan't to know if my code is answering my task.
    The task:
    BlueJ casino in Las Vegas has given you this task to create a class where they can register their players. You should create a new project and a class called Player. The purpose with this task is that player information could be captured to a secure object and that it couldn't be changed arbitrary.
    The class Player should therefore contain the private fields 'firstname', 'lastname' and 'credits'.
    The official methods that player should define, does the following:
    - setFirstname: Sets the first name to the player
    - getFirstname: Returns the first name to the player
    - setLastname: Sets the last name to the player
    - getLastname: Returns the last name to the player
    - addCredits: Adds the player's credits to a given amount
    - getCredits: Returns the player's credits.
    - validPlayer: Checks if the player credits is higher greater zero, with an if sentence. If it is greater, it should return 'true', otherwise, it should return 'false'.
    - print: Prints the player information to the terminal window (with System.out.println).
    The class Player should also have a constructor that gets two arguments/current parameters to initialize the Player object:
    - A text string that represents the player's first name.
    - A text string that represents the player's last name.
    - The constructor should also set the player's credits to 100.
    My code so far:
    public class Player {
        private String firstname;
        private String lastname;
        private int credits;
        public Player(String firstname, String lastname, int credits) {
           this.firstname = "";
           this.lastname = "";
           this.credits = 100;
        public void setFirstname(String name) {
            firstname = name;
        public String getFirstname() {
            return firstname;
        public void setLastname(String name) {
            lastname = name;
        public String getLastname() {
            return lastname;
        public void addCredits(int amount) {
            credits = credits + amount;
        public int getCredits() {
            return credits;
        public boolean validPlayer() {
            if(getCredits() > 0){
                return true;
            } else {
                return false;
        public void print() {
            System.out.println("PLAYER INFORMATION:");
            System.out.println("First name: " + getFirstname());
            System.out.println("Last name: " + getLastname());
            System.out.println("Credit: " + getCredits());
            System.out.println("-------------------");
    }Please give me some help here, and please show me some code! Thanks for any help!

    Thanks again.
    What about this?public class Player {
        private String firstname;
        private String lastname;
        private int credits;
        public Player(String firstname, String lastname) {
           this.firstname = firstname;
           this.lastname = lastname;
           this.credits = 100;
        public void setFirstname(String name) {
            firstname = name;
        public String getFirstname() {
            return firstname;
        public void setLastname(String name) {
            lastname = name;
        public String getLastname() {
            return lastname;
        public void addCredits(int amount) {
            credits = credits + amount;
        public int getCredits() {
            return credits;
        public boolean validPlayer() {
            if(getCredits() > 0){
                return true;
            } else {
                return false;
        public void print() {
            System.out.println("PLAYER INFORMATION:");
            System.out.println("First name: " + getFirstname());
            System.out.println("Last name: " + getLastname());
            System.out.println("Credit: " + getCredits());
            System.out.println("-------------------");
    }Edit: Oh, yeah - could I write the addCredits() like this?    public void addCredits(int amount) {
            amount+=credits;
        }Edited by: JKM123 on Feb 1, 2009 3:22 PM
    Edited by: JKM123 on Feb 1, 2009 3:24 PM

  • Need help with Fancybox please

    Hola
    I need some help with Fancybox.
    I bought this template and it came without facybox, so I thought
    that this will be a great help to learn some about jQuerry, but I'm lost
    Why is NOT working on my page?
    I just cannot figure this out.
    Can you please check my page?
    http://tummytime.biz/pages/portfolio_fancy.html
    I got Windows 8, Dreamweaver CC
    Thanks a lot.

    There are a couple things that could be causing a couple browsers' collective heads to implode.
    Remove the <! right before your </head> tag...
    </script>
    <!
    </head>
    <body>
    You have two calls to the fancybox css file, you only need one.
    Aside from that I'm not seeing any code problems jump out at me.
    EDIT: Ah, didn't scroll far enough. You have more than one reference to the jquery library. Typically, only one is needed and two or more will cause them all to fail. Usually, you can use the "latest" link and cover all your bases.
    If you aren't using those referenced scripts at the bottom of your page, delete them.

Maybe you are looking for