Results 1 to 7 of 7
Thread: Problem regarding "GridLayout"
- 08-11-2010, 01:18 PM #1
Member
- Join Date
- Aug 2010
- Posts
- 15
- Rep Power
- 0
Problem regarding "GridLayout"
Hey all,
plz tell me that how to use the "GridLayout" class in the following code...
i want the size of textarea to be set by me...
but it is not been done here....:(
XML Code:import java.awt.*; import java.awt.event.*; class Demo implements ActionListener { TextField t; Demo(TextField t) { this.t=t; } public void actionPerformed(ActionEvent a) { String s=a.getActionCommand(); t.setText(s); } } class Cal { Cal() { int i; int c=10; Frame f=new Frame(); f.setSize(400,400); Panel p=new Panel(); p.setLayout(new GridLayout(3,2)); Button b[]=new Button[10]; TextField t=new TextField(); Demo d=new Demo(t); for(i=0;i<b.length;i++) { String s=Integer.toString(i); b[i]=new Button(s); b[i].setBounds(i*40,120,30,30); p.add(b[i]); } t.setBounds(30,40,340,40); p.add(t); for(i=0;i<b.length;i++) { b[i].addActionListener(d); } f.add(p); f.setVisible(true); } public static void main(String zx[]) { new Cal(); } }
plzzz do help me...
plzzz....
-
You're using setBounds which shouldn't be used at all if you're using layouts. Rather if you want to set the size of the Buttons held by the GridLayout-using container, then set their preferredSize and don't set the size of the application. Also, since your TextArea is separate from your buttons, best if you place your Buttons in one Panel that uses GridLayout and then place this Button Panel in another Panel using another layout such as BorderLayout, and then add the TextArea to the same BorderLayout using Panel. Most important of all, read the tutorials. By the way, why AWT and not Swing?
- 08-11-2010, 02:49 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
- 08-11-2010, 03:50 PM #4
Member
- Join Date
- Aug 2010
- Posts
- 15
- Rep Power
- 0
- 08-11-2010, 03:52 PM #5
Member
- Join Date
- Aug 2010
- Posts
- 15
- Rep Power
- 0
-
"It didn't work" doesn't help us figure out what you're doing wrong. If you attempt to do something and desire our help, you need to show your attempt and describe in detail how it's not working including posting any error messages that you encounter.
I won't create the code for you, but can guide you to the tutorials that will show you how to use these layouts. They can be found here: Lesson: Laying Out Components Within a Container (The Java™ Tutorials > Creating a GUI With JFC/Swing)plzz tell me how to use both "GridLayout" and this "BorderLayout" in my program..
Most here would say that your teacher is mistaken as there's no need to do AWT first and then go to Swing.nd i am on the learning stage now...:) my teacher told me to use awt first and then try swing... so i am using awt...:)
Please avoid unnecessary and non-standard abbreviations. It's hard enough to interpret questions here and your use of these abbreviations makes it harder still, not to mention for those for whom English is not their primary language.
- 08-11-2010, 04:20 PM #7
Member
- Join Date
- Aug 2010
- Posts
- 15
- Rep Power
- 0
Similar Threads
-
Java, Military Format using "/" and "%" Operator!!
By sk8rsam77 in forum New To JavaReplies: 11Last Post: 02-26-2010, 03:03 AM -
How to change my form design from "metal" to "nimbus" in Netbeans 6.7.1?
By mlibot in forum New To JavaReplies: 1Last Post: 01-21-2010, 09:20 AM -
problem with argument list and precedence "(" and ")"
By helpisontheway in forum Advanced JavaReplies: 6Last Post: 12-24-2009, 07:50 AM -
MoneyOut.println("It took you (whats wrong?>",year,"<WW?) years to repay the loan")
By soc86 in forum New To JavaReplies: 2Last Post: 01-24-2009, 06:56 PM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks