Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-12-2008, 11:04 AM
Member
 
Join Date: Aug 2008
Posts: 7
sya1912 is on a distinguished road
Assistant on my codes. SOS!!
Hi,

I've already created the layout. I am creating a game call "Toto". User will click on the Button Winning Numbers and a random winning number will appear above the button "Winning Numbers". The problem is Im stuck in creating the random number generator. Need help please..

Thank You.

Here is my codes which I have done.


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.awt.Color;
import java.util.Random; // For random number generator
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class Toto extends JApplet
{
JTextField tf1, tf2, tf3, tf4, tf5, tf6; // User to place his bet numbers.
JLabel lbl1, lbl2, lbl3, lbl4, lbl5, lbl6, lbl7, lbl8, lbl9, lbl10, lbl11;
JButton bWinningNumbers, bBet, bReset;
JPanel p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, pp1;
JCheckBox jcbPopcorn, jcbDrinks;


Vector v = new Vector();

public void init()
{
//p1 = new JPanel(new GridLayout(8,1));
p1 = new JPanel();
p1.setLayout(new FlowLayout());
lbl1 = new JLabel("********************************");

p2 = new JPanel();
lbl2 = new JLabel("***** TOTO BETTING MACHINE *****");
lbl2.setFont(new Font("TimesRoman", Font.BOLD, 12));

// lbl2.setForeGround(Color.BLUE);

p3 = new JPanel();
lbl3 = new JLabel("********************************");

p1.add(lbl1);
p2.add(lbl2);
p3.add(lbl3);

p5 = new JPanel();
p5.setLayout(new FlowLayout());
bWinningNumbers = new JButton("WINNING NUMBER!!!!");
// bWinningNumbers.addActionListener(new Select());
p5.add(bWinningNumbers);




p6 = new JPanel();
p6.setLayout(new FlowLayout());
lbl5 = new JLabel("===== Each Bet Cost $5 =====");
lbl5.setFont(new Font("TimesRoman", Font.ITALIC, 12));

p6.add(lbl5);

p7 = new JPanel();
p7.setLayout(new FlowLayout());
lbl6 = new JLabel("- Please Input Numbers Between 1 to 45 -");
lbl6.setFont(new Font("TimesRoman", Font.ITALIC, 13));

p7.add(lbl6);

p8 = new JPanel(); p8.setLayout(new FlowLayout());


tf1 = new JTextField(3);
tf1.setBackground(Color.RED);
tf1.setForeground(Color.CYAN);

tf2 = new JTextField(3);
tf2.setBackground(Color.YELLOW);
tf2.setForeground(Color.RED);

tf3 = new JTextField(3);
tf3.setBackground(Color.GREEN);
tf3.setForeground(Color.BLACK);

tf4 = new JTextField(3); tf4.setBackground(Color.RED);
tf4.setForeground(Color.CYAN);

tf5 = new JTextField(3); //User place betting number
tf5.setBackground(Color.YELLOW);
tf5.setForeground(Color.RED);


tf6 = new JTextField(3); //User place betting number
tf6.setBackground(Color.GREEN);
tf6.setForeground(Color.BLACK);


p8.add(tf1); //Textfield is added in the panel(p8)
p8.add(tf2); //Textfield is added in the panel(p8)
p8.add(tf3); //Textfield is added in the panel(p8)
p8.add(tf4); //Textfield is added in the panel(p8)
p8.add(tf5); //Textfield is added in the panel(p8)
p8.add(tf6); //Textfield is added in the panel(p8)




p9 = new JPanel();
p9.setLayout(new FlowLayout());
bBet = new JButton("BET"); //For button "BET"
lbl7 = new JLabel("Click On Winning Numbers"); //Between Button Bet and Rest
bReset = new JButton("RESET"); //For button "RESET"
p9.add(bBet);
p9.add(lbl7);
p9.add(bReset);


p10 = new JPanel();
p10.setLayout(new FlowLayout(FlowLayout.LEFT));
lbl8 = new JLabel("Money available: $ ");
p10.add(lbl8);
//lbl10 = new JLabel("");
//p10.add(lbl10);

p11 = new JPanel();
p11.setLayout(new FlowLayout(FlowLayout.LEFT));
lbl9 = new JLabel("Accumulated Bet Amount: $ ");
p11.add(lbl9);
//lbl11 = new JLabel();
//p11.add(lbl11);

pp1 = new JPanel(); // The main Panel for the programme.
pp1.add(p1); // Individual panel in the main panel.
pp1.add(p2); // Individual panel in the main panel.
pp1.add(p3); // Individual panel in the main panel.
pp1.add(p5); // Individual panel in the main panel.
pp1.add(p6); // Individual panel in the main panel.
pp1.add(p7); // Individual panel in the main panel.
pp1.add(p8); // Individual panel in the main panel.
pp1.add(p9); // Individual panel in the main panel.
pp1.add(p10); // Individual panel in the main panel.
pp1.add(p11); // Individual panel in the main panel.

add(pp1);

setVisible(true); //Add pp1 for the main panel.

}
}// end of programme
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-12-2008, 04:00 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
Quote:
creating the random number generator
You need to read the API doc.
Random rand = new Random(seed); // do this one time in your program

int aNbr = rand.nextInt(); // get next random int

You need to describe what kind and the range of numbers you want to generate.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 08-12-2008, 07:39 PM
Member
 
Join Date: Aug 2008
Posts: 7
sya1912 is on a distinguished road
Hi,

I appreciate your help. But I dont know where i supposed to place the codes u gave.


- Where do I Place this in my codes?
- I want to make random number maximun to only 45.

Random rand = new Random(seed); // do this one time in your program

int aNbr = rand.nextInt(); // get next random int
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 08-12-2008, 10:16 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
Quote:
Where do I Place this in my codes?
Create the Random class object in the init code. Have rand be a class variable.
Read the doc on how to use the Random class methods. One of them will: Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive)

Use the method call where you need the number.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 08-13-2008, 08:05 AM
Member
 
Join Date: Aug 2008
Posts: 7
sya1912 is on a distinguished road
Im so noob about this. Could you please add in the codes. Ive tried doing but it kept saying error. Ive tried so many ways to do it but still theres error. I dont understand it. Could u help me please.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 08-13-2008, 08:55 AM
Fubarable's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 883
Fubarable is on a distinguished road
again, read the docs referred to above and give it your best shot. Show us your attempt at using a Random object (I haven't seen any of your attempts posted here yet). In other words, why not try it first and show us what you've tried. It is after all your homework, not ours.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 08-13-2008, 04:02 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
Quote:
but still theres error.
Copy and post them here if you want help with them.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 08-14-2008, 08:42 AM
Member
 
Join Date: Aug 2008
Posts: 7
sya1912 is on a distinguished road
Ok ive figure out about the random numebers. Heres how ive dont it.

class WinningNumbersListener implements ActionListener {

public void actionPerformed(ActionEvent e) {
//handle the button pressing events
Random rand = new Random(); // do this one time in your program

int randonInt1 = rand.nextInt(45);
int randonInt2 = rand.nextInt(45);
int randonInt3 = rand.nextInt(45);
int randonInt4 = rand.nextInt(45);
int randonInt5 = rand.nextInt(45);
int randonInt6 = rand.nextInt(45);

wNum = wNum + randonInt1 + "-" + randonInt2 + "-" + randonInt3 + "-" + randonInt4 + "-" + randonInt5 + "-" + randonInt6;


------------------------------------------------------------------------------------------------------------------------

I have another question. Im doing a button which play music .wav format when click but i have error doing it. It says cannot find symbol method bMusicPlayer();


heres my codes:

class MusicPlayerListener implements ActionListener{

public void init(){
// bMusicPlayer = new Button("MUSIC PLAY");
add(bMusicPlayer);
bMusicPlayer.addActionListener(new MusicPlayerListener());
// stop = new Button(" Stop ");
//add(stop);
// stop.addActionListener(this);
audioClip = getAudioClip(getCodeBase(), "how_six_songs_collide.wav");
}

public void actionPerformed(ActionEvent ae){
Button source = (Button)ae.getSource();
if (source.getLabel() == "MUSIC PLAY "){
audioClip.bMusicPlayer(); <<<<<<<<<<<<<<<<<< Here is the error.
}
//else if(source.getLabel() == " Stop "){
//audioClip.stop();
//}
}
}


Why it kept saying that error?
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 08-14-2008, 08:43 AM
Member
 
Join Date: Aug 2008
Posts: 7
sya1912 is on a distinguished road
Sorry bout the previous post, typo errors.
-----------------------------------------------------------------------

Ok ive figure out about the random numbers. Heres how ive done it.

class WinningNumbersListener implements ActionListener {

public void actionPerformed(ActionEvent e) {
//handle the button pressing events
Random rand = new Random(); // do this one time in your program

int randonInt1 = rand.nextInt(45);
int randonInt2 = rand.nextInt(45);
int randonInt3 = rand.nextInt(45);
int randonInt4 = rand.nextInt(45);
int randonInt5 = rand.nextInt(45);
int randonInt6 = rand.nextInt(45);

wNum = wNum + randonInt1 + "-" + randonInt2 + "-" + randonInt3 + "-" + randonInt4 + "-" + randonInt5 + "-" + randonInt6;


------------------------------------------------------------------------------------------------------------------------

I have another question. Im doing a button which play music .wav format when click but i have error doing it. It says cannot find symbol method bMusicPlayer();


heres my codes:

class MusicPlayerListener implements ActionListener{

public void init(){
// bMusicPlayer = new Button("MUSIC PLAY");
add(bMusicPlayer);
bMusicPlayer.addActionListener(new MusicPlayerListener());
// stop = new Button(" Stop ");
//add(stop);
// stop.addActionListener(this);
audioClip = getAudioClip(getCodeBase(), "how_six_songs_collide.wav");
}

public void actionPerformed(ActionEvent ae){
Button source = (Button)ae.getSource();
if (source.getLabel() == "MUSIC PLAY "){
audioClip.bMusicPlayer(); <<<<<<<<<<<<<<<<<< Here is the error.
}
//else if(source.getLabel() == " Stop "){
//audioClip.stop();
//}
}
}


Why it kept saying that error?
Bookmark Post in Technorati
Reply With Quote
  #10 (permalink)  
Old 08-14-2008, 04:15 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
I can't help you because I don't know what class the audioClip object is. How is it defined?
The compiler can NOT find the method bMusicPlayer() in that class.
What class is bMusicPlayer a method in?
Bookmark Post in Technorati
Reply With Quote
  #11 (permalink)  
Old 08-14-2008, 06:43 PM
Member
 
Join Date: Aug 2008
Posts: 7
sya1912 is on a distinguished road
What does Illegal start of expression means? Im having this error which I dont understand.

Heres my codes.

---------------------------------------------------------------------------------------------

class WinningNumbersListener implements ActionListener {

public void actionPerformed(ActionEvent e) {

if(money < = 0) <<<<<< Error. Illegal start of expression
{
(lbl99 = new JLabel("Game Over!! You have $0/- left. Have a Nice Day."));
}

//handle the button pressing events
Random rand = new Random(); // do this one time in your program

int randonInt1 = rand.nextInt(45);
int randonInt2 = rand.nextInt(45);
int randonInt3 = rand.nextInt(45);
int randonInt4 = rand.nextInt(45);
int randonInt5 = rand.nextInt(45);
int randonInt6 = rand.nextInt(45);

wNum = wNum + randonInt1 + "-" + randonInt2 + "-" + randonInt3 + "-" + randonInt4 + "-" + randonInt5 + "-" + randonInt6;

lbl4.setText(wNum);
//lbl4.setFont(new Font("TimesRoman", Font.BOLD, 16));
money = money - bet;
String sMoney = "" + money;
lbl10.setText(sMoney);
wNum = "";



}
}
-------------------------------------------------------------------------------------

Really aprreciate ur help. Thank You.
Bookmark Post in Technorati
Reply With Quote
  #12 (permalink)  
Old 08-14-2008, 07:58 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
Quote:
Illegal start of expression
Where is the text of your error message? Don't edit it!!!! Copy as is.
Bookmark Post in Technorati
Reply With Quote
  #13 (permalink)  
Old 08-15-2008, 10:02 AM
Member
 
Join Date: Aug 2008
Posts: 7
sya1912 is on a distinguished road
Norm i really appreciate your replies. Ive solved the problem, there shouldnt be no spacing.

What ive type was if(money < = 0). It should be if(money<=0). And also take away the outer bracket for the next line.

Norm, I have a Question, can music in .wav format play in Applet?
Bookmark Post in Technorati
Reply With Quote
  #14 (permalink)  
Old 08-15-2008, 03:39 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
I think .wav is one of the formats that java can play.
Bookmark Post in Technorati
Reply With Quote
  #15 (permalink)  
Old 08-31-2008, 09:46 PM
Senior Member
 
Join Date: Aug 2008
Posts: 178
Supamagier is on a distinguished road
About the random numbers, I would use a loop to generate them. :\
Code:
int[] rands = new int[amount] Random rand = new Random(); for (int i = 0; i < amount; ++i) { rands[i] = rand.nextInt(45); }
Oh, and for God's sake, use [ code] [ /code] tags
__________________
check out
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
, 100% made by me.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #16 (permalink)  
Old 09-01-2008, 10:15 AM
Member
 
Join Date: Sep 2008
Posts: 1
monikachaudhary is on a distinguished road
configure servlet class in tomcat 5.5
Hi all,
I want to know how to configure servet class in web.xml in tomcat 5.5? I am eagerly waiting for reply.
Bookmark Post in Technorati
Reply With Quote
  #17 (permalink)  
Old 09-01-2008, 04:23 PM
Norm's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
Norm is on a distinguished road
You should start your own thread instead of adding to an existing one.
If you Search for web.xml you'll get examples of how to use it.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
What's wrong with my codes? ayoood New To Java 16 09-01-2008 05:57 AM
Error codes lookup - II JavaForums Java Blogs 0 05-23-2008 04:50 PM
Error codes lookup - I JavaForums Java Blogs 0 05-23-2008 04:50 PM
Posting codes and help Java_Man New To Java 2 02-16-2008 05:15 AM
Getting ASCII codes of character gapper New To Java 1 02-02-2008 11:42 AM


All times are GMT +3. The time now is 07:40 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org