Please help i have added buttons but they aren't how i want them.....how do i change the letters to squares and how i want them? and at the very bottom i am confused with what to do next thanks for anyhelp

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.JOptionPane;

public class MyHangman extends Applet  {

private boolean usd[] = new boolean[26];

private String guess;

private int numguesses = 0;

private boolean finished = false;

private boolean won = false;

private Button b[];

char secretWord[];
public void init() {

int a;
StringBuffer buff = new StringBuffer();

setLayout ( new GridLayout(83,1));
b = new Button[26];

for(a = 0; a < 26; a++)
buff = new StringBuffer();
b[a] = new Button(buff.toString());

add(b[a]);//adds all of the buttons
//guess = getParameter("wrd").toUpperCase();



StringBuffer wrong = new StringBuffer();

for (int l = 0; l<=25; l++) {
if (usd[l]) wrong.append((char)(l+65));
else wrong.append(".");


g.setColor(Color.green);//Setting up the incorrect guessed letters

Font f = new Font("Palatino",Font.BOLD+Font.ITALIC,65);
g.drawString(wrong.toString(),300,850);//end of writing the wrong letters

StringBuffer right = new StringBuffer();

Font ff = new Font("Palatino",Font.BOLD,85);


for (int ii = 0; ii < guess.length(); ii++)
right.append(guess.charAt(ii));//Marks down the right answers
right.append(".");  //If the same letter is used twice it won't be put down
//or counted


Edited by happygeek: fixed formatting

8 Years
Discussion Span
Last Post by Futbol10

A lot of your code is drifting outside of a method or most likely outside of the init/start methods so you're going to have some errors trying to compile.

Also if you want to change the way components look in your GUI you will have to use a different LayoutManager or the dreaded absolute-positioning idea which I don't recommend. The 2nd-worst case scenerio would be using the GridBagLayout which is the hardest LayoutManager to use (which, actually, implements absolute positioning to a point but makes things easier for you).

Your best bet is to use a FlowLayout for simplicity.

I changed your new GridLayout(83, 1) line to new FlowLayout(), as well as adding the standard applet start method--

public void start()

--and added the rest of the code in there.

Furthermore your g and guess values are null. You should initialize them before going any further.


Thanks man ill try that out and see where i can get ive been honestly taking some code from a guy while trying to add my own and even when i use his exact code it doesnt run which i dont know is an html problem or just me being an idiot......but i will try this stuff out and research it more because i need to get it done before wednesday :angry:

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.