Link removed by mod
need to this assignment for school. if anyone can help it would be great
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Link removed by mod
need to this assignment for school. if anyone can help it would be great
Assignment Hangman
^^ the link to the assignment
right now i have this code
//WheelofFortune
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.Math;
public class WheelofFortune extends JApplet implements ActionListener
{
//button for spin
private Container cp; //layout
private JLabel label1; //font
private JPanel p1, p2, p3, p4, p5;
private String phrase[] = {"HOUSE", "FISH", "WALL", "FORD", "KING", "JOB", "", "", "", "", "", "", "", "", "", "", "", "", ""};
private String clue[] = {"place where you live", "lives in water", "made of brick", "car mades", "ruler", "work"};
private JButton spin, solve, b1, b2, b3, b4, b5, b6, b7, b8, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
private JTextArea answer;
private JTextField turns;
public void init ()
{
cp = getContentPane ();
//color of the background
cp.setLayout (new BorderLayout ());
//button
String name = "Wheel of Fortune";
label1 = new JLabel (name);
label1.setLayout (new FlowLayout (FlowLayout.CENTER, 100, 10));
label1.setFont (new Font ("Agency FB", Font.BOLD, 30));
cp.add ("North", label1);
p3 = new JPanel ();
p3.setLayout (new FlowLayout (FlowLayout.CENTER, 50, 150));
Dimension buttonSizes = new Dimension (60, 60);
b1 = new JButton (" ");
b1.setPreferredSize (buttonSizes);
b2 = new JButton (" ");
b2.setPreferredSize (buttonSizes);
b3 = new JButton (" ");
b3.setPreferredSize (buttonSizes);
b4 = new JButton (" ");
b4.setPreferredSize (buttonSizes);
b5 = new JButton (" ");
b5.setPreferredSize (buttonSizes);
b6 = new JButton (" ");
b6.setPreferredSize (buttonSizes);
b7 = new JButton (" ");
b7.setPreferredSize (buttonSizes);
b8 = new JButton (" ");
b8 = new JButton (" ");
b8.setPreferredSize (buttonSizes);
p3.add (b1);
p3.add (b2);
p3.add (b3);
p3.add (b4);
p3.add (b5);
p3.add (b6);
p3.add (b7);
p3.add (b8);
answer = new JTextArea (4, 30);
p3.add (answer);
cp.add ("Center", p3);
p1 = new JPanel ();
p1.setLayout (new FlowLayout (FlowLayout.RIGHT, 10, 300));
p2 = new JPanel ();
p2.setLayout (new FlowLayout (FlowLayout.CENTER, 10, 300));
turns = new JTextField("turns Remaining");
p1.add (turns);
Dimension buttonSize2 = new Dimension (150, 50);
solve = new JButton ("Click to Solve");
solve.setPreferredSize (buttonSize2);
p1.add (solve);
cp.add ("West", p1);
Dimension buttonSize = new Dimension (150, 100);
spin = new JButton ("Click to Spin");
spin.setPreferredSize (buttonSize);
p2.add (spin);
cp.add ("East", p2);
JButton buttonArray[] = {spin, solve, b1, b2, b3, b4, b5, b6, b7, b8, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z};
Dimension buttonSizess = new Dimension (50, 25);
a = new JButton ("A");
a.setPreferredSize (buttonSizess);
b = new JButton ("B");
b.setPreferredSize (buttonSizess);
c = new JButton ("C");
c.setPreferredSize (buttonSizess);
d = new JButton ("D");
d.setPreferredSize (buttonSizess);
e = new JButton ("E");
e.setPreferredSize (buttonSizess);
f = new JButton ("F");
f.setPreferredSize (buttonSizess);
g = new JButton ("G");
g.setPreferredSize (buttonSizess);
h = new JButton ("H");
h.setPreferredSize (buttonSizess);
i = new JButton ("I");
i.setPreferredSize (buttonSizess);
j = new JButton ("J");
j.setPreferredSize (buttonSizess);
k = new JButton ("K");
k.setPreferredSize (buttonSizess);
l = new JButton ("L");
l.setPreferredSize (buttonSizess);
m = new JButton ("M");
m.setPreferredSize (buttonSizess);
n = new JButton ("N");
n.setPreferredSize (buttonSizess);
o = new JButton ("O");
o.setPreferredSize (buttonSizess);
p = new JButton ("P");
p.setPreferredSize (buttonSizess);
q = new JButton ("Q");
q.setPreferredSize (buttonSizess);
r = new JButton ("R");
r.setPreferredSize (buttonSizess);
p4 = new JPanel ();
Dimension panel = new Dimension (100, 100);
p4.add (a);
p4.add (b);
p4.add (c);
p4.add (d);
p4.add (e);
p4.add (f);
p4.add (g);
p4.add (h);
p4.add (i);
p4.add (j);
p4.add (k);
p4.add (l);
p4.add (m);
p4.add (n);
p4.add (o);
p4.add (p);
p4.add (q);
p4.add (r);
p4.setPreferredSize (panel);
cp.add ("South", p4);
s = new JButton ("S");
s.setPreferredSize (buttonSizess);
t = new JButton ("T");
t.setPreferredSize (buttonSizess);
u = new JButton ("U");
u.setPreferredSize (buttonSizess);
v = new JButton ("V");
v.setPreferredSize (buttonSizess);
w = new JButton ("W");
w.setPreferredSize (buttonSizess);
x = new JButton ("X");
x.setPreferredSize (buttonSizess);
y = new JButton ("Y");
y.setPreferredSize (buttonSizess);
z = new JButton ("Z");
z.setPreferredSize (buttonSizess);
p5 = new JPanel ();
p5.setLayout (new FlowLayout (FlowLayout.CENTER, 10, 10));
p5.add (s);
p5.add (t);
p5.add (u);
p5.add (v);
p5.add (w);
p5.add (x);
p5.add (y);
p5.add (z);
p4.add (p5);
//adding actionlistener
a.addActionListener (this);
b.addActionListener (this);
c.addActionListener (this);
d.addActionListener (this);
e.addActionListener (this);
f.addActionListener (this);
g.addActionListener (this);
h.addActionListener (this);
i.addActionListener (this);
j.addActionListener (this);
k.addActionListener (this);
l.addActionListener (this);
m.addActionListener (this);
n.addActionListener (this);
o.addActionListener (this);
p.addActionListener (this);
q.addActionListener (this);
r.addActionListener (this);
s.addActionListener (this);
t.addActionListener (this);
u.addActionListener (this);
v.addActionListener (this);
w.addActionListener (this);
x.addActionListener (this);
y.addActionListener (this);
z.addActionListener (this);
b1.addActionListener (this);
b2.addActionListener (this);
b3.addActionListener (this);
b4.addActionListener (this);
spin.addActionListener (this);
solve.addActionListener (this);
}
public void actionPerformed (ActionEvent ae)
{
Object source = ae.getSource ();
int i = (int) (Math.random () * 6 + 1);
if (source == spin)
{
answer.append (clue [i]);
answer.append (phrase [i]);
}
if (source == h)
{
b1.setText ("h");
}
if (source == o)
{
b2.setText ("o");
}
if (source == u)
{
b3.setText ("u");
}
if (source == s)
{
b4.setText ("s");
}
if (source == e)
{
b5.setText ("e");
}
} //end actionPerformed
} //WheelofFortuneclass
the clues should be matched to the phrase for example if the clue is "where you live" the phrase generated should be "house". and obviously we dont want the user to see the answer "house" because they have to guess it. and also the amount of letters in the phrase determines the buttons to show the answer so how do i do that?
Do you have any specific questions about your assignment?
Please post your code and any questions about problems you are having.
If you don't understand my answer, don't ignore it, ask a question.
The String class has a method that returns its length. Use that in a loop to create one button for each character in the String.the amount of letters in the phrase determines the buttons to show the answer so how do i do that?
Please edit your post and wrap your code with
[code=java]
<YOUR CODE HERE>
[/code]
to get highlighting and preserve formatting.
If you don't understand my answer, don't ignore it, ask a question.
alright i have a better code now too (i think)
//WheelofFortune import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.lang.Math; public class WheelofFortune extends JApplet implements ActionListener { //button for spin private Container cp; //layout private JLabel label1, cash; //font private JPanel p1, p2, p3, p4, p5, heading, logo; private String alpa[] = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}; private String space[] = {" ", " ", " ", " ", " ", " ", " ", " "}; private JButton buttons[] = new JButton [space.length]; private JButton button[] = new JButton [alpa.length]; private String phrase[] = {"HOUSE", "FISH", "WALL", "FORD", "KING", "JOB", "", "", "", "", "", "", "", "", "", "", "", "", ""}; private String clue[] = {"place where you live", "lives in water", "made of brick", "makes car", "ruler", "work"}; private JButton spin, solve; private JTextArea answer; int i = 0; public void init () { cp = getContentPane (); String name = "Wheel of Fortune"; String names = "Cash:"; cash = new JLabel (names); cash.setFont (new Font ("Agency FB", Font.BOLD, 30)); label1 = new JLabel (name); label1.setFont (new Font ("Agency FB", Font.BOLD, 30)); heading = new JPanel (); heading.setLayout (new FlowLayout (FlowLayout.RIGHT, 250, 11)); heading.add (cash); logo = new JPanel (); logo.add (label1); logo.add (heading); logo.setLayout (new FlowLayout (FlowLayout.LEFT, 10, 11)); cp.add ("North", logo); p3 = new JPanel (); p3.setLayout (new FlowLayout (FlowLayout.CENTER, 50, 150)); Dimension buttonSizes = new Dimension (60, 60); for (i = 0 ; i < 8 ; i++) { buttons [i] = new JButton (space [i]); buttons [i].setPreferredSize (buttonSizes); buttons [i].addActionListener (this); p3.add (buttons [i]); } answer = new JTextArea (4, 20); p3.add (answer); cp.add ("Center", p3); p1 = new JPanel (); p1.setLayout (new FlowLayout (FlowLayout.RIGHT, 10, 300)); p2 = new JPanel (); p2.setLayout (new FlowLayout (FlowLayout.CENTER, 10, 300)); Dimension buttonSize2 = new Dimension (150, 50); solve = new JButton ("Click to Solve"); solve.setPreferredSize (buttonSize2); solve.setBackground (Color.red); p1.add (solve); cp.add ("West", p1); Dimension buttonSize = new Dimension (150, 100); spin = new JButton ("Click to Spin"); spin.setPreferredSize (buttonSize); spin.setBackground (Color.yellow); p2.add (spin); cp.add ("East", p2); JButton buttonArray[] = {spin, solve, }; Dimension buttonSizess = new Dimension (50, 25); p4 = new JPanel (); p4.setLayout (new FlowLayout (FlowLayout.CENTER, 10, 100)); Dimension panel = new Dimension (100, 100); for (i = 0 ; i < 26 ; i++) { button [i] = new JButton (alpa [i]); button [i].addActionListener (this); p4.add (button [i]); } cp.add ("South", p4); //adding actionlistener spin.addActionListener (this); solve.addActionListener (this); } public void actionPerformed (ActionEvent ae) { Object source = ae.getSource (); int a = (int) (Math.random () * 5 + 1); String letter = " "; String word = phrase [0]; int position = -1; buttons [5].setVisible (false); if (source == spin) { answer.append (clue [0]); } for (int i = 0 ; i < alpa.length ; i++) { if (source == button [i]) { button [i].setEnabled (false); letter = button [i].getText (); } } for (int i = 0 ; i < word.length () ; i++) { position = word.indexOf (letter); } if (position > -1) { buttons [position].setText (letter); } } //end actionPerformed } //WheelofFortuneclass
--- Update ---
alright i have a better code now too (i think)
//WheelofFortune import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.lang.Math; public class WheelofFortune extends JApplet implements ActionListener { //button for spin private Container cp; //layout private JLabel label1, cash; //font private JPanel p1, p2, p3, p4, p5, heading, logo; private String alpa[] = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}; private String space[] = {" ", " ", " ", " ", " ", " ", " ", " "}; private JButton buttons[] = new JButton [space.length]; private JButton button[] = new JButton [alpa.length]; private String phrase[] = {"HOUSE", "FISH", "WALL", "FORD", "KING", "JOB", "", "", "", "", "", "", "", "", "", "", "", "", ""}; private String clue[] = {"place where you live", "lives in water", "made of brick", "makes car", "ruler", "work"}; private JButton spin, solve; private JTextArea answer; int i = 0; public void init () { cp = getContentPane (); String name = "Wheel of Fortune"; String names = "Cash:"; cash = new JLabel (names); cash.setFont (new Font ("Agency FB", Font.BOLD, 30)); label1 = new JLabel (name); label1.setFont (new Font ("Agency FB", Font.BOLD, 30)); heading = new JPanel (); heading.setLayout (new FlowLayout (FlowLayout.RIGHT, 250, 11)); heading.add (cash); logo = new JPanel (); logo.add (label1); logo.add (heading); logo.setLayout (new FlowLayout (FlowLayout.LEFT, 10, 11)); cp.add ("North", logo); p3 = new JPanel (); p3.setLayout (new FlowLayout (FlowLayout.CENTER, 50, 150)); Dimension buttonSizes = new Dimension (60, 60); for (i = 0 ; i < 8 ; i++) { buttons [i] = new JButton (space [i]); buttons [i].setPreferredSize (buttonSizes); buttons [i].addActionListener (this); p3.add (buttons [i]); } answer = new JTextArea (4, 20); p3.add (answer); cp.add ("Center", p3); p1 = new JPanel (); p1.setLayout (new FlowLayout (FlowLayout.RIGHT, 10, 300)); p2 = new JPanel (); p2.setLayout (new FlowLayout (FlowLayout.CENTER, 10, 300)); Dimension buttonSize2 = new Dimension (150, 50); solve = new JButton ("Click to Solve"); solve.setPreferredSize (buttonSize2); solve.setBackground (Color.red); p1.add (solve); cp.add ("West", p1); Dimension buttonSize = new Dimension (150, 100); spin = new JButton ("Click to Spin"); spin.setPreferredSize (buttonSize); spin.setBackground (Color.yellow); p2.add (spin); cp.add ("East", p2); JButton buttonArray[] = {spin, solve, }; Dimension buttonSizess = new Dimension (50, 25); p4 = new JPanel (); p4.setLayout (new FlowLayout (FlowLayout.CENTER, 10, 100)); Dimension panel = new Dimension (100, 100); for (i = 0 ; i < 26 ; i++) { button [i] = new JButton (alpa [i]); button [i].addActionListener (this); p4.add (button [i]); } cp.add ("South", p4); //adding actionlistener spin.addActionListener (this); solve.addActionListener (this); } public void actionPerformed (ActionEvent ae) { Object source = ae.getSource (); int a = (int) (Math.random () * 5 + 1); String letter = " "; String word = phrase [0]; int position = -1; buttons [5].setVisible (false); if (source == spin) { answer.append (clue [0]); } for (int i = 0 ; i < alpa.length ; i++) { if (source == button [i]) { button [i].setEnabled (false); letter = button [i].getText (); } } for (int i = 0 ; i < word.length () ; i++) { position = word.indexOf (letter); } if (position > -1) { buttons [position].setText (letter); } } //end actionPerformed } //WheelofFortuneclass
--- Update ---
only the word house works :/ i have to make all of them work and also i havent put what happens to the cash label when i click spin
yes right now in this code only the word house works with its correct clue but i have to make all of them work. and i need to create a new label of turns remaining and every time i click spin it should go down by 1... whenever i try to make the new label and put it on the top panel the other things disappear and only turns remaining show up.
please if u can help by tomorrow it would be awesome because i have thursday the final deadline to show it.
//WheelofFortune import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.lang.Math; public class WheelofFortune extends JApplet implements ActionListener { //button for spin private Container cp; //layout private JLabel label1, cash; //font private JPanel p1, p2, p3, p4, p5, heading, logo; private String alpa[] = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}; private String space[] = {" ", " ", " ", " ", " ", " ", " ", " "}; private JButton buttons[] = new JButton [space.length]; private JButton button[] = new JButton [alpa.length]; private String phrase[] = {"HOUSE", "FISH", "WALL", "FORD", "KING", "JOB", "", "", "", "", "", "", "", "", "", "", "", "", ""}; private String clue[] = {"place where you live", "lives in water", "made of brick", "makes car", "ruler", "work"}; private JButton spin, solve; private JTextArea answer; int i = 0; public void init () { cp = getContentPane (); String name = "Wheel of Fortune"; String names = "Cash:"; cash = new JLabel (names); cash.setFont (new Font ("Agency FB", Font.BOLD, 30)); label1 = new JLabel (name); label1.setFont (new Font ("Agency FB", Font.BOLD, 30)); heading = new JPanel (); heading.setLayout (new FlowLayout (FlowLayout.RIGHT, 250, 11)); heading.add (cash); logo = new JPanel (); logo.add (label1); logo.add (heading); logo.setLayout (new FlowLayout (FlowLayout.LEFT, 10, 11)); cp.add ("North", logo); p3 = new JPanel (); p3.setLayout (new FlowLayout (FlowLayout.CENTER, 50, 150)); Dimension buttonSizes = new Dimension (60, 60); for (i = 0 ; i < 8 ; i++) { buttons [i] = new JButton (space [i]); buttons [i].setPreferredSize (buttonSizes); buttons [i].addActionListener (this); p3.add (buttons [i]); } answer = new JTextArea (4, 20); p3.add (answer); cp.add ("Center", p3); p1 = new JPanel (); p1.setLayout (new FlowLayout (FlowLayout.RIGHT, 10, 300)); p2 = new JPanel (); p2.setLayout (new FlowLayout (FlowLayout.CENTER, 10, 300)); Dimension buttonSize2 = new Dimension (150, 50); solve = new JButton ("Click to Solve"); solve.setPreferredSize (buttonSize2); solve.setBackground (Color.red); p1.add (solve); cp.add ("West", p1); Dimension buttonSize = new Dimension (150, 100); spin = new JButton ("Click to Spin"); spin.setPreferredSize (buttonSize); spin.setBackground (Color.yellow); p2.add (spin); cp.add ("East", p2); JButton buttonArray[] = {spin, solve, }; Dimension buttonSizess = new Dimension (50, 25); p4 = new JPanel (); p4.setLayout (new FlowLayout (FlowLayout.CENTER, 10, 100)); Dimension panel = new Dimension (100, 100); for (i = 0 ; i < 26 ; i++) { button [i] = new JButton (alpa [i]); button [i].addActionListener (this); p4.add (button [i]); } cp.add ("South", p4); //adding actionlistener spin.addActionListener (this); solve.addActionListener (this); } public void actionPerformed (ActionEvent ae) { Object source = ae.getSource (); int a = (int) (Math.random () * 5 + 1); String letter = " "; String word = phrase [0]; int position = -1; buttons [5].setVisible (false); if (source == spin) { answer.append (clue [0]); } for (int i = 0 ; i < alpa.length ; i++) { if (source == button [i]) { button [i].setEnabled (false); letter = button [i].getText (); } } for (int i = 0 ; i < word.length () ; i++) { position = word.indexOf (letter); } if (position > -1) { buttons [position].setText (letter); } } //end actionPerformed } //WheelofFortuneclass
The index to the phrase array is hardcoded as 0. If you want different Strings from the array you need to use a variable whose value can be changed.in this code only the word house works
What is the name of the label you are trying to add? I don't see "turns" anywhere in the program.whenever i try to make the new label and put it on the top panel the other things disappear
If you don't understand my answer, don't ignore it, ask a question.
yes exactly whenever i try to generate a random phrase by putting phrase[i] and do the same the thing to the clue[i] it doesnt work ... do i have to create a loop
and for the turns .. i removed it thats why its not in the program... forget turns for now .. if i want to create random cash values beside the cash label like $100,200,300,400,500,600,700,800,900 and add the them as i click the spin button everytime for example if i click the spin button once beside the cash label it should say any of those values and then i play the game and then when i click the spin button again everything should reset except that cash value it should add the previous one to the new one that generates when i click the spin button the second time.
Please explain. Somewhere the code needs randomly chose an index to the phrase array and use that vs the index of 0.it doesnt work
The code has several "magic numbers" coded in it. Its best not to hard code numbers in a program but rather to use variables. For example I see these numbers used: 0, 5, 8
The layout is terrible. I have a small screen so the letters disappear at about r. Wrap the letters to two rows.
I'd work on the turns thing after you get the changing of phrase to work. Its often best to work on one thing at a time.
If you don't understand my answer, don't ignore it, ask a question.
change the 2 "0"'s in action performed to "a"
"a" is a poor name for a variable. Variable names should say what value they contain.
Doesn't the word have to be determined before the blank buttons are displayed so you know how many buttons to display?
If you don't understand my answer, don't ignore it, ask a question.
What about these "magic numbers"?
for (i = 0 ; i < 8 ; i++)
buttons [5].setVisible (false);
String word = phrase [0];
int a = (int) (Math.random () * 5 + 1);
They should all be replaced with variables. Some are the length of arrays, some the length of Strings.
If you don't understand my answer, don't ignore it, ask a question.
the 8 is there because thats the length of the array ... thats how many phrases and clues we have right now .. and it should be 6 actually lol :/
that 5 should also be 6 since there are 6 clues and phrases .. we have to create random clues and phrases everytime the spin button is clicked
--- Update ---
Assignment Hangman
can u read this and try to fix my program?
That is not the way to control a loop. You should use the array's .length attribute, It tells anyone reading the code what is happening and allow the size of the array to be changed without breaking the program.the 8 is there because thats the length of the array
Same reason and problem as with 8.that 5 should also be 6 since there are 6 clues and phrases
You need to work on the layout so the letter buttons are shown in two rows so they fit on a small window.
--- Update ---
That is not the way to control a loop. You should use the array's .length attribute, It tells anyone reading the code what is happening and allow the size of the array to be changed without breaking the program.the 8 is there because thats the length of the array
Same reason and problem as with 8.that 5 should also be 6 since there are 6 clues and phrases
You need to work on the layout so the letter buttons are shown in two rows so they fit on a small window.
If you don't understand my answer, don't ignore it, ask a question.
[code=java]
//WheelofFortune
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.Math;
public class WheelofFortune extends JApplet implements ActionListener
{
//button for spin
private Container cp; //layout
private JLabel label1, cash,cashs, turns, number; //font
private JPanel p1, p2, p3, p4, p5, heading, logo, p6;
private String alpa[] = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
private String space[] = {" ", " ", " ", " ", " ", " ", " ", " "};
private JButton buttons[] = new JButton [space.length];
private JButton button[] = new JButton [alpa.length];
private String phrase[] = {"HOUSE", "FISH", "SHIT", "FORD", "KING", "JOB", "", "", "", "", "", "", "", "", "", "", "", "", ""};
private int cashh[] = {100, 200, 300, 400, 500, 600, 700, 800, 900};
private String clue[] = {"place where you live", "lives in water", "washroom", "makes car", "ruler", "work"};
private JButton spin, solve;
private JTextArea answer;
int i = 0;
int counter = 0;
int times = 0;
public void init ()
{
cp = getContentPane ();
String name = "Wheel of Fortune";
String names = "Cash:";
String turnsRemaining = "Turns Remaining: ";
String numberRemaining = "-5";
cash = new JLabel (names);
cash.setFont (new Font ("Agency FB", Font.BOLD, 30));
cashs = new JLabel ("" + counter);
cashs.setLayout (new FlowLayout (FlowLayout.LEFT, 100, 11));
cp.add(cashs);
label1 = new JLabel (name);
label1.setFont (new Font ("Agency FB", Font.BOLD, 30));
heading = new JPanel ();
heading.setLayout (new FlowLayout (FlowLayout.RIGHT, 5, 25));
heading.add (cash);
turns = new JLabel (turnsRemaining);
number = new JLabel (numberRemaining);
p6 = new JPanel ();
turns.setFont (new Font ("Agency FB", Font.BOLD, 30));
p6.setLayout (new FlowLayout (FlowLayout.RIGHT, 250, 11));
p6.add (turns);
p6.add (number);
logo = new JPanel ();
logo.add (label1);
logo.add (heading);
heading.add (p6);
logo.setLayout (new FlowLayout (FlowLayout.LEFT, 10, 11));
cp.add ("North", logo);
p3 = new JPanel ();
p3.setLayout (new FlowLayout (FlowLayout.CENTER, 10, 100));
Dimension buttonSizes = new Dimension (60, 60);
for (i = 0 ; i < 4 ; i++)
{
buttons [i] = new JButton (space [i]);
buttons [i].setPreferredSize (buttonSizes);
buttons [i].addActionListener (this);
p3.add (buttons [i]);
}
answer = new JTextArea (4, 20);
p3.add (answer);
cp.add ("Center", p3);
p1 = new JPanel ();
p1.setLayout (new FlowLayout (FlowLayout.RIGHT, 10, 200));
p2 = new JPanel ();
p2.setLayout (new FlowLayout (FlowLayout.CENTER, 10, 200));
Dimension buttonSize2 = new Dimension (150, 50);
solve = new JButton ("Click to Solve");
solve.setPreferredSize (buttonSize2);
solve.setBackground (Color.red);
p1.add (solve);
cp.add ("West", p1);
Dimension buttonSize = new Dimension (150, 100);
spin = new JButton ("Click to Spin");
spin.setPreferredSize (buttonSize);
spin.setBackground (Color.yellow);
p2.add (spin);
cp.add ("East", p2);
JButton buttonArray[] = {spin, solve, };
Dimension buttonSizess = new Dimension (50, 25);
p4 = new JPanel ();
p4.setLayout (new FlowLayout (FlowLayout.CENTER, 10, 50));
Dimension panel = new Dimension (10, 250);
for (i = 0 ; i < 26 ; i++)
{
button [i] = new JButton (alpa [i]);
p4.setPreferredSize (panel);
p4.add (button [i]);
button [i].addActionListener (this);
}
cp.add ("South", p4);
//adding actionlistener
spin.addActionListener (this);
solve.addActionListener (this);
}
public void actionPerformed (ActionEvent ae)
{
Object source = ae.getSource ();
int a = (int) (Math.random () * 5 + 1);
String letter = " ";
String word = phrase [a];
int position = -1;
if (source == spin)
{
answer.append (clue [a]);
counter += cashh [a];
cashs.setText(""+counter);
times --;
number.setText("" + times);
}
for (int i = 0 ; i < alpa.length ; i++)
{
if (source == button [i])
{
letter = button [i].getText ();
}
}
for (int i = 0 ; i < word.length () ; i++)
{
position = word.indexOf (letter);
}
if (position > -1)
{
buttons [position].setText (letter);
}
} //end actionPerformed
} //WheelofFortuneclass
</code>
this code shows the letters on two rows ... and try doing the answers now if u click the correct letter for many times it shows up so for example if it shows "ruler" in the clue try clicking "K" "I""N""G" many times and it will show up.
also i dont get how to use the .length to clear the clue area with the previous clue every time spin is clicked
--- Update ---
//WheelofFortune import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.lang.Math; public class WheelofFortune extends JApplet implements ActionListener { //button for spin private Container cp; //layout private JLabel label1, cash,cashs, turns, number; //font private JPanel p1, p2, p3, p4, p5, heading, logo, p6; private String alpa[] = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}; private String space[] = {" ", " ", " ", " ", " ", " ", " ", " "}; private JButton buttons[] = new JButton [space.length]; private JButton button[] = new JButton [alpa.length]; private String phrase[] = {"HOUSE", "FISH", "SHIT", "FORD", "KING", "JOB", "", "", "", "", "", "", "", "", "", "", "", "", ""}; private int cashh[] = {100, 200, 300, 400, 500, 600, 700, 800, 900}; private String clue[] = {"place where you live", "lives in water", "washroom", "makes car", "ruler", "work"}; private JButton spin, solve; private JTextArea answer; int i = 0; int counter = 0; int times = 0; public void init () { cp = getContentPane (); String name = "Wheel of Fortune"; String names = "Cash:"; String turnsRemaining = "Turns Remaining: "; String numberRemaining = "-5"; cash = new JLabel (names); cash.setFont (new Font ("Agency FB", Font.BOLD, 30)); cashs = new JLabel ("" + counter); cashs.setLayout (new FlowLayout (FlowLayout.LEFT, 100, 11)); cp.add(cashs); label1 = new JLabel (name); label1.setFont (new Font ("Agency FB", Font.BOLD, 30)); heading = new JPanel (); heading.setLayout (new FlowLayout (FlowLayout.RIGHT, 5, 25)); heading.add (cash); turns = new JLabel (turnsRemaining); number = new JLabel (numberRemaining); p6 = new JPanel (); turns.setFont (new Font ("Agency FB", Font.BOLD, 30)); p6.setLayout (new FlowLayout (FlowLayout.RIGHT, 250, 11)); p6.add (turns); p6.add (number); logo = new JPanel (); logo.add (label1); logo.add (heading); heading.add (p6); logo.setLayout (new FlowLayout (FlowLayout.LEFT, 10, 11)); cp.add ("North", logo); p3 = new JPanel (); p3.setLayout (new FlowLayout (FlowLayout.CENTER, 10, 100)); Dimension buttonSizes = new Dimension (60, 60); for (i = 0 ; i < 4 ; i++) { buttons [i] = new JButton (space [i]); buttons [i].setPreferredSize (buttonSizes); buttons [i].addActionListener (this); p3.add (buttons [i]); } answer = new JTextArea (4, 20); p3.add (answer); cp.add ("Center", p3); p1 = new JPanel (); p1.setLayout (new FlowLayout (FlowLayout.RIGHT, 10, 200)); p2 = new JPanel (); p2.setLayout (new FlowLayout (FlowLayout.CENTER, 10, 200)); Dimension buttonSize2 = new Dimension (150, 50); solve = new JButton ("Click to Solve"); solve.setPreferredSize (buttonSize2); solve.setBackground (Color.red); p1.add (solve); cp.add ("West", p1); Dimension buttonSize = new Dimension (150, 100); spin = new JButton ("Click to Spin"); spin.setPreferredSize (buttonSize); spin.setBackground (Color.yellow); p2.add (spin); cp.add ("East", p2); JButton buttonArray[] = {spin, solve, }; Dimension buttonSizess = new Dimension (50, 25); p4 = new JPanel (); p4.setLayout (new FlowLayout (FlowLayout.CENTER, 10, 50)); Dimension panel = new Dimension (10, 250); for (i = 0 ; i < 26 ; i++) { button [i] = new JButton (alpa [i]); p4.setPreferredSize (panel); p4.add (button [i]); button [i].addActionListener (this); } cp.add ("South", p4); //adding actionlistener spin.addActionListener (this); solve.addActionListener (this); } public void actionPerformed (ActionEvent ae) { Object source = ae.getSource (); int a = (int) (Math.random () * 5 + 1); String letter = " "; String word = phrase [a]; int position = -1; if (source == spin) { answer.append (clue [a]); counter += cashh [a]; cashs.setText(""+counter); times --; number.setText("" + times); } for (int i = 0 ; i < alpa.length ; i++) { if (source == button [i]) { letter = button [i].getText (); } } for (int i = 0 ; i < word.length () ; i++) { position = word.indexOf (letter); } if (position > -1) { buttons [position].setText (letter); } } //end actionPerformed } //WheelofFortuneclass
this code shows the letters on two rows ... and try doing the answers now if u click the correct letter for many times it shows up so for example if it shows "ruler" in the clue try clicking "K" "I""N""G" many times and it will show up.
also i dont get how to use the .length to clear the clue area with the previous clue every time spin is clicked
--- Update ---
yes yes yes that exactly whats supposed to happen! how do i do that?
--- Update ---
this is one part of what i have to do ..
The layout does not work for me. The empty buttons are only partially shown.
The spin and solve buttons are missing.
The answer text field is not shown
The posted code has lost its formatting. There is no indentation for nested statements. Please fix the formatting.
If you don't understand my answer, don't ignore it, ask a question.
how small is ur screen? try making the applet size bigger 1200 * 1200
Screen 1024 x 600
If you don't understand my answer, don't ignore it, ask a question.
mine is 1024 * 768 and it works fine
You have 168 move vertical pixels.
If you don't understand my answer, don't ignore it, ask a question.