• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 16:47
CET 22:47
KST 06:47
  • 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
Weekly Cups (Nov 24-30): MaxPax, Clem, herO win2BGE Stara Zagora 2026 announced15[BSL21] Ro.16 Group Stage (C->B->A->D)4Weekly Cups (Nov 17-23): Solar, MaxPax, Clem win3RSL Season 3: RO16 results & RO8 bracket13
StarCraft 2
General
Chinese SC2 server to reopen; live all-star event in Hangzhou Maestros of the Game: Live Finals Preview (RO4) BGE Stara Zagora 2026 announced Weekly Cups (Nov 24-30): MaxPax, Clem, herO win SC2 Proleague Discontinued; SKT, KT, SGK, CJ disband
Tourneys
RSL Offline Finals Info - Dec 13 and 14! Sparkling Tuna Cup - Weekly Open Tournament StarCraft Evolution League (SC Evo Biweekly) Sea Duckling Open (Global, Bronze-Diamond) $5,000+ WardiTV 2025 Championship
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 502 Negative Reinforcement Mutation # 501 Price of Progress Mutation # 500 Fright night Mutation # 499 Chilling Adaptation
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ Foreign Brood War Data analysis on 70 million replays BW General Discussion MBCGame Torrents
Tourneys
Small VOD Thread 2.0 [Megathread] Daily Proleagues [BSL21] RO16 Group D - Sunday 21:00 CET [BSL21] RO16 Group A - Saturday 21:00 CET
Strategy
Current Meta Game Theory for Starcraft How to stay on top of macro? PvZ map balance
Other Games
General Games
Nintendo Switch Thread Stormgate/Frost Giant Megathread Path of Exile ZeroSpace Megathread The Perfect Game
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
Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread US Politics Mega-thread European Politico-economics QA Mega-thread The Big Programming Thread
Fan Clubs
White-Ra Fan Club
Media & Entertainment
Anime Discussion Thread [Manga] One Piece Movie Discussion!
Sports
2024 - 2026 Football Thread Formula 1 Discussion
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
I decided to write a webnov…
DjKniteX
Physical Exertion During Gam…
TrAiDoS
James Bond movies ranking - pa…
Topin
Thanks for the RSL
Hildegard
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1693 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 States24745 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 A
Sziky vs OyAji
Gypsy vs eOnzErG
ZZZero.O377
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
Liquid`TLO 357
White-Ra 239
CosmosSc2 75
Nathanias 67
DisKSc2 44
StarCraft: Brood War
Shuttle 517
ZZZero.O 377
Dewaltoss 117
NaDa 13
Dota 2
Fuzer 441
Counter-Strike
fl0m5200
Super Smash Bros
Mew2King89
Heroes of the Storm
Khaldor255
Other Games
Grubby6588
Mlord725
Beastyqt516
RotterdaM333
Liquid`Hasu255
DeMusliM176
XaKoH 84
Trikslyr66
Livibee39
Organizations
Other Games
EGCTV1416
gamesdonequick761
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 19 non-featured ]
StarCraft 2
• printf 63
• davetesta21
• Reevou 6
• LaughNgamezSOOP
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• sooper7s
• Migwel
StarCraft: Brood War
• 80smullet 12
• Michael_bg 5
• Pr0nogo 2
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Other Games
• imaqtpie1826
• Shiphtur220
• tFFMrPink 14
Upcoming Events
OSC
13m
Solar vs Creator
ByuN vs Gerald
Percival vs Babymarine
Moja vs Krystianer
EnDerr vs ForJumy
sebesdes vs Nicoract
Sparkling Tuna Cup
12h 13m
WardiTV 2025
14h 13m
OSC
17h 13m
IPSL
19h 13m
Bonyth vs KameZerg
BSL 21
22h 13m
Bonyth vs StRyKeR
Tarson vs Dandy
Replay Cast
1d 11h
Wardi Open
1d 14h
StarCraft2.fi
1d 18h
Monday Night Weeklies
1d 19h
[ Show More ]
Replay Cast
2 days
WardiTV 2025
2 days
StarCraft2.fi
2 days
PiGosaur Monday
3 days
StarCraft2.fi
3 days
Tenacious Turtle Tussle
4 days
The PondCast
4 days
WardiTV 2025
4 days
StarCraft2.fi
4 days
WardiTV 2025
5 days
StarCraft2.fi
6 days
RSL Revival
6 days
IPSL
6 days
Sziky vs JDConan
Liquipedia Results

Completed

Proleague 2025-12-04
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
Acropolis #4 - TS3
WardiTV 2025
META Madness #9
Light HT
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

Upcoming

BSL 21 Non-Korean Championship
Acropolis #4
IPSL Spring 2026
Bellum Gens Elite Stara Zagora 2026
HSC XXVIII
Big Gabe Cup #3
RSL Offline Finals
Kuram Kup
PGL Cluj-Napoca 2026
IEM Kraków 2026
BLAST Bounty Winter 2026
BLAST Bounty Winter Qual
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.