|
Subject:
|
GridLayout :: help needed
|
|
Posted By:
|
kanoorani
|
Post Date:
|
12/30/2005 7:44:33 AM
|
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); } }
|
|
Reply By:
|
aminsky
|
Reply Date:
|
1/5/2006 5:49:26 AM
|
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... }
|
|
Reply By:
|
mithun_7_4u
|
Reply Date:
|
1/22/2006 12:02:47 PM
|
nice reply aminsky
|
|