Results 1 to 4 of 4
  1. #1
    bobleny's Avatar
    bobleny is offline Member
    Join Date
    Apr 2008
    Posts
    50
    Rep Power
    0

    Default [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...

  2. #2
    Zosden's Avatar
    Zosden is offline Senior Member
    Join Date
    Apr 2008
    Posts
    384
    Rep Power
    6

    Default

    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

  3. #3
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    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);
        }
    }

  4. #4
    bobleny's Avatar
    bobleny is offline Member
    Join Date
    Apr 2008
    Posts
    50
    Rep Power
    0

    Default

    Hey, thanks! It works! :D
    -- www.firemelt.net --
    Cheer up, the worst has yet to come...

Similar Threads

  1. Problem with String Building
    By Albert in forum New To Java
    Replies: 2
    Last Post: 04-30-2012, 12:49 AM
  2. help needed regarding tree building
    By invincible_me in forum New To Java
    Replies: 2
    Last Post: 08-12-2008, 01:44 PM
  3. building a house
    By dc2acgsr99 in forum Java Applets
    Replies: 4
    Last Post: 03-07-2008, 11:18 PM
  4. Building a document from a DOM
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-03-2008, 09:22 AM
  5. Building A Java Project In Eclipse
    By JavaForums in forum Eclipse
    Replies: 0
    Last Post: 05-22-2007, 09:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •