Solved

background for button

Posted on 1997-05-03
6
259 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
Revamp Your Training Process

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

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 67
jsp insert to database example 2 89
Notify sent to other threads in Java 9 54
How to log java errors in tomcat 8 37
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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

734 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