Solved

background for button

Posted on 1997-05-03
6
261 Views
Last Modified: 2010-04-16
I have an applet that has buttons that change color depending on the situation.  This applet works fine
on a unix machine. However, on a pc this doesnt work.
So much for paltform independent.  Is there a way
to make this work on a pc?

Here are parts of the code:

 if (dates[0]  != null) {
              for(int k=0;k<dates.length;k++)
                {
                  month=dates[k][1];
                  if(!(month==null) && changeMonth(month)==thismonth && Integer.parseInt(dates[k][3])==tmp && Integer.parseInt(dates[k][4])==thisyear+1900)
                    {
                      myButton[i].setBackground(new Color(0, 128, 128));
                      break;            
                    }              
                }
            }
           
          }
          else myButton[i].setBackground(new Color(16512));    
        }
      }
0
Comment
Question by:arth
[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
6 Comments
 
LVL 6

Expert Comment

by:jpk041897
ID: 1220085
Could you post the relevant parts of the code?
0
 

Author Comment

by:arth
ID: 1220086
Edited text of question
0
 
LVL 6

Expert Comment

by:jpk041897
ID: 1220087
Hum,

Have you tried:

myButton[i].setBackground(new Color(0, 128, 128));
myButton[i].repaint();
break;

To force an update of the component?
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Expert Comment

by:rickl032797
ID: 1220088
Maybe this is an answer, but one you won't want! I think in the windows implementation, background has no effect (ie if you could change background it would be for all gui buttons). Not 100% on this though.If this is the case, your only alternative is to code up your own button class, or perhaps just use a bitmap type button from somewhere.
0
 

Expert Comment

by:rickl032797
ID: 1220089
Sorry you rejected my answer, but I have discovered it's true. Maybe in 1.1.? they will introduce some trick to accomplish it. I had someone else run into this (with a code sample from a book) and it does run on unix but not in win95 (didn't try any others).So unless you use an alternative button you make yourself, I think you're stuck for now....
0
 

Accepted Solution

by:
jpzwarte earned 100 total points
ID: 1220090
I don't know if it works with setBackground, but i've used it succesfully with setForeground in jdk1.1.1. ... i just tried using setBackground on a button in jdk1.1.1 and it WORKS!

here's some code:

public void mouseEntered(MouseEvent e)
    {
        Object obj = e.getSource();
        Color active = Color.red;

        if (obj == Quit) // Quit = Button
            Quit.setBackground(active); // this WORKS!
        else if (obj == Send)
            Send.setForeground(active);
        else if (obj == SendToAll)
            SendToAll.setForeground(active);
        else if (obj == ClearText)
            ClearText.setForeground(active);
    }
0

Featured Post

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 …
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 video teaches viewers about errors in exception handling.

695 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