Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-14-2008, 11:42 PM
Member
 
Join Date: Sep 2008
Posts: 8
Rep Power: 0
fritz1474 is on a distinguished road
Default Grid layout frames GUI
I am having a problem with creating a calculator. I using JFrames to create a non working calculator that has the text box and the number grid, but the numbers are not coming into the frame. If I remove the text box lines, the numbers are shown. Any help is appreciated...

Here is the code:

Last edited by fritz1474; 10-15-2008 at 04:29 AM. Reason: unknown reason
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 10-15-2008, 03:04 AM
hardwired's Avatar
Senior Member
 
Join Date: Jul 2007
Posts: 1,577
Rep Power: 4
hardwired is on a distinguished road
Default
Code:
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class GLF extends JFrame
{
    private JTextField textField1;
    private JButton[] buttons;
    private final String[] names =
    {
        "7", "8", "9", "/", "4", "5", "6",
        "*","1","2","3","-","0",".","=","+"
    };

    public GLF()
    {
        super( "Calculator" );
        System.out.println("default layout manager for JFrame = " +
                            getLayout().getClass().getName());
        textField1 = new JTextField( 10 );

        textField1.setHorizontalAlignment(JTextField.RIGHT );
        // same as getContentPane().add(textField1,...
        add( textField1,BorderLayout.NORTH );

        JPanel center = new JPanel( new GridLayout(4,4,1,1) );
        buttons = new JButton[ names.length ]; // create array of JButtons

        for ( int count = 0; count < names.length; count++ )
        {
            buttons[ count ] = new JButton( names[ count ] );
            //buttons[ count ].addActionListener( this );
            center.add( buttons[count]);
        }
        add(center, BorderLayout.CENTER);
        pack();
        setVisible(true);
    }

    public static void main(String[] args)
    {
        new GLF();
    }
}
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

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

BB 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
What are the hot java frames works on demand mallaravi Web Frameworks 1 10-28-2008 02:34 PM
Help needed in Frames text alignment ravjot28 Java Applets 2 06-27-2008 05:42 PM
Editing video frames in JMF russ2620 Networking 0 05-31-2008 12:26 AM
Help with Grid Layout coco AWT / Swing 1 08-06-2007 09:03 PM
will java webBrowser work with frames elipford New To Java 2 06-04-2007 04:26 PM


All times are GMT +2. The time now is 09:13 AM.



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