Solved

JButton question

Posted on 2004-09-06
20
253 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

747 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

15 Experts available now in Live!

Get 1:1 Help Now