• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 17:23
CET 23:23
KST 07:23
  • 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
RSL Season 3 - Playoffs Preview0RSL Season 3 - RO16 Groups C & D Preview0RSL Season 3 - RO16 Groups A & B Preview2TL.net Map Contest #21: Winners12Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10
Community News
BGE Stara Zagora 2026 announced11[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3RSL Season 3: RO16 results & RO8 bracket13Weekly Cups (Nov 10-16): Reynor, Solar lead Zerg surge2
StarCraft 2
General
BGE Stara Zagora 2026 announced SC: Evo Complete - Ranked Ladder OPEN ALPHA When will we find out if there are more tournament Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win Weekly Cups (Nov 10-16): Reynor, Solar lead Zerg surge
Tourneys
RSL Revival: Season 3 Constellation Cup - Main Event - Stellar Fest Tenacious Turtle Tussle [Alpha Pro Series] Nice vs Cure $5,000+ WardiTV 2025 Championship
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 501 Price of Progress Mutation # 500 Fright night Mutation # 499 Chilling Adaptation Mutation # 498 Wheel of Misfortune|Cradle of Death
Brood War
General
BW General Discussion BGH Auto Balance -> http://bghmmr.eu/ A cwal.gg Extension - Easily keep track of anyone Which season is the best in ASL? soO on: FanTaSy's Potential Return to StarCraft
Tourneys
[Megathread] Daily Proleagues [BSL21] RO16 Group B - Sunday 21:00 CET [BSL21] RO16 Group C - Saturday 21:00 CET Small VOD Thread 2.0
Strategy
Game Theory for Starcraft How to stay on top of macro? Current Meta PvZ map balance
Other Games
General Games
Nintendo Switch Thread The Perfect Game Stormgate/Frost Giant Megathread Beyond All Reason Should offensive tower rushing be viable in RTS games?
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
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
Mafia Game Mode Feedback/Ideas TL Mafia Community Thread
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread The Big Programming Thread Things Aren’t Peaceful in Palestine Artificial Intelligence Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
[Manga] One Piece Movie Discussion! Anime Discussion Thread
Sports
2024 - 2026 Football Thread Formula 1 Discussion NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
Where to ask questions and add stream? The Automated Ban List
Blogs
Esports Earnings: Bigger Pri…
TrAiDoS
Thanks for the RSL
Hildegard
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Customize Sidebar...

Website Feedback

Closed Threads



Active: 3011 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 States24743 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
BSL 21
20:00
RO16: Group C
TerrOr vs Dewalt
Semih vs Tech
ZZZero.O289
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
PiGStarcraft501
JuggernautJason96
ROOTCatZ 70
StarCraft: Brood War
ZZZero.O 273
Shinee 84
NaDa 22
ivOry 2
Dota 2
syndereN490
Other Games
Grubby6378
FrodaN2869
tarik_tv563
RotterdaM245
Pyrionflax202
KnowMe178
Sick165
Mew2King95
ViBE29
Organizations
Other Games
gamesdonequick3415
Dota 2
PGL Dota 2 - Main Stream162
Other Games
BasetradeTV108
angryscii15
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 19 non-featured ]
StarCraft 2
• HeavenSC 41
• musti20045 32
• IndyKCrew
• Migwel
• AfreecaTV YouTube
• sooper7s
• intothetv
• Kozan
• LaughNgamezSOOP
StarCraft: Brood War
• FirePhoenix15
• RayReign 1
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• masondota21561
• Ler97
Other Games
• imaqtpie2232
• Shiphtur231
• tFFMrPink 11
Upcoming Events
Sparkling Tuna Cup
11h 37m
WardiTV Korean Royale
13h 37m
Zoun vs SHIN
TBD vs Reynor
TBD vs herO
Solar vs TBD
BSL 21
21h 37m
Hawk vs Kyrie
spx vs Cross
Replay Cast
1d 1h
Wardi Open
1d 13h
Monday Night Weeklies
1d 18h
StarCraft2.fi
1d 18h
Replay Cast
2 days
Wardi Open
2 days
StarCraft2.fi
2 days
[ Show More ]
PiGosaur Monday
3 days
Wardi Open
3 days
StarCraft2.fi
3 days
Replay Cast
4 days
The PondCast
4 days
Replay Cast
5 days
Korean StarCraft League
6 days
CranKy Ducklings
6 days
SC Evo League
6 days
BSL 21
6 days
Sziky vs OyAji
Gypsy vs eOnzErG
Liquipedia Results

Completed

SOOP Univ League 2025
RSL Revival: Season 3
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
YSL S2
BSL Season 21
CSCL: Masked Kings S3
Slon Tour Season 2
META Madness #9
SL Budapest Major 2025
ESL Impact League Season 8
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 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.