Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2009
    Posts
    22
    Rep Power
    0

    Default help me about Interface



    I want user GridBagLayout.

    Because I learning about GridBagLayout should I create three Panel to container at Controls.

    JPanel1 container JButton:1,2,3,+;
    JPanel2 container JButton:4,7,0;
    JPanel3 container the left JButton.

    I hope everyone help me about learn.

    other, you can to speak for me edit distance from container to JFrame

    Java Code:
    import javax.swing.*;
    import javax.swing.JTextField;
    import java.awt.*;
    
    public class ToCalculator extends JFrame
    {
           
            private JMenuBar menuBar;
            private JMenu file,view,help;
            private JMenuItem mnew,exit,colorred, colorblue,colordefalt,helpitem;
            private JTextField input;
           
            private JButton btn[],btnSum, btnSub, btnDiv, btnMul, btnEqual,btnSqrt,btnSquare;
            private String str[] = {"0","1","2","3","4","5","6","7","8","9"};
            private GridBagLayout gridBagLayout;
            private GridBagConstraints gridBagConstraint;
            private Container container;
           
            // khai bao 3 panel d? ch?a các nút tuong ?ng
            private JPanel panel123,p;
            private JPanel panel470;
            private JPanel panel5689;
            public ToCalculator()
            {
                    //supre must call the first on create function
                    super("Calculator v1.0");
                    this.setBackground(Color.red);
                    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
                   
                    //menu
                    file = new JMenu("File");
                    mnew = new JMenuItem("New");
                    exit = new JMenuItem("Exit");
                    file.add(mnew);
                    file.add(exit);
                   
                    view = new JMenu("View");
                    colorred = new JMenuItem("Red");
                    colorblue = new JMenuItem("Blue");
                    colordefalt = new JMenuItem("Default");
                    view.add(colorred)      ;
                    view.add(colorblue);
                    view.add(colordefalt);
                           
                    help = new JMenu("Help");
                    helpitem = new JMenuItem("Help");
                    help.add(helpitem);
                   
                    menuBar = new JMenuBar();
           
                    menuBar.add(file);
                    menuBar.add(view);
                    menuBar.add(help);
                    setJMenuBar(menuBar);
                   
                    //layout
                    btnEqual = new JButton("=");
                    btnDiv = new JButton("/");
                    btnMul = new JButton("*");
                    btnSquare = new JButton("x^2");
                    btnSqrt = new JButton("Sqrt");
                    btnSub = new JButton("-");
                    btnSum = new JButton("+");
                   
                    btn = new JButton[str.length];
                    for(int i = 0;i<str.length;i++)        
                    {
                            btn = new JButton(str);
                    }
                   
                    panel123 = new JPanel( new GridLayout(1,4));
                    panel123.add(btn[1]);
                    panel123.add(btn[2]);
                    panel123.add(btn[3]);
                    panel123.add(btnSum);
                   
                    panel470 = new JPanel(new GridLayout(3,1));
                    panel470.add(btn[4]);
                    panel470.add(btn[7]);
                    panel470.add(btn[0]);
                   
                    panel5689 = new JPanel( new GridLayout(3,3));
                    panel5689.add(btn[5]);
                    panel5689.add(btn[6]);
                    panel5689.add(btnSub);
                    panel5689.add(btn[8]);
                    panel5689.add(btn[9]);
                    panel5689.add(btnMul);
                    panel5689.add(btnSqrt);
                    panel5689.add(btnSquare);
                    panel5689.add(btnDiv);
                   
                    input = new JTextField(20);
                                   
                    gridBagLayout = new GridBagLayout();
                    container = this.getContentPane();
                    container.setLayout(gridBagLayout);
                   
                    gridBagConstraint = new GridBagConstraints();
                    //add test field
                    gridBagConstraint.gridy = 0;
                    gridBagConstraint.gridx = 0;
                    gridBagConstraint.gridwidth = 2;
                    gridBagConstraint.gridheight = 1;
                    container.add(input,gridBagConstraint);
                   
                    gridBagConstraint.gridy =1;
                    gridBagConstraint.gridx = 0;
                    gridBagConstraint.gridwidth = 2;
                    gridBagConstraint.gridheight = 1;
                    container.add(panel123,gridBagConstraint);
                   
                    gridBagConstraint.gridy = 2;
                    gridBagConstraint.gridx = 0;
                    gridBagConstraint.gridwidth = 1;
                    gridBagConstraint.gridheight = 1;
                    container.add(panel470,gridBagConstraint);
                   
                    gridBagConstraint.gridx = 1;
                    gridBagConstraint.gridwidth = 1;
                    gridBagConstraint.gridheight = 1;
                    container.add(panel5689,gridBagConstraint);
                   
                    //to display Frame, must call the end on create function
                    pack();
                    setVisible(true);              
            }
    }
    I want


    thank everyone
    Last edited by manhtungtnk28@gmail.com; 11-23-2009 at 09:55 AM.
    :D I'm from vietnam - I hope you help me :D

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default

    You've flooded the forum. IgnoreList++
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    sky
    sky is offline Member
    Join Date
    Nov 2009
    Posts
    96
    Rep Power
    0

    Default

    There is no need to post this twice. Maybe a BorderLayout + GridLayout on the center could be more helpful.

  4. #4
    Join Date
    Nov 2009
    Posts
    22
    Rep Power
    0

    Default

    java - why java techology hard
    :D I'm from vietnam - I hope you help me :D

Similar Threads

  1. How do I use an Interface for this?
    By aaronfsimons in forum New To Java
    Replies: 14
    Last Post: 06-22-2009, 03:19 PM
  2. Interface?
    By MarkWilson in forum New To Java
    Replies: 4
    Last Post: 07-11-2008, 10:10 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
  •