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

08-12-2008, 11:04 AM
|
|
Member
|
|
Join Date: Aug 2008
Posts: 7
|
|
|
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
|
|

08-12-2008, 04:00 PM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
|
|
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.
|
|

08-12-2008, 07:39 PM
|
|
Member
|
|
Join Date: Aug 2008
Posts: 7
|
|
|
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
|
|

08-12-2008, 10:16 PM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
|
|
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.
|
|

08-13-2008, 08:05 AM
|
|
Member
|
|
Join Date: Aug 2008
Posts: 7
|
|
|
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.
|
|

08-13-2008, 08:55 AM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Posts: 883
|
|
|
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.
|
|

08-13-2008, 04:02 PM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
|
|
Copy and post them here if you want help with them.
|
|

08-14-2008, 08:42 AM
|
|
Member
|
|
Join Date: Aug 2008
Posts: 7
|
|
|
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?
|
|

08-14-2008, 08:43 AM
|
|
Member
|
|
Join Date: Aug 2008
Posts: 7
|
|
|
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?
|
|

08-14-2008, 04:15 PM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
|
|
|
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?
|
|

08-14-2008, 06:43 PM
|
|
Member
|
|
Join Date: Aug 2008
Posts: 7
|
|
|
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.
|
|

08-14-2008, 07:58 PM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
|
|
Illegal start of expression
Where is the text of your error message? Don't edit it!!!! Copy as is.
|
|

08-15-2008, 10:02 AM
|
|
Member
|
|
Join Date: Aug 2008
Posts: 7
|
|
|
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?
|
|

08-15-2008, 03:39 PM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
|
|
|
I think .wav is one of the formats that java can play.
|
|

08-31-2008, 09:46 PM
|
|
Senior Member
|
|
Join Date: Aug 2008
Posts: 178
|
|
About the random numbers, I would use a loop to generate them. :\
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.
|
|

09-01-2008, 10:15 AM
|
|
Member
|
|
Join Date: Sep 2008
Posts: 1
|
|
|
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.
|
|

09-01-2008, 04:23 PM
|
 |
Senior Member
|
|
Join Date: Jun 2008
Location: Heredia, Costa Rica
Posts: 2,223
|
|
|
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.
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|