• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 12:29
CEST 18:29
KST 01:29
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
Maestros of the Game: Week 1/Play-in Preview9[ASL20] Ro24 Preview Pt2: Take-Off7[ASL20] Ro24 Preview Pt1: Runway132v2 & SC: Evo Complete: Weekend Double Feature4Team Liquid Map Contest #21 - Presented by Monster Energy9
Community News
Weekly Cups (August 25-31): Clem's Last Straw?16Weekly Cups (Aug 18-24): herO dethrones MaxPax6Maestros of The Game—$20k event w/ live finals in Paris46Weekly Cups (Aug 11-17): MaxPax triples again!15Weekly Cups (Aug 4-10): MaxPax wins a triple6
StarCraft 2
General
Weekly Cups (August 25-31): Clem's Last Straw? #1: Maru - Greatest Players of All Time Maestros of the Game: Week 1/Play-in Preview Weekly Cups (Aug 11-17): MaxPax triples again! 2024/25 Off-Season Roster Moves
Tourneys
Sparkling Tuna Cup - Weekly Open Tournament Maestros of The Game—$20k event w/ live finals in Paris Monday Nights Weeklies LiuLi Cup - September 2025 Tournaments 🏆 GTL Season 2 – StarCraft II Team League
Strategy
Custom Maps
External Content
Mutation # 489 Bannable Offense Mutation # 488 What Goes Around Mutation # 487 Think Fast Mutation # 486 Watch the Skies
Brood War
General
No Rain in ASL20? ASL20 General Discussion Starcraft at lower levels TvP Victoria gamers BGH Auto Balance -> http://bghmmr.eu/
Tourneys
Is there English video for group selection for ASL [ASL20] Ro24 Group F [IPSL] CSLAN Review and CSLPRO Reimagined! Small VOD Thread 2.0
Strategy
Simple Questions, Simple Answers Muta micro map competition Fighting Spirit mining rates [G] Mineral Boosting
Other Games
General Games
Nintendo Switch Thread Stormgate/Frost Giant Megathread Mechabellum Teeworlds - online game General RTS Discussion Thread
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread Vanilla Mini Mafia
Community
General
Things Aren’t Peaceful in Palestine US Politics Mega-thread Russo-Ukrainian War Thread Canadian Politics Mega-thread YouTube Thread
Fan Clubs
The Happy Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece [\m/] Heavy Metal Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread High temperatures on bridge(s) Gtx660 graphics card replacement
TL Community
The Automated Ban List TeamLiquid Team Shirt On Sale
Blogs
A very expensive lesson on ma…
Garnet
hello world
radishsoup
Lemme tell you a thing o…
JoinTheRain
How Culture and Conflict Imp…
TrAiDoS
RTS Design in Hypercoven
a11
Evil Gacha Games and the…
ffswowsucks
INDEPENDIENTE LA CTM
XenOsky
Customize Sidebar...

Website Feedback

Closed Threads



Active: 773 users

Java HELP

Blogs > alphafuzard
Post a Reply
alphafuzard
Profile Blog Joined June 2007
United States1610 Posts
June 07 2008 21:05 GMT
#1
I have to write a program for my final project
I chose to do a hangman game, but im running into a few problems ~_~
It's an applet, and I am trying to add in a text box for the user to enter in the letters they are going to guess.

I am fairly new to applets and gui, and ive been sort of trying to guess my way through using the text book and checking open source hangman games.

i want to add the text box either above or below the gallows image. Any gosu programmer help me out plz?
here is my pitiful program so far
+ Show Spoiler +
/**
* @(#)HangmanGame.java
*
* HangmanGame Applet application
*
* @author
* @version 1.00 2008/6/7
*/

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

public class HangmanGame extends Applet{

int wrongguesses = 0;

String word = ("intuitive");
String line = ("---------");

public void init() {
JTextField guessletter = new JTextField(1);
JPanel panel = new JPanel ();
panel.setBackground(Color.yellow);
panel.setPreferredSize(new Dimension(300, 75));
panel.add(guessletter);
JFrame frame = new JFrame ("Letter");

//frame.getContentPane().add (panel);

}

public void paint(Graphics page) {

setBackground(Color.white);
page.fillRect(10, 250, 150, 20);
page.fillRect(40,70,10,200);
page.fillRect(40,70,60,10);
page.fillRect(95,70,5,25);

Font abc = new Font("Courier",Font.BOLD,36);
page.setFont(abc);
page.drawString (line, 100, 230);
}
}


**
more weight
h3r1n6
Profile Blog Joined September 2007
Iceland2039 Posts
Last Edited: 2008-06-07 21:15:43
June 07 2008 21:15 GMT
#2
The frame needs to know, that the Panel you created is the right panel. So you should invoke setContentPane(panel) on the JFrame.

Then you can use different LayoutManagers to make the Layout. For your case a null layout will be suitable, where you just tell the components where they are. You won't resize the applet anyway and only need 2 components, so no resizing needed, so thats fine.

Night[Mare
Profile Blog Joined December 2004
Mexico4793 Posts
June 07 2008 22:01 GMT
#3
On June 08 2008 06:15 h3r1n6 wrote:
The frame needs to know, that the Panel you created is the right panel. So you should invoke setContentPane(panel) on the JFrame.

Then you can use different LayoutManagers to make the Layout. For your case a null layout will be suitable, where you just tell the components where they are. You won't resize the applet anyway and only need 2 components, so no resizing needed, so thats fine.



if you put the null Layout when you resize the window it will fuck up. Either use a GridbagLayout or BorderLayour. You can find how to use them at the java tutorials.

I also recommend that you post this in the java sun forums. They'll be far more helpful than here.
Teamliquidian townie
micronesia
Profile Blog Joined July 2006
United States24698 Posts
Last Edited: 2008-06-07 22:03:28
June 07 2008 22:03 GMT
#4
On June 08 2008 06:05 alphafuzard wrote:
Any gosu programmer help me out plz?

Sounds to me like you don't need a gosu programmer haha.

In java I made a program years ago which would animate a snake moving around. It was kyoot.
ModeratorThere are animal crackers for people and there are people crackers for animals.
h3r1n6
Profile Blog Joined September 2007
Iceland2039 Posts
June 07 2008 22:23 GMT
#5
On June 08 2008 07:01 RtS)Night[Mare wrote:
if you put the null Layout when you resize the window it will fuck up. Either use a GridbagLayout or BorderLayour. You can find how to use them at the java tutorials.

I also recommend that you post this in the java sun forums. They'll be far more helpful than here.


He said he wants it in an applet, and you don't resize applets, so.


Don't mistake me, I like the Gridbaglayout, but for 2 elements its total overkill. And yes, actual programmer forums will be more helpfull than this.
city42
Profile Joined October 2007
1656 Posts
Last Edited: 2008-06-07 22:47:47
June 07 2008 22:46 GMT
#6
I have no experience in applets so I have no clue if any of this is valid:

If you're trying to get some organization to your GUI, you need to use a layout. The three most common ones are BorderLayout, FlowLayout, and GridLayout, but there more (the java api is your friend). I'll leave it up to you to investigate the others, but BorderLayout is like this:

North

East Center West

South

Let's say you wanted to put the text box above the hangman picture. You'll need to make a JPanel and give it a BorderLayout with the method JPanel.setLayout(new BorderLayout()). Then you'll put whatever you're containing the hangman image in the middle of the layout by using the method JPanel.add(someGUIComponent, BorderLayout.CENTER). Pick some sort of text box (there are a few to choose from) and add it to the north section in a similar fashion. Let's say you use a JTextField and name it textfield, simply do JPanel.add(textfield, BorderLayout.NORTH). That would basically give you something that looks like:

JTextField

Nothing Hangman Picture Nothing

Nothing

but since the other areas of the BorderLayout have nothing, it would appear just as:

JTextField
Hangman Picture

You can pretty much make any layout you want by using layouts within layouts, but I find keeping it as simple as possible to be the way to go.

As for the text box interacting with the user so as to allow them to guess letters, you'd normally use the ActionListener or KeyListener interfaces, but I have no clue if applets run the same way. It'll probably involve getting the user's input, checking to make sure it's a letter (in other words, within a certain range of char values), checking to see if the letter has already been guessed, searching the hangman word to see if the letter is present, and then taking the correct course of action based on the result of the search.

That probably wasn't any help at all but good luck anyway.



Oh crap, my diagrams don't look the same when the post is on the forum.
Please log in or register to reply.
Live Events Refresh
Next event in 7h 32m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mcanning 167
Dewaltoss 43
SC2Nice 29
StarCraft: Brood War
Bisu 1581
Flash 927
EffOrt 707
Mini 491
Stork 473
mouzHeroMarine 389
actioN 222
Soulkey 196
Larva 171
Snow 171
[ Show more ]
ggaemo 168
ZerO 143
Mind 125
hero 122
Soma 95
Barracks 82
Mong 74
Hyun 64
Rush 60
Movie 56
PianO 46
Sharp 40
Nal_rA 38
sSak 36
yabsab 34
JulyZerg 28
sorry 25
JYJ20
zelot 18
HiyA 13
Sacsri 12
soO 11
Shine 9
Terrorterran 8
SilentControl 8
ajuk12(nOOB) 6
ivOry 6
Dota 2
qojqva4095
Dendi1595
420jenkins507
League of Legends
Reynor72
Counter-Strike
byalli305
oskar162
Heroes of the Storm
XaKoH 93
Other Games
FrodaN1014
ceh9381
crisheroes360
Lowko273
Sick176
Mew2King115
SortOf113
Trikslyr60
QueenE55
MindelVK18
ZerO(Twitch)9
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 17 non-featured ]
StarCraft 2
• poizon28 28
• LUISG 9
• Kozan
• LaughNgamezSOOP
• sooper7s
• AfreecaTV YouTube
• Migwel
• intothetv
• IndyKCrew
StarCraft: Brood War
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• C_a_k_e 3467
• WagamamaTV721
League of Legends
• Nemesis3960
• Jankos1424
Counter-Strike
• Shiphtur4
Upcoming Events
PiGosaur Monday
7h 32m
LiuLi Cup
18h 32m
Replay Cast
1d 7h
The PondCast
1d 17h
RSL Revival
1d 17h
Maru vs SHIN
MaNa vs MaxPax
Maestros of the Game
2 days
OSC
2 days
MaNa vs SHIN
SKillous vs ShoWTimE
Bunny vs TBD
Cham vs TBD
RSL Revival
2 days
Reynor vs Astrea
Classic vs sOs
Maestros of the Game
3 days
BSL Team Wars
3 days
Team Bonyth vs Team Dewalt
[ Show More ]
CranKy Ducklings
3 days
RSL Revival
3 days
GuMiho vs Cham
ByuN vs TriGGeR
Cosmonarchy
3 days
TriGGeR vs YoungYakov
YoungYakov vs HonMonO
HonMonO vs TriGGeR
Maestros of the Game
4 days
[BSL 2025] Weekly
4 days
RSL Revival
4 days
Cure vs Bunny
Creator vs Zoun
Maestros of the Game
5 days
BSL Team Wars
5 days
Team Hawk vs Team Sziky
Sparkling Tuna Cup
5 days
Liquipedia Results

Completed

CSL Season 18: Qualifier 2
SEL Season 2 Championship
HCC Europe

Ongoing

Copa Latinoamericana 4
BSL 20 Team Wars
KCM Race Survival 2025 Season 3
BSL 21 Qualifiers
ASL Season 20
CSL 2025 AUTUMN (S18)
Maestros of the Game
Sisters' Call Cup
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
BLAST.tv Austin Major 2025

Upcoming

LASL Season 20
2025 Chongqing Offline CUP
BSL Season 21
BSL 21 Team A
Chzzk MurlocKing SC1 vs SC2 Cup #2
RSL Revival: Season 2
EC S1
BLAST Rivals Fall 2025
Skyesports Masters 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
MESA Nomadic Masters Fall
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.