Solved

JButton question

Posted on 2004-09-06
20
258 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
ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Checkbox and ListView in Android Layout 4 67
tomcat not starting 6 46
Java exception bubble up 2 18
Is there a simpler dropbox system? 10 24
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

831 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