How to copy a text from java code in cygwin? - java

I need to get the value of selected item and to copy it from Java application in cygwin.
My problem is that I don't know how to copy a text from Java application in cygwin.
This is a portion of my code:
private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {
String cmmd = "moshell"+jComboBox1.getSelectedItem()
/*I need a help here :how to write this text (cmmd) in cygwin?*/
}
I'm debutant in programming. Can someone help me to resolve this problem. Thank you.

If I understand your question, the same way you write any text to the console,
// I need a help here :how to write this text (cmmd) in cygwin?
String cmmd = "moshell"+jComboBox1.getSelectedItem();
System.out.println(cmmd);

Related

Getting Text from TextField in CodeName One for Java

I have designed the GUI elements and put everything together using CodeName One plugin for Netbeans 8.1. I am first working on my client information GUI that has textfields and a submit button. I'm looking to retrieve the textfield imputs via the submit button action event(I will use the first name textfield as an example:
#Override
protected void onAddRecordGUI_SubmitButtonAction(Component c, ActionEvent event) {
..I tried this
String Fname = findTxt_Firstn(c).getText();
..I also tried this
String FirstName = findTxt_Firstn.getText();
..I then tried this
String FirstName = Txt_Firstn.getText();
}
I get "error: cannot find symbol" with regards to the textfields name (It is correct and located on the same form the button is located)
Am I doing something very wrong here? I found two post on Stack, however, I tried the solutions above anyway.
Okay! I have solved my own questions and this might be applicable to anyone else who encounters this issue. The issue isn't the code, but it is naming textfields with an underscore "_". I renamed the field and was able to create a reference to it.
Thanks.

SendKeys(Keys.Enter) not working in Appium

I have entered text in a text box. And now I want to press Enter key. To do that, I am passing sendKey(Keys.Enter) which just cut the text from the text box and does nothing.
driver.findMobileElement("id", setLocationTextBoxId).sendKeys(parkingLocation+"\n");
driver.getKeyboard().sendKeys(Keys.ENTER);
Note: "\n" is not working already. sendKeyEvent/pressKeyEvent method is not available.
To press ENTER key on Android device, you need to use Android KeyEvent codes. The key code for ENTER is 66. You can use the below code snippet.
driver.longPressKeyCode(66);
To get the all Android KeyEvent codes please refer this official link
Try this! I have the same problem like you, and i got frustated untill i found this. Hope this will help you out!
public void pressEnterEditText(String elementName, String value) {
AndroidElement tempElement = getAndroidElement(elementName);
tempElement.click();
driver.pressKey(new KeyEvent(AndroidKey.ENTER));
}

URL code assistance please short code (Newbie Java programmer)

I'm using NetBeans and trying to make a Jbutton play this .wav file that I have located in the build/classes/shadow part of my project. I want the .Jar to build with the .wav file so I could download the .Jar file on another computer and press the button and the music will play. The music is not locating or starting I'm not sure which it is, also please be easy on the terminology I am very very new.
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:File Clap = new File("sanic.WAV");
display.setText("cum on step it up!!!");
}
public static void startMusic() {
{
try{
URL url = Shadow.class.getClassLoader().getResource("sanic.wav");
play(); // NetBeans says it cannot find the symbol for play.
}catch(Exception e){
}
}
}
I'm not sure in what part of your code are you using your URL... But I'd suggest you to use AudioInputStream...
Regarding the problem finding the file... I had implemented something similar some time ago, while checking the code I have in my HDD, I found that this made it for me:
URL url = Shadow.class.getResource(myfile.wav);
But nowadays, I prefer working with this:
InputStream resourceAsStream = Shadow.class.getResourceAsStream(myfile.wav);
Hope it helps for what you need to do.
Regards and... happy coding :)

Want to access attribute value

i need help regarding html parser i want to get the first attribute"href" value of tag "a" please resolve my problem.I want to fetch this link from the code http://myneta.info/gujarat2012/candidate.php?candidate_id=1591,
i am attaching the snap please see and provide some solution,
i have tried this code but not works for me -
String temp = source.getElementById("main").getFirstElementByClass("grid_9").getAttributeValue("a");
here is image
Please try the following:
source.getElementById("main").getFirstElementByClass("grid_9").getFirstElement("a").getAttributeValue("href")

How do you replace htmlspecialchars simply?

input.replace("&", "&").replace("<", "<").replace(">", ">").replace(""", "\"");
im using this line of code as a sudo htmlspecialchars converter. with my application, it doesnt need to be too elaborate.
for some reason the above code does not replace("&", "&"), it doesnt seem to do anything.
any advice?
input = input.replaceAll("[^\\x20-\\x7e]", "");
i also tried this.
In android there is one class Html inside android.text.Html which you can use like this as below:
Html.fromHtml(any_html_text);
But this function will return Spanned object so use
Spanned spn=Html.fromHtml(any_html_text);
You can set this spanned text to any button or textview text Hope it will help you.
See this link also for your reference.
Instead of doing this manually, check out the Html class. Calling Html.fromHtml() should do the trick.
Trying to escape/unescape html by replacing strings yourself you might introduce security issues in your application (depending on what it does with the output). Either use Html.FromHtml or from Apache libs org.apache.commons.lang.StringEscapeUtils.unescapeHtml
This does the work -
public String cleanString(String dirty) {
return Html.fromHtml(dirty).toString();
}

Categories