Results 1 to 4 of 4
Thread: help me about Interface
- 11-23-2009, 08:47 AM #1
Member
- Join Date
- Nov 2009
- Posts
- 22
- Rep Power
- 0
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
I wantJava 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); } }
thank everyoneLast edited by manhtungtnk28@gmail.com; 11-23-2009 at 08:55 AM.
:D I'm from vietnam - I hope you help me :D
- 11-23-2009, 08:59 AM #2
You've flooded the forum. IgnoreList++
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 11-23-2009, 12:56 PM #3
Member
- Join Date
- Nov 2009
- Posts
- 96
- Rep Power
- 0
There is no need to post this twice. Maybe a BorderLayout + GridLayout on the center could be more helpful.
- 11-23-2009, 05:15 PM #4
Member
- Join Date
- Nov 2009
- Posts
- 22
- Rep Power
- 0
Similar Threads
-
How do I use an Interface for this?
By aaronfsimons in forum New To JavaReplies: 14Last Post: 06-22-2009, 02:19 PM -
Interface?
By MarkWilson in forum New To JavaReplies: 4Last Post: 07-11-2008, 09:10 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks