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
CHEERS !!!

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");
        b1.addActionListener(this);
        b2=new Button("2");
        b2.addActionListener(this);
        b3=new Button("3");
        b3.addActionListener(this);
        b4=new Button("4");
        b4.addActionListener(this);
        b5=new Button("5");
        b5.addActionListener(this);
        b6=new Button("6");
        b6.addActionListener(this);
        b7=new Button("7");
        b7.addActionListener(this);
        b8=new Button("8");
        b8.addActionListener(this);
        b9=new Button("9");
        b9.addActionListener(this);
        setLayout(new GridLayout(3,3));
        add(b1);
        add(b2);
        add(b3);
        add(b4);
        add(b5);
        add(b6);
        add(b7);
        add(b8);
        add(b9);
    }
    public void actionPerformed(ActionEvent ae)
    {
        // WHAT TO DO HERE ???
    }
    public static void main(String args[])
    {
        GridDemo gd=new GridDemo();
        gd.setSize(300,300);
        gd.setVisible(true);
    }
}

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

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

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

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.