I am currently working on a chat type window in eclipse rcp application.
I have created a StyledText where user will type some message and a system generated message will be visible to StyledText. I want to capture what user has typed in the current line. Especilly, I want to grab the test line entered by the user in StyledText not the whole text.
The example is given below.
System: Welcome
User: Hi
System: Log the ticket
User: where to log
In the above case, I want to track each sentence written by user like "Hi", "where to log" etc. Please help me in this regard.
Thanks in advance.
Related
I have a Swing base Java application that requires ldap user and password for login. I would like to automate the login so that each time the application is launched, it fills the user and password.
I have seen library robot for java but could not make it.
Is there a way to pass through the JVM / or read Swing component in JVM?
I believe you want to add the remember me feature If you use a database like SQL or oracle then keep the checkbox option in the database with boolean. Otherwise, the checkbox is selected then store your password in some hidden file on the user path. Next time before login look at that password.
Sample code
String file_path=System.getProperty("user.home")+"/.myapp";
FileWriter obj=new FileWriter(file_path);
obj.write("Your Password Here ");
obj.close();
I'm creating a Java log-in screen for a scheduling program that uses one-way encryption. The program should work as follows:
If it's the first time opening the program, ever, a window will show up asking the user to enter a username and password, as well as a security question. This first time, the password will not be hidden by black circles. Instead, it will be shown in plain text.
Then, the three fields will be encrypted using a caesar/shift cipher of 3 spots, and the 'encrypted' values will be saved into a file called info.txt in the source folder of the program.
The user will then be redirected to a log-in page, where they will re-enter their username and password to log in. Here, the password field is fixed so that the letters show up as black circles(not sure what this is called). A new int variable called loginAttempts is declared and initialized with the value 0.
After the user hits 'log-in', the system will use the same encryption method for the log-in details entered and compare them to the encrypted information in the text file. If both values match, then the user will be re-directed to the main screen of the program, having been granted access.
If not, then loginAttempts increments. After the 5th time, this happens, the user will be asked their security question. If the answer this wrong the first time, they will be booted from the program.
I have a few questions, as I'm having trouble creating this.
The dialog boxes I'm using to produce error messages are very confusing, and not seeming to work. I got the code to use them straight from the Oracle website and I'm still having trouble-- NetBeans has informed me that it 'cannot find symbol' for showInputDialog(the method I'm using to display the error message), but it's not suggesting that I'm missing any imports.
String errorMessage = "Security Question: What was your favorite class in college?";
String s = (String) JTextField.showInputDialog(
null,
errorMessage,
"ERROR",
JOptionPane.PLAIN_MESSAGE,
JOptionPane.WARNING_MESSAGE,
null,
securityAnswer);
The part that's given me an error is the word 'showInputDialog' itself, and I'm unsure why..? I would like for this particular dialog to appear with a text field in it so that the user can enter the answer to the security question in there. However, the code doesn't even seem to be working.
On the Oracle page, this is the code that is given that is supposed to show a dialog box with an input field:
String s = (String)JOptionPane.showInputDialog(
frame,
"Complete the sentence:\n"
+ "\"Green eggs and...\"",
"Customized Dialog",
JOptionPane.PLAIN_MESSAGE,
icon,
null,
"ham");
//If a string was returned, say so.
if ((s != null) && (s.length() > 0)) {
setLabel("Green eggs and... " + s + "!");
return;
}
//If you're here, the return value was null/empty.
setLabel("Come on, finish the sentence!");
But the word frame creates an error in the Netbeans GUI, and I'm not sure why it doesn't work. All I want is to create a text box that looks like this:
but I don't know how to do that in a way that would work.
The way that I've set up my program, I've made multiple jFrame components(different classes), and I've set it up so that if you were to try and access a different frame, the frame you were currently on would turn invisible. For example:
(a user is on the main screen, and they click on a button that says 'Add Appointment.')
addAppointment a = new addAppointment();
a.setVisible(true);
a.setAlwaysOnTop(true);
this.dispose();
And this works for literally all of my program except for the log-in page!
public createUserPass() throws IOException {
String path="\\src\\Schedulemanager\\pkg\\info.txt";
file = new File(path); //creates new File
if (file.exists()) { //make a new file if it's not already existent
logIn loginPage = new logIn();
loginPage.setVisible(true);
loginPage.setAlwaysOnTop(true);
this.dispose();
this.setVisible(false);
} else {
file.createNewFile(); //creates the new file
initComponents();
}
}
This is the 'main' class in the program that will run if the .jar file is clicked. What it's supposed to do is check if the info.txt file exists. If it does, then obviously the user has already set login information, and it should close itself and open an instance of the logIn class, which is the jFrame that handles the log-in functions once the information has been set. However, it doesn't work! It opens the new logIn class, but it doesn't dispose of the original one where you set the information, to begin with.
It's crucial that the original jFrame is hidden so that the user can't just set a new password every single time they run the program! How can I fix this?
Please let me know if I need to clarify anything.
We are automating an iOS app using Appium and JAVA
We stuck at below point
How to open a keyboard view in appium to type in UIAtextbox field as sendkeys of webdriver is not working without it ?
Please help ....
You should not use send_keys on iOS. It is notoriously unreliable. (read more about that here)
Here's my implementation in python:
textfield = driver.find_element_by_class_name('UIATextField')
text = 'ABCDEF'
driver.execute_script("au.getElement('%s').setValue('%s')" % (textfield.id, text))
driver.hide_keyboard('return') # Close the keyboard with the return button
So what you need to do is:
Get the webelement/textfield
On the driver, call ExecuteScript
Pass in the the webelement's id and the value you want to set the textfield to
Optional: Hide the keyboard afterward
To add some clarity:
When you use sendkeys, do the textfield appear clicked?
What is the response from the server regarding the request of the sendkeys action?
Can you show the line where you do the inputing part?
This may be caused by a) Appium doesn't see the UItextbox b) The action is called before the textbox is usable(init phase) c)there is sth completely wrong with your line of code :)
Awaiting your answer
I am trying to a display message when i will push save button saying that the content got saved using SWT. Can anyone please help me.
Note: I am not using Jface, Shell, Display. I am using a Composite.
Actually, you are using a Display and a base Shell. But these are hidden behind your Eclipse RCP app. I'm guessing you are creating your message dialog in the createContents(Composite) method of a ViewPart, correct?
You can access the Display with Display.getCurrent() anywhere in your code, and you can get the active Shell with parent.getActiveShell().
If you don't want to use JFace, use the MessageBox widget from SWT.
MessageBox box = new MessageBox(parent.getActiveShell(), SWT.CANCEL | SWT.OK);
box.setText("Title");
box.setMessage("This will be the message");
box.open(); // Call this on button pressed. Returns SWT.OK or SWT.CANCEL
If you want specific features for the MessageBox, you can either ask me in a comment, or check out these 18 Java code examples.
Alternatively you can use as below
MessageBox box = new MessageBox(comp.getShell(), SWT.CANCEL | SWT.OK);
Where comp is Composite.
i am new learner of java i want to create one application program in applet. i want to create
"applet which has a Text Field to accept a URL string, and displays the document of the URL string in a new browser window."
Thanks in advance.
#nimit parekh
this post contains answer to your question:
Getting java gui to open a webpage in web browser
From inside your applet class (which must extend java.awt.Applet or javax.swing.JApplet):
getAppletContext().showDocument(new URL("http://www.google.com"));