Solved

JButton question

Posted on 2004-09-06
20
254 Views
Last Modified: 2012-05-05
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!
0
Comment
Question by:azcalv408
  • 10
  • 2
  • 2
  • +2
20 Comments
 
LVL 35

Accepted Solution

by:
girionis earned 43 total points
ID: 11991280
Try this: JButton button = new JButton("X");
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11991281
JButton b = new JButton("X");

would be the easiest
0
 
LVL 14

Assisted Solution

by:sudhakar_koundinya
sudhakar_koundinya earned 41 total points
ID: 11991318
JButton jb=new JButton("", new ImageIcon(new Image("X.bmp")));

In which X.bmp should contain the image "X"
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 41 total points
ID: 11991334
If setting the text as i mentioned doesn't look right, you can change the font:

b.setFont(new Font("sanserif", Font.BOLD, 22));
0
 

Author Comment

by:azcalv408
ID: 11991352
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
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 11991369
for(int i=0;i<row.i++)
{
          for(int j=0;j<col;j++)
         {
 JButton jb=new JButton("", new ImageIcon(new Image("X.bmp")));
          }
}
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 11991376
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")));
          }
}
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 11991389
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");

          }
}
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 11991394
>> jb[i][j]=new  JButton b = new JButton("X");

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

0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 11991412
//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

          }
}
0
 

Expert Comment

by:Naveen13
ID: 11994514
//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
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 11994548
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

0
 

Expert Comment

by:Naveen13
ID: 11994582

Yes I also have same idea just posted If he/she needs,  just copy and paste my code with out adding any extra code
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 11994618
;-)
0
 
LVL 35

Expert Comment

by:girionis
ID: 12215231
The answer is already given, so I'd say split points among all participants.
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12215254
I agree to split the points between all participants
0
 
LVL 14

Expert Comment

by:sudhakar_koundinya
ID: 12241163
ok by me
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now