• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 17:27
CET 23:27
KST 07: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
RSL 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[ASL20] Finals Preview: Arrival13
Community News
[TLMC] Fall/Winter 2025 Ladder Map Rotation12Weekly Cups (Nov 3-9): Clem Conquers in Canada4SC: Evo Complete - Ranked Ladder OPEN ALPHA8StarCraft, SC2, HotS, WC3, Returning to Blizzcon!45$5,000+ WardiTV 2025 Championship7
StarCraft 2
General
Mech is the composition that needs teleportation t RotterdaM "Serral is the GOAT, and it's not close" RSL Season 3 - RO16 Groups C & D Preview [TLMC] Fall/Winter 2025 Ladder Map Rotation TL.net Map Contest #21: Winners
Tourneys
RSL Revival: Season 3 Sparkling Tuna Cup - Weekly Open Tournament Constellation Cup - Main Event - Stellar Fest Tenacious Turtle Tussle Master Swan Open (Global Bronze-Master 2)
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 499 Chilling Adaptation Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened Mutation # 496 Endless Infection
Brood War
General
FlaSh on: Biggest Problem With SnOw's Playstyle What happened to TvZ on Retro? SnOw's ASL S20 Finals Review BW General Discussion Brood War web app to calculate unit interactions
Tourneys
[Megathread] Daily Proleagues Small VOD Thread 2.0 [BSL21] RO32 Group D - Sunday 21:00 CET [BSL21] RO32 Group C - Saturday 21:00 CET
Strategy
PvZ map balance Current Meta Simple Questions, Simple Answers How to stay on top of macro?
Other Games
General Games
Should offensive tower rushing be viable in RTS games? Path of Exile Stormgate/Frost Giant Megathread Nintendo Switch Thread Clair Obscur - Expedition 33
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
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread US Politics Mega-thread Artificial Intelligence Thread Canadian Politics Mega-thread
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
Movie Discussion! [Manga] One Piece Anime Discussion Thread Korean Music Discussion Series you have seen recently...
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
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List
Blogs
Dyadica Gospel – a Pulp No…
Hildegard
Coffee x Performance in Espo…
TrAiDoS
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Reality "theory" prov…
perfectspheres
Customize Sidebar...

Website Feedback

Closed Threads



Active: 2102 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 States24740 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 PiG Daily
20:30
Best Games of SC
Serral vs Clem
Solar vs Cure
Serral vs Clem
Reynor vs GuMiho
herO vs Cure
PiGStarcraft322
LiquipediaDiscussion
BSL 21
20:00
ProLeague - RO32 Group C
Tarson vs Julia
Doodle vs OldBoy
eOnzErG vs WolFix
StRyKeR vs Aeternum
ZZZero.O323
LiquipediaDiscussion
OSC
19:00
Masters Cup #150: Group B
davetesta56
Liquipedia
PSISTORM Gaming Misc
15:55
FSL teamleague CNvsASH, ASHvRR
Liquipedia
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
PiGStarcraft322
Nathanias 119
ProTech70
StarCraft: Brood War
Shuttle 935
ZZZero.O 323
NaDa 58
Dota 2
LuMiX1
Counter-Strike
fl0m1107
Super Smash Bros
AZ_Axe111
Other Games
tarik_tv6434
Grubby5300
summit1g4453
gofns4093
DeMusliM420
Pyrionflax195
Fuzer 191
Dewaltoss14
ViBE11
Organizations
Other Games
EGCTV935
gamesdonequick798
StarCraft 2
angryscii 33
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 19 non-featured ]
StarCraft 2
• StrangeGG 58
• musti20045 19
• Dystopia_ 3
• IndyKCrew
• Migwel
• AfreecaTV YouTube
• sooper7s
• intothetv
• Kozan
• LaughNgamezSOOP
StarCraft: Brood War
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• masondota2715
• Ler80
Other Games
• imaqtpie1667
• WagamamaTV495
• Shiphtur261
• tFFMrPink 13
Upcoming Events
Sparkling Tuna Cup
11h 33m
RSL Revival
11h 33m
Reynor vs sOs
Maru vs Ryung
Kung Fu Cup
13h 33m
Cure vs herO
Reynor vs TBD
WardiTV Korean Royale
13h 33m
BSL 21
21h 33m
JDConan vs Semih
Dragon vs Dienmax
Tech vs NewOcean
TerrOr vs Artosis
IPSL
21h 33m
Dewalt vs WolFix
eOnzErG vs Bonyth
Replay Cast
1d
Wardi Open
1d 13h
Monday Night Weeklies
1d 18h
WardiTV Korean Royale
2 days
[ Show More ]
BSL: GosuLeague
2 days
The PondCast
3 days
Replay Cast
4 days
RSL Revival
4 days
BSL: GosuLeague
4 days
RSL Revival
5 days
WardiTV Korean Royale
5 days
RSL Revival
6 days
WardiTV Korean Royale
6 days
IPSL
6 days
Julia vs Artosis
JDConan vs DragOn
Liquipedia Results

Completed

Proleague 2025-11-14
Stellar Fest: Constellation Cup
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
BSL Season 21
CSCL: Masked Kings S3
SLON Tour Season 2
RSL Revival: Season 3
META Madness #9
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
BLAST Open Fall 2025

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
HSC XXVIII
RSL Offline Finals
WardiTV 2025
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 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.