Solved

background for button

Posted on 1997-05-03
6
257 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
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
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.

 

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
rhino JavaScript import, load 25 85
spring jars download 1 29
by zero exception 10 41
Cisco ASA: Java web start no go, asdm launcher no go 3 15
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…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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 one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

825 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