Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Java Basics
Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old December 30th, 2005, 08:44 AM
Authorized User
Join Date: Aug 2005
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
Default GridLayout :: help needed

hello every1
i need a small help regarding grid layout ... i've created a grid layout of 3 rows & 3 cols, every cell contains a button and every button is associated with an action listener ... now whenever any button is pressend, iz there any way to get the coordinates of that button, i mean if i press button "6" ... then on the command prompt, message should be displayed "row:2 col:3" ... similarly, i want 2 do the same operation on every button. so iz it possible to do this ???

below i m pasting my code, i just need the coding for actionPerformed() method ... i hope that i'll get good reply as soon as possible

import java.awt.*;
import java.awt.event.*;
class GridDemo extends Frame implements ActionListener
    Button b1,b2,b3,b4,b5,b6,b7,b8,b9;
    public GridDemo()
        b1=new Button("1");
        b2=new Button("2");
        b3=new Button("3");
        b4=new Button("4");
        b5=new Button("5");
        b6=new Button("6");
        b7=new Button("7");
        b8=new Button("8");
        b9=new Button("9");
        setLayout(new GridLayout(3,3));
    public void actionPerformed(ActionEvent ae)
        // WHAT TO DO HERE ???
    public static void main(String args[])
        GridDemo gd=new GridDemo();

Old January 5th, 2006, 06:49 AM
Registered User
Join Date: Jan 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts

you could first add a textarea,then
public void actionPerformed(ActionEvent e){
Object source=e.getSource();
}else if(source==b2){

Old January 22nd, 2006, 01:02 PM
Registered User
Join Date: Jan 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts

nice reply aminsky

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help Needed ????? sanjivbshinde ASP.NET 2.0 Professional 1 September 10th, 2007 07:37 AM
Help needed fastmike Pro PHP 1 February 15th, 2007 03:25 AM
Is GridLayout Mode gone in VS2005? Aaron Edwards ASP.NET 2.0 Basics 1 January 2nd, 2006 04:22 AM
GridLayout and Panels spudgun2005 J2EE 0 September 12th, 2005 01:21 AM
GridLayout problem thanasis_gr Java GUI 2 December 1st, 2004 02:59 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.