Link to home
Start Free TrialLog in
Avatar of azcalv408
azcalv408

asked on

JButton question

Hi,
    I would like to know if there's a way to draw an "X' on a JButton object ? I'm working on a Maze program that displays 'X' 's  on the solution path. Thanks!
ASKER CERTIFIED SOLUTION
Avatar of girionis
girionis
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
JButton b = new JButton("X");

would be the easiest
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of azcalv408
azcalv408

ASKER

Hi,
  Is there a way to invoke it on an object. I have a double array object  JButton box[x][y] (x = row, y = col). I want to write a method to draw the 'X' on that Jbutton object. Thanks
for(int i=0;i<row.i++)
{
          for(int j=0;j<col;j++)
         {
 JButton jb=new JButton("", new ImageIcon(new Image("X.bmp")));
          }
}
JButton jb[row][col];
 for(int i=0;i<row.i++)
{
          for(int j=0;j<col;j++)
         {
 JButton jb[i][j]=new JButton("", new ImageIcon(new Image("X.bmp")));
          }
}
or if u plan to use other expert's code
 JButton jb[row][col];
 for(int i=0;i<row.i++)
{
          for(int j=0;j<col;j++)
         {
             jb[i][j]=new  JButton b = new JButton("X");

          }
}
>> jb[i][j]=new  JButton b = new JButton("X");

should be  jb[i][j]=new  JButton("X");

//text based
for(int i=0;i<row.i++)
{
          for(int j=0;j<col;j++)
         {
             jb[i][j]=new  JButton("X");

          }
}


//Image  based
for(int i=0;i<row.i++)
{
          for(int j=0;j<col;j++)
         {
            jb[i][j]=new JButton("", new ImageIcon(new Image("X.bmp")));// or u can use GIF/JPeg

          }
}
//If you want to display text use the following code
int row=10;
int col=10;
JButton box[row][col];
for(int x=0;x<row;x++)
{
          for(int y=0;y<col;y++)
         {
             box[x][y]=new  JButton("X");
          }
}


// If you want to display image

for(int x=0;x<row;x++)
{
          for(int y=0;y<col;y++)
         {
             box[x][y]=new  JButton("", new ImageIcon(new Image("X.bmp
          }
}

This may reach your requirement
Thanks
Naveen
Naveen

what is the speciality in ur code??

You just rename the variables of my ides :)

If u thing this is extra u gave
>>int row=10;
>>int col=10;
>>JButton box[row][col];

I think he/she knows abt that already

Regards
Sudhakar


Yes I also have same idea just posted If he/she needs,  just copy and paste my code with out adding any extra code
The answer is already given, so I'd say split points among all participants.
I agree to split the points between all participants