Results 1 to 2 of 2
  1. #1
    fritz1474 is offline Member
    Join Date
    Sep 2008
    Posts
    8
    Rep Power
    0

    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 03:29 AM. Reason: unknown reason

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

    Default

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

Similar Threads

  1. What are the hot java frames works on demand
    By mallaravi in forum Web Frameworks
    Replies: 1
    Last Post: 10-28-2008, 01:34 PM
  2. Help needed in Frames text alignment
    By ravjot28 in forum Java Applets
    Replies: 2
    Last Post: 06-27-2008, 04:42 PM
  3. Editing video frames in JMF
    By russ2620 in forum Networking
    Replies: 0
    Last Post: 05-30-2008, 11:26 PM
  4. Help with Grid Layout
    By coco in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 08:03 PM
  5. will java webBrowser work with frames
    By elipford in forum New To Java
    Replies: 2
    Last Post: 06-04-2007, 03:26 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
  •