How do you access the value of a JTextField in JRuby? - jruby

I want to use the value of the text field to validate the username and password for my GUI. I have tried this code:
If user.Text = "abc" and passwrd.Text = "abc" then

You access it the exact same as you would in Java:
my_text_field.getText
JRuby has some nice syntactic sugar to make interoperating with Java feel more Ruby-like, which you can also use:
# these are equivalent
my_text_field.get_text
my_text_field.text

Related

LIBGDX : setPasswordMode not working

So I am building a game in LibGDX (Kotlin) and trying to setup a username and password field.
I create my TextField
password = TextField("", Gui.skin)
I set
password.isPasswordMode = true (Kotin changes setter and getters, under the hode this is calling setPasswordMode)
However the text still appears when I enter it in the box. I am using LibGDX 1.9.6
setPasswordMode will enable the password display mode of a text field.
How it works is that it replaces each character with a predefined character.
By default, this is the bullet "•", which some fonts may not have.
Change the password character to something else your font does have, like "*" for example:
password.setPasswordCharacter('*')
Note that you cannot do
password.passwordCharacter = '*'
because there is no corresponding getPasswordCharacter method, so no Kotlin property is generated.

I just started learning python. I want to get file name as user input

def copy_file(from_file,to_file):
content = open(from_file).read()
target = open(to_file,'w').write(content)
print open(to_file).read()
def user_input(f1):
f1 = raw_input("Enter the source file : ")
user_input(f1)
user_input(f2)
copy_file(user_input(f1),user_input(f2))
What is the mistake in this ? I tried it with argv and it was working.
You're not calling the function user_input (by using ()). (fixed in question by OP).
Also, you need to return a string from user_input. currently you're trying to set a variable f1 which is local to the function user_input. While this is possible using global - I do not recommend this (this beats keeping your code DRY).
It's possible to do something similar with objects by changing their states. String is an object - but since strings are immutable, and you can't have the function change their state - this approach of expecting a function to change the string it's given is also doomed to fail.
def user_input():
return raw_input("Enter the source file :").strip()
copy_file(user_input(),user_input())
You can see user_input does very little, it's actually redundant if you assume user input is valid.

C# and LuaInterface: How to add table entries to a C# object in Lua

I use SharpLua with MonoDevelop. I created a class on C# side, which should be usable from Lua. That's works fine, I can access all fields from Lua. It's very easy.
public class Test {
public string Name;
}
could be access from Lua with
print(test.Name)
Now, I want to create new fields by Lua. In Lua it should look like
test.abc = "A string"
print(test.abc)
But this didn't work. I get an error in the ObjectTranslator. So I couldn't extend the table from Lua. I didn't want to access this new entries from C#. It should only be possible to create them.
Is there an other way to achieve this? Could I create a class from LuaTable and insert this to Lua?
lua["NewLuaTable"] = new ClassFromLuaTable;
and than use in Lua
NewLuaTable.abc = "A string"
print(NewLuaTable.abc);
But than, how did I get notifications, that something I want to know is changed in the LuaTable (NewLuaTable.Name is changed)?
Thank you for your help.
Ok, I found it by myself.
You could extend C# classes from Lua with the functions get_Item() and set_Item(). These both functions are the same as __index and __newindex in Lua metatables. So you could create a Dictionary table in C# and fill it in the set_Item() function. If LuaInterface didn't find an entry in the class, it calls get_Item() to look, if it could get the value on this way. There you could look into your table, if it is a valid key-value-pair.

f# class constructor formatting

I am creating a program that takes an email and converts it into json. In the interest of learning functional languages I thought it would be a good opportunity to learn F#. So first off I want a message class that can then easily be serialized into json. This class will have some members that can be null. Because of these optional parameters I am using the following format
type Email(from:string, recipient:string, ?cc:string .........) =
member x.From = from
member x.Recipient = recipient.....
This class actually has a lot of members as I want to store every piece of information that an email could have. What happens is if I try to format the constructor myself by splitting it onto multiple lines I get warnings. How do people make such a gigantic constructor look good in f#? Is there a better way to do this?
On a similar note, I'm not finding visual studio very helpful for f#, what are other people using to code? I think there is a mode for emacs for example...
There should not be any warnings if all "newlined" parameters start at the same column. For example:
type Email(from:string, recipient:string,
?cc:string) =
member x.From = from
member x.Recipient = recipient
(I personally enjoy using Visual Studio for F#. I doubt there is an IDE with more complete support.)
As an alternative to creating constructor that takes all properties as parameters, you can also create an object with mutable properties and then specify only those that you want to set in the construction:
type Email(from:string, recipient:string) =
member val From = from with get, set
member val Recipient = recipient with get, set
member val Cc = "" with get, set
member val Bcc = "" with get, set
let eml = Email("me#me.com", "you#you.com", Cc="she#she.net")
This is using a new member val feature of F# 3.0. Writing the same in F# 2.0 would be pretty annoying, because you'd have to define getter and setter by hand.

Is there any way to include variables inside strings for printing in Actionscript3?

I find myself always typing something like
Alert.show("blah = " + blah);
In PHP we have
"blah = $blah"
In Ruby we have
"blah = #{blah}"
Do we have anything like that in Actionscript3?
Also...what is the proper name for what we are doing here?
Thanks!
If you're asking whether you can include a variable name within a string and have it evaluated as opposed to treated like a literal (like your PHP example), the answer is no. This isn't a feature of the ActionScript language. However, you can achieve something like this by using the StringUtil's substitute method. Here's an example:
StringUtil.substitute("My name is {0} and I am {1} years old", name, age);
http://livedocs.adobe.com/flex/3/langref/mx/utils/StringUtil.html
Not sure if you mean the trace() function:
http://help.adobe.com/en_US/AS3LCR/Flash_10.0/package.html#trace()
As in:
trace("Blah: " + Blah);