JavaScript, change TextField color based on ComoBox value - background-color

I have a problem with a JavaScript coding to change TextField color with value.
I have a ComboBox to feed TextFeild with a value when it's Buy Order the TextField background color is changing to Green, with a Sell order the color is Red.
The JavaScript I have is working fine, but, I didn't like the coloring at all!!!
I would like to find a way to use RGB colors, can you help me that?
function test()
{
var s = this.getField("Order01");
if(!event.willCommit)
{
if (event.change == "Sell")
{
this.resetForm(s);
s.fillColor = color.red;
s.value = "Sell Order";
}
else if (event.change =="Buy")
{
this.resetForm(s);
s.fillColor = color.green;
s.value = "Buy Order";
}
else if (event.change=="Transaction")
{
this.resetForm(s);
s.fillColor = color.transparent;
s.value = " ";
}
}
}

Related

Remove tint color but keep font color UISegmentedControl

I would like to remove the selected color from my UISegmetedControl. I know tintColor can do this but that also removes the font color with it. Also using kCTForegroundColorAttributeName will remove both.
Side note I made a UIView and placed it above the selected segment to show selected state. I thought this would look better. Trying to branch out and make my own custom controls.
public let topLine = UIView()
override func awakeFromNib() {
super.awakeFromNib()
self.removeBorders()
setFont()
addTopLine()
}
func setFont() {
let font = UIFont(name: FontTypes.avenirNextUltraLight, size: 22.0)!
let textColor = UIColor.MyColors.flatWhite
let attribute = [kCTFontAttributeName:font]
self.setTitleTextAttributes(attribute, for: .normal)
}
func addTopLine() {
topLine.backgroundColor = UIColor.MyColors.flatWhite
let frame = CGRect(x: 7,
y: -5,
width: Int(self.frame.size.width)/2,
height: 2)
topLine.frame = frame
self.addSubview(topLine)
}
struct FontTypes {
static let avenirNextRegular = "AvenirNext-Regular"
static let avenirLight = "Avenir-Light"
static let avenirNextUltraLight = "AvenirNext-UltraLight"
}
TintColor is attach with
Background colour of Selected segment,
Text color of Unselected segment and
Border colour of UISegmentedControl.
So, if you going to change tintColor to white, then background colour and tint color Both are gone.
You need to set Selected/Unselected text attribute like below:
mySegment.tintColor = .white
let selectedAtrribute = [NSAttributedStringKey.foregroundColor: UIColor.red, NSAttributedStringKey.font: UIFont.systemFont(ofSize: 16)]
mySegment.setTitleTextAttributes(selectedAtrribute as [NSObject : AnyObject], for: UIControlState.selected)
let unselected = [NSAttributedStringKey.foregroundColor: UIColor.black, NSAttributedStringKey.font: UIFont.systemFont(ofSize: 16)]
mySegment.setTitleTextAttributes(unselected as [NSObject : AnyObject], for: UIControlState.normal)

Cannot implicitly convert type string to System.Drawing.Color

I made app in C# that convert resistor value to color codes.
How to show color instead of text. For example, if I enter 15K it shows me brown,green and orange color, not text.
https://postimg.org/image/4tccjjnax/
When I set label15.BackColor=colours(res[0] - '0')
I get error cannot implicitly convert type string to System.Drawing.Color
You can convert a string to a Color with Color.FromName();
Example
label15.BackColor = Color.FromName(colours(res[0] - '0'));
Be aware you don't have { } Behind your else statement and only the first line will execute in else and the other lines will always execute.
You don't have to but I recommend you to do it like this
if (res.Count() > 11)
{
MessageBox.Show("Invalid value");
}
else
{
textBox4.Text = ..
textBoxS.Text = ..
textBox6.Text = ..
}
I also recommend you to give your textboxes logic names

How to set a new property and provide its setter in Groovy

I have this groovy class:
class Car {
int speed = 0
}
I want to use metaprogramming to introduce a new property "color" and also provide setColor method to an instance of the Car object, like this:
def c = new Car()
c.metaClass.setProperty("color", "red")
c.metaClass.setColor = {
def newColor-> "color switched from $existingColor to $newColor
}
My ultimate goal is that when I call:
c.color("yellow")
it prints out:
color switched from red to yellow"
I have gotten the c.color part working with my above code, but not the second part (setColor).
Could someone help me accomplish this or tell me if it is even possible?
Thanks.
When you add a property, you get both the getter and setter for free, e.g.
class Car {
int speed = 0
}
def c = new Car()
c.metaClass.setProperty("color", "red")
assert c.color == 'red'
c.setColor('blue')
assert c.getColor() == 'blue'
If the ultimate goal is to invoke a method called color to set the color property, you can add one like this:
c.metaClass.color << { col ->
println "color switched from $delegate.color to $col"
c.color = col
}
c.color('yellow') // prints "color switched from blue to yellow"
assert c.color == 'yellow'
You are so very close to getting it working. Since you made a new property that has a setter, all you have to do is this:
c.metaClass.getColor = {'red'}
c.metaClass.setColor = {
def newColor-> println "color switched from ${delegate.color} to $newColor"
}
c.color = "yellow"
Please note, that this does not make a property that is set, but merely provides a mechanism to inject a get and a set method for the delegates color.
it could probably be fixed by doing this:
def currentColor = 'red'
def previousColor = ''
c.metaClass.getColor = { currentColor }
c.metaClass.getPreviousColor = { previousColor }
c.metaClass.setColor = {
def newColor-> previousColor = delegate.color; currentColor = newColor
}
c.color = "yellow"
println "Changed color from $c.previousColor to $c.color"
c.color = "blue"
println "Changed color from $c.previousColor to $c.color"
but now we're into code that is purely for experiments not for production :)

How to Change Background Color on Processing?

I'm still extremely new to processing and I'm just playing around with it right now. I was hoping to find out how to change the background color between two colors, particularly between white and black, when I click my mouse. I found a code online that has the background color change between several different colors but I can't seem to figure out how the bg color can be changed between two colors. I would particularly like what 'col+=' and 'col%=' represent because I can't seem to find it in the processing tutorial. Please help me! Thank you!
Below is the code that I found.
void setup() {
size(600,400);
smooth();
colorMode(HSB);
}
int col = 0;
void draw() {
background(col,255,255);
}
void mousePressed(){
col+=20;
col%=255;
println(col);
}
"x += y" is shorthand for "x = x + y" and, likewise, "x %=y" is shorthand for "x = x % y" (where % is the modulo operator).
I'm going to assume that you wanted to ask is "how do I change the background from one colour to another, and then back again"; there's two basic ways to do this.
1: set up two (or more) reference colours, an extra "current" colour, and then change what 'current' points to, drawing the background off of that:
color c1 = color(255,0,0), c2 = color(0,0,255), current;
void setup() { current = c1; }
void draw() { background(current); }
void mousePressed() { if(current==c1) { current = c2; } else { current = c1; }}
Every time you click, the program checks which of the two colours "current" points to, and then instead points it to the other colour.
2: set up one colour, and apply some operation that is modulo in 1, or 2, or ... steps:
color c = color(255,0,0);
void draw() { background(c); }
void mousePressed() { c = color( red(c), (green(c)+50)%255, blue(c)); }
Every time you click, the colour "c" gets its green component increased by 50, and then modulo-corrected for 255. So it'll cycle through: 0, 50, 100, 150, 200, 250, 300%255=45, 95, 145, 195, 245, 295%255=40, 90, etc.

I am beginner in j2me.In J2me Ticker function, How to apply differnt Color in Single Ticker?

*I am developing one j2me-Lwuit Project for Nokia s40 devices.I have some problem abuot ticker. I have apply Only one color for tiker.But i want differnt color to apply for single ticker.This is my code for Ticker:
Ticker tick;
String tickerText=" ";
Label lblIndice=new Label();
Label ticker=new Label("");
for (int i = 0; i < tickerIndiceData.size(); i++)
{
tickerText +=" "+tickerIndiceData.elementAt(i).toString();
tickerText +=" "+tickerValueData.elementAt(i).toString();
tickerText +=" "+"("+tickerChangeData.elementAt(i).toString()+")";
lblIndice.setText(" "+tickerIndiceData.elementAt(i).toString());
lblValue.setText(" "+tickerValueData.elementAt(i).toString());
double val=Double.parseDouble(tickerChangeData.elementAt(i).toString());
if(val>0)
{
ticker.getStyle().setFgColor(0X2E9F37);
}
else
{
ticker.getStyle().setFgColor(0XFF0000);
}
lblChange.setText(" "+"("+val+")");
}
System.out.println("TICKER==="+tickerText);
ticker.setText(tickerText);
ticker.getStyle().setFont(Font.createSystemFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD, Font.SIZE_SMALL));
ticker.startTicker(50, true);*
LWUIT doesn't support different colors for a label (hence ticker) since that would require quite a bit of processing.
Implementing a ticker from scratch in LWUIT is pretty easy though. Just derive label and override paint as such:
public void paint(Graphics g) {
UIManager.getInstance().setFG(g, this);
Style style = l.getStyle();
Font f = style.getFont();
boolean isTickerRunning = l.isTickerRunning();
int txtW = f.stringWidth(text);
// update this to draw two strings one with the color that's already set and the
// other with the color you want
g.drawString(getText(), getShiftText() + getX(), getY(),style.getTextDecoration());
}

Resources