Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

JButton question

Posted on 2004-09-06
20
Medium Priority
?
268 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
17 Comments
 
LVL 35

Accepted Solution

by:
girionis earned 172 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 164 total points
ID: 11991318
JButton jb=new JButton("", new ImageIcon(new Image("X.bmp")));

In which X.bmp should contain the image "X"
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 164 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
 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

877 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