Solved

JButton question

Posted on 2004-09-06
20
260 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ejb stateless example 2 68
Java: The Public Class Main 4 66
JDBC performance 8 35
Github api to fetch the number of collaborators in a git repo 1 69
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

739 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