Results 1 to 4 of 4
- 05-04-2008, 07:02 AM #1
[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?
Java 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...
- 05-04-2008, 07:22 AM #2
Look at this video if it doesn't help at least you will have a laugh. Link
My IP address is 127.0.0.1
- 05-04-2008, 07:52 AM #3
Java 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); } }
- 05-09-2008, 07:42 PM #4
Similar Threads
-
Problem with String Building
By Albert in forum New To JavaReplies: 2Last Post: 04-30-2012, 12:49 AM -
help needed regarding tree building
By invincible_me in forum New To JavaReplies: 2Last Post: 08-12-2008, 01:44 PM -
building a house
By dc2acgsr99 in forum Java AppletsReplies: 4Last Post: 03-07-2008, 11:18 PM -
Building a document from a DOM
By Java Tip in forum Java TipReplies: 0Last Post: 01-03-2008, 09:22 AM -
Building A Java Project In Eclipse
By JavaForums in forum EclipseReplies: 0Last Post: 05-22-2007, 09:34 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks