• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 07:27
CEST 13:27
KST 20:27
  • 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
[ASL19] Finals Recap: Standing Tall10HomeStory Cup 27 - Info & Preview18Classic wins Code S Season 2 (2025)16Code S RO4 & Finals Preview: herO, Rogue, Classic, GuMiho0TL Team Map Contest #5: Presented by Monster Energy6
Community News
Firefly given lifetime ban by ESIC following match-fixing investigation5$25,000 Streamerzone StarCraft Pro Series announced4Weekly Cups (June 30 - July 6): Classic Doubles6[BSL20] Non-Korean Championship 4x BSL + 4x China9Flash Announces Hiatus From ASL66
StarCraft 2
General
TL Team Map Contest #4: Winners Weekly Cups (June 30 - July 6): Classic Doubles The SCII GOAT: A statistical Evaluation The GOAT ranking of GOAT rankings Firefly given lifetime ban by ESIC following match-fixing investigation
Tourneys
$25,000 Streamerzone StarCraft Pro Series announced FEL Cracov 2025 (July 27) - $8000 live event Sparkling Tuna Cup - Weekly Open Tournament RSL: Revival, a new crowdfunded tournament series WardiTV Mondays
Strategy
How did i lose this ZvP, whats the proper response Simple Questions Simple Answers
Custom Maps
[UMS] Zillion Zerglings
External Content
Mutation # 481 Fear and Lava Mutation # 480 Moths to the Flame Mutation # 479 Worn Out Welcome Mutation # 478 Instant Karma
Brood War
General
ASL20 Preliminary Maps [G] Progamer Settings i aint gon lie to u bruh... BGH Auto Balance -> http://bghmmr.eu/ [ASL19] Finals Recap: Standing Tall
Tourneys
[BSL20] Non-Korean Championship 4x BSL + 4x China [BSL20] Grand Finals - Sunday 20:00 CET CSL Xiamen International Invitational The Casual Games of the Week Thread
Strategy
Simple Questions, Simple Answers I am doing this better than progamers do.
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Path of Exile What do you want from future RTS games? Beyond All Reason
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
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine Summer Games Done Quick 2025! Stop Killing Games - European Citizens Initiative
Fan Clubs
SKT1 Classic Fan Club! Maru Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece [\m/] Heavy Metal Thread
Sports
Formula 1 Discussion 2024 - 2025 Football Thread NBA General Discussion TeamLiquid Health and Fitness Initiative For 2023 NHL Playoffs 2024
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
momentary artworks from des…
tankgirl
Culture Clash in Video Games…
TrAiDoS
from making sc maps to makin…
Husyelt
StarCraft improvement
iopq
Customize Sidebar...

Website Feedback

Closed Threads



Active: 569 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 States24670 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
The PondCast
10:00
Episode 54
CranKy Ducklings86
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
ForJumy 42
StarCraft: Brood War
Britney 20104
firebathero 3575
actioN 1068
Bisu 949
Shuttle 836
Flash 806
Hyuk 473
Larva 440
Mini 371
EffOrt 358
[ Show more ]
Stork 257
Soulkey 206
Soma 198
Zeus 180
Last 170
Snow 151
hero 128
ToSsGirL 126
TY 117
Nal_rA 106
soO 106
Pusan 99
Hyun 79
sas.Sziky 52
sSak 37
sorry 37
Noble 33
Sharp 29
yabsab 27
Rush 26
Sacsri 23
Yoon 15
GoRush 15
JulyZerg 14
zelot 13
Movie 11
JYJ9
IntoTheRainbow 4
ivOry 3
Dota 2
Gorgc6564
XcaliburYe377
League of Legends
singsing2092
Counter-Strike
x6flipin378
chrisJcsgo78
Other Games
tarik_tv26606
gofns8834
shahzam741
B2W.Neo566
DeMusliM371
Fuzer 314
XaKoH 294
crisheroes260
Pyrionflax114
Organizations
Other Games
gamesdonequick32530
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 16 non-featured ]
StarCraft 2
• Berry_CruncH422
• LUISG 15
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• iopq 1
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Dota 2
• lizZardDota2139
League of Legends
• HappyZerGling166
Other Games
• WagamamaTV157
Upcoming Events
uThermal 2v2 Circuit
4h 33m
WardiTV European League
4h 33m
Jumy vs NightPhoenix
Percival vs Nicoract
ArT vs HiGhDrA
MaxPax vs Harstem
Scarlett vs Shameless
SKillous vs uThermal
Replay Cast
12h 33m
RSL Revival
22h 33m
ByuN vs SHIN
Clem vs Reynor
OSC
1d 1h
Replay Cast
1d 12h
RSL Revival
1d 22h
Classic vs Cure
FEL
2 days
OSC
2 days
RSL Revival
2 days
[ Show More ]
FEL
3 days
FEL
3 days
CSO Cup
3 days
BSL20 Non-Korean Champi…
3 days
Bonyth vs QiaoGege
Dewalt vs Fengzi
Hawk vs Zhanhun
Sziky vs Mihu
Mihu vs QiaoGege
Zhanhun vs Sziky
Fengzi vs Hawk
Sparkling Tuna Cup
3 days
RSL Revival
3 days
FEL
4 days
BSL20 Non-Korean Champi…
4 days
Bonyth vs Dewalt
QiaoGege vs Dewalt
Hawk vs Bonyth
Sziky vs Fengzi
Mihu vs Zhanhun
QiaoGege vs Zhanhun
Fengzi vs Mihu
Replay Cast
5 days
Liquipedia Results

Completed

Proleague 2025-07-07
HSC XXVII
Heroes 10 EU

Ongoing

JPL Season 2
BSL 2v2 Season 3
Acropolis #3
KCM Race Survival 2025 Season 2
CSL 17: 2025 SUMMER
Copa Latinoamericana 4
Jiahua Invitational
Championship of Russia 2025
RSL Revival: Season 1
Murky Cup #2
BLAST.tv Austin Major 2025
ESL Impact League Season 7
IEM Dallas 2025
PGL Astana 2025
Asian Champions League '25
BLAST Rivals Spring 2025
MESA Nomadic Masters
CCT Season 2 Global Finals
IEM Melbourne 2025

Upcoming

2025 ACS Season 2: Qualifier
CSLPRO Last Chance 2025
CSL Xiamen Invitational
2025 ACS Season 2
CSLPRO Chat StarLAN 3
K-Championship
uThermal 2v2 Main Event
SEL Season 2 Championship
FEL Cracov 2025
Esports World Cup 2025
Underdog Cup #2
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual
IEM Cologne 2025
FISSURE Playground #1
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.