Saturday, March 10, 2012

' the price is right' java code?

hi there

i have a school assesment and it is due soon.

i am trying to create the game ' the price is right' but just cant finish it





i think im missing out some valuable codes in there





so could someone please have a look through and see where ive gone wrong and maybe put in the right codes so it will work



thanks for you help!















import java.awt.*;

import java.awt.event.*;

import javax.swing.*;



public class Frame3 extends JFrame

{



// This code sets up parts of that game that are displayed

JPanel thePanel = new JPanel();

JButton convertButton = new JButton();

JButton quitButton = new JButton();

JButton bidButton = new JButton();

JTextArea theTextArea = new JTextArea();

JTextArea enterbids = new JTextArea();

JTextArea higherlower = new JTextArea();

JLabel theLabel = new JLabel();

JTextArea errorTextArea = new JTextArea();

JTextArea resultTextArea = new JTextArea();

JTextField theTextField = new JTextField();















// once the frame is working

public Frame3()

{

}



// This method describes how to set up the frame's objects

public void initComponents() throws Exception

{

// fromthis code you can change the color of the display

Color red = new Color(255,0,0);

Color green = new Color(0,255,0);

Color black = new Color(0,0,0);

Color grey = new Color(100,100,100);

Color womble = new Color(150,200,50);



// this sets upthe size and colour of the actual applet

thePanel.setSize(new java.awt.Dimension(500,500));

thePanel.setBackground(red);







// Quit button

quitButton.setText("Quit");

quitButton.setLocation(new java.awt.Point(280, 300));

quitButton.setBackground(womble);

quitButton.setVisible(true);

quitButton.setSize(new java.awt.Dimension(100, 40));





// bidding button

bidButton.setText("Bid");

bidButton.setLocation(new java.awt.Point(100, 300));

bidButton.setBackground(womble);

bidButton.setVisible(true);

bidButton.setSize(new java.awt.Dimension(100, 40));



// Text area to display the answer

theTextArea.setText("Valued between $110,000 and $110,500");

theTextArea.setLocation(new java.awt.Point(50, 80));

bidButton.setBackground(green);

theTextArea.setEditable(false);

theTextArea.setVisible(true);

theTextArea.setSize(new java.awt.Dimension(300, 30));







// place bids here

enterbids.setText("PLLLLLACE YOUR BIDSSSS!");

enterbids.setLocation(new java.awt.Point(50, 150));

bidButton.setBackground(green);

enterbids.setEditable(true);

enterbids.setVisible(true);

enterbids.setSize(new java.awt.Dimension(300, 30));



// higher or lower

higherlower.setText("Higher or Lower!!!!!!!!!");

higherlower.setLocation(new java.awt.Point(50, 210));

bidButton.setBackground(green);

higherlower.setEditable(false);

higherlower.setVisible(true);

higherlower.setSize(new java.awt.Dimension(300, 30));



// this code enables a box to be editable so players can enter bids

theTextField.setText("place your bids");

theTextField.setLocation(new java.awt.Point(50, 130));

theTextField.setVisible(true);

theTextField.setEditable(false);

theTextField.setSize(new java.awt.Dimension(300, 30));



setSize(500,500);

getContentPane().add(quitButton);

getContentPane().add(enterbids);

getContentPane().add(higherlower);

getContentPane().add(bidButton);

getContentPane().add(theTextArea);

getContentPane().add(theLabel);

getContentPane().add(thePanel);

getContentPane().add(errorTextArea);

getContentPane().add(resultTextArea);

getContentPane().add(theTextField);





}

}' the price is right' java code?
Well of course you are missing important codes in there. You are missing half the programs functionality! Things I notice just with this is that you seem to set the background color of the bidButton over and over again. First womble, then you set it to green three different times. I assume this is because you copied and pasted and forgot to change that.



You are also missing the actual game logic like determining when a button is pressed, the reading in of an item that is going to be bid on, judging who is the closest without going over and to determine which players are currently bidding.



I have to assume this is just your GUI portion of the game, so my advise to you here is to lookup the ActionListener interface and its actionPerformed event handler method. You can find it in the java.awt.event package. You will need this to hook up your buttons to game logic code you have elsewhere.



You can also put in the actionListener anonymously by calling the button's addActionListener method like so...



bidButton.addActionListener(new ActionListener() {



public void actionPerformed(ActionEvent e) {

// Code to handle the clicking of the bid button

}



});



The ActionEvent "e" in this case, is going to represent the control that triggered the action and holds other information about the type and source of the action (the button click).



Once you correct the repeat code and add in some event handling for your button, you will be well on your way to getting this up and running.



Good luck! :)' the price is right' java code?
Jackson,

Did you try to ask your teacher?

Report Abuse

  • sea doo
  • argus
  • dickey s bbq
  • nashville restaurants
  • No comments:

    Post a Comment