Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-04-2008, 08:02 AM
bobleny's Avatar
Member
 
Join Date: Apr 2008
Posts: 36
bobleny is on a distinguished road
[SOLVED] Building a nice GUI applet?
Hi, me again!
I'm trying to work on a GUI applet for a program, but I'm dead in the water...

I'm trying to do a GridBagLayout because I think that is exactly what I need.
I don't know why, but it doesn't work?

Code:
import java.awt.Color; import java.awt.Container; import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.JApplet; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JTextField; public class AppTest extends JApplet { Font font01 = new Font("Helvetica", Font.BOLD, 20); Font font02 = new Font("Courier New", Font.PLAIN, 14); public void init() { Container window = getContentPane(); GridBagConstraints c = new GridBagConstraints(); GridBagLayout grid = new GridBagLayout(); window.setLayout(grid); window.setBackground(Color.WHITE); { JLabel label01 = new JLabel("Hang Man!"); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 2; c.gridy = 0; label01.setFont(font01); window.add(label01, c); } { JLabel label03 = new JLabel("Guess a Letter: "); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 1; c.gridy = 1; label03.setFont(font02); window.add(label03); } { JTextField field01 = new JTextField(2); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 2; c.gridy = 1; field01.setFont(font02); window.add(field01); } { JButton button01 = new JButton("Guess!"); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 3; c.gridy = 1; button01.setFont(font02); window.add(button01); } { JButton button01 = new JButton("Next Phrase ->"); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 3; c.gridy = 2; button01.setFont(font02); window.add(button01); } } }

What am I doing wrong?

Thanks!
__________________
-- www.firemelt.net --
Cheer up, the worst has yet to come...
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-04-2008, 08:22 AM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 218
Zosden is on a distinguished road
Look at this video if it doesn't help at least you will have a laugh. Link
__________________
Definition of Impossible = making a good game in Java.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-04-2008, 08:52 AM
Senior Member
 
Join Date: Jul 2007
Posts: 930
hardwired is on a distinguished road
Code:
// <applet code="AppletTest" width="400" height="400"></applet> import java.awt.Color; import java.awt.Container; import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import javax.swing.JApplet; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JTextField; public class AppletTest extends JApplet { Font font01 = new Font("Helvetica", Font.BOLD, 20); Font font02 = new Font("Courier New", Font.PLAIN, 14); public void init() { Container window = getContentPane(); GridBagConstraints c = new GridBagConstraints(); c.weightx = 1.0; // horizontal dispersion c.weighty = 1.0; // vertical dispersion GridBagLayout grid = new GridBagLayout(); window.setLayout(grid); window.setBackground(Color.WHITE); JLabel label01 = new JLabel("Hang Man!", JLabel.CENTER); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridy = 0; c.gridwidth = 3; c.anchor = GridBagConstraints.NORTH; label01.setFont(font01); window.add(label01, c); JLabel label03 = new JLabel("Guess a Letter: "); // c.fill = GridBagConstraints.HORIZONTAL; c.fill = GridBagConstraints.NONE; c.gridx = 0; c.gridy = 1; c.gridwidth = 1; c.anchor = GridBagConstraints.EAST; label03.setFont(font02); window.add(label03, c); JTextField field01 = new JTextField(2); // c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 1; c.gridy = 1; c.anchor = GridBagConstraints.WEST; field01.setFont(font02); window.add(field01, c); JButton button1 = new JButton("Guess!"); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 2; c.gridy = 1; c.anchor = GridBagConstraints.CENTER; button1.setFont(font02); window.add(button1, c); JButton button2 = new JButton("Next Phrase ->"); // c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 2; c.gridy = 2; c.gridwidth = 3; button2.setFont(font02); window.add(button2, c); } }
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-09-2008, 08:42 PM
bobleny's Avatar
Member
 
Join Date: Apr 2008
Posts: 36
bobleny is on a distinguished road
Hey, thanks! It works!
__________________
-- www.firemelt.net --
Cheer up, the worst has yet to come...
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
building a house dc2acgsr99 Java Applets 4 03-08-2008 12:18 AM
Building a document from a DOM Java Tip Java Tips 0 01-03-2008 10:22 AM
Problem with String Building Albert New To Java 0 07-09-2007 08:20 PM
Building A Java Project In Eclipse JavaForums Eclipse 0 05-22-2007 10:34 PM
help needed regarding tree building invincible_me New To Java 1 04-29-2007 11:39 AM


All times are GMT +3. The time now is 10:50 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org