Let's say I have two forms: form1 and form2.
After pressing a NEXT_COMMAND in form1, I need to change the value of the gauge in form2 and then show form2. Thus:
public void commandAction(Command command, Displayable displayable) {
....
else if (displayable == form1) {
if (command == NEXT_COMMAND) {
form2_gauge.setValue(value);
display.setCurrent(form2);
}
....
}
....
However, this doesn't work as I expected it to. It doesn't change a thing at first. On the other hand, if I go back from form2 to form1 and then again from form1 to form2 it would work.
I can't figure it out myself. I'd be enormously grateful of any possible help.
Thanks!
It seems to me that form2.gauge isn't correct here. You have to save the Gauge object like this:
Gauge form2_gauge([...]);
form2.append(form2_gauge);
Then your code would be:
[...]
form2_gauge.setValue(value);
display.setCurrent(form2);
[...]
Have you tried another sequence? Like this:
display.setCurrent(form2);
form2_gauge.setValue(value);
I don't think it would change anything, but may make it work.
Related
Hello guys i really need your help . I want to make some program in javafx so i need to add listener to random generated button on the keyboard. For example :
i don't want to add some action if user type enter but i want to add action to some random button and nobody would know which is that button . so the user need to click every single button on the keyboard to find out which is that button.How would he knows that this is the correct button ? - > well the program will be executed , when he click on the wrong button -> nothing will happen.
Try something like this:
private void handleKeyPress(KeyEvent ke) {
String text = ke.getText();
KeyCode code = ke.getCode();
if ( ke.isControlDown() || ke.isMetaDown() ) {
//DO something for example
}
}
I have made a 2D Game using unity in which user has to select objects of similar color and now i want to display hint when user is unable to select the color for more than four seconds.
I want something similar to candy crush hint displaying system in which candy crush shows hint by highlighting the possible combination if user is not able to identify any combination himself.
I cannot figure out how to find if the user is inactive so that i can display hints.
I would really appreciate if someone can help me in figuring it out. Thanks in advance.
I dont agree with Joe Blow on this one that you need to call that EVERYWHERE in your code the user does something. What a user can do is press a key on the keyboard(also count on gamepads and controllers) or move the mouse(on mobile the mouse is simulated so that works too). So if you have a single class that looks something like this :
using UnityEngine;
public class TestInActive : MonoBehaviour {
private Vector3 prevMousePosition = Vector3.zero;
void ShowGameHintInvoke()
{
CancelInvoke();
Invoke("GameHint", 5);
}
void GameHint()
{
Debug.Log("This is a Hint");
}
// Update is called once per frame
void Update () {
if (Input.anyKeyDown || Input.mousePosition != prevMousePosition)
ShowGameHintInvoke();
prevMousePosition = Input.mousePosition;
}
}
It should work just fine. This calls ShowGameHintInvoke() once after the user has been inactive for 5 secs. Then it will not call it again until the user does something.
You can use DateTime type and set it on Update, so when the user doesnt do anything, you see all frames if DateTime (now) and the saved DateTime, the difference is more or equal to 5 seconds, there you show.
If the user touches, you flag that the user had done that, so next frame, you will see he didn't touch, and you set again DateTime and start seeing if exceeds 5 seconds.
Do you get what I mean ?
You could use some Coroutines with Yields of 5 seconds (WaitForSeconds) and you put 5 seconds and if it continues the yield, you show hint.
i have made a program, which include a lot of controls. The controls would be showed and hided according to the choice of the user. That means that controls overlapped on each other at design time. now i want to change the forecolor and backcolor of all controls at design time. but i founded so hard to accomplish this task, because all the control overlapping each other. so I decided to make a for loop method to iterate the controls in the form and then check each control in turn whether it has controls. when the control has also controls in it, I call the same method and pass the control to it to change the properties for the subcontrols too. The method like so:
void setColor(ref Control con)
{
con.BackColor= System.Drawing.Color.Black;
con.ForeColor=System.Drawing.Color.Yellow;
if (con.Controls.Count > 0) { setColor(ref con); }
}
so my Form include tabControl with multiple tabPages. I iterate the tabPages and wanted to pass it to this method, but I become error "Indexer may not be passed as an out or ref parameter"
I pass it so: setColor(ref tabControl1.Controls[i]);
can you please help me to solve this problem?
I have resolved the problem.
I have removed the "ref" from method and wrote the method simply like the following:
void SetColor(Control con)
{
con.BackColor = System.Drawing.Color.Black;
con.ForeColor = System.Drawing.Color.Yellow;
if (con.Controls.Count > 0)
{
for (int i=0; i<con.Controls.Count;i++)
SetColor(con.Controls[i]);
}
}
and call it so: setColor(this.Controls[i]);
Is there possible to disable child's form buttons from parent form?
For example, I have 2 radio-buttons in parent form, one is True second False, when I choose one of them fires radiobutton.CheckedChanged event and there I have code what goes like this, but it's not working:
ChildForm.Button1.Enabled = False
where seems to be the problem? Can anyone help with this?
You would need to create an instance of the childform.
So...
ChildForm cf = new ChildForm();
cf.Button1.Enabled = false;
You have to keep in mind though, it could be a different instance than the child form that is currently being shown.
To be sure, depending on your code (which I can't see) and how your program is laid out I would probably do something like this...
ChildForm cf = new ChildForm();
cf.show();
cf.Button1.Enabled = false;
so here I know that the ChildForm that is showing is the one that has the button disabled.
In VB6 the following project works:
1 MDI form:
Option Explicit
Private Sub MDIForm_Click()
Form1.Option1.Enabled = False
End Sub
Private Sub MDIForm_Load()
Form1.Show
End Sub
Form1 is a MDI child form with 2 radio buttons on it
In REALBasic, how do I loop through all of the objects in Window1? Is there some array property of Window1 with all of its children? Also, how do you set custom properties of objects: e.g. Me.isFlamingo = true
Thanks in advance!
Adding properties to a built-in class like a pushbutton can be done in two ways. The better way would be to subclass the PushBustton class and to add properties to the subclass like you would with any custom class. The other, somewhat uglier way would be to use a pair of overloaded functions like this:
Function isFlamingo(Extends ByRef pb As PushButton) As Boolean
Dim flamingo As Boolean
//Do stuff to figure out if the PushButton is Flamingo-y
//and Return a Boolean based on the result
Return flamingo
End Function
And:
Sub isFlamingo(Extends ByRef pb As PushButton, Assigns b As Boolean)
If b Then
//Do stuff that makes the PushButton flamingo-y
Else
//Do stuff that makes the PushButton not flamingo-y
End If
End Sub
To iterate through the controls on a window, use code like this:
ListBox1.DeleteAllRows
For i As Integer = 0 To Self.ControlCount-1
ListBox1.AddRow(Self.Control(i).Name)
Next
(For this example, be sure to add at least one ListBox to the Window.)
Properties are set just like you describe: ObjectInstance.PropertyName.
If you are in the event of an object that has been dragged to the window, then you can modify its properties using Me.PropertyName. Otherwise you would use the object name.