How do I avoid keypad during Scrolling? - java

I need to test the button which is below the text box and for that I need to scroll the screen as button is not visible. But when it starts Scrolling the screen,keypad appears (as the text box is editable) and hide the button and stop scrolling down. It happens on my Samsung S4 android phone (version 4.4.4) not on any other android device.
I am using appium (version 1.4.13.1) on my window machine.
try {
ClickShareViaEmailBtn();
if (panelShareObject.ShareTextBtn.isDisplayed()) {
MobileUtils.navigateBack(driver);
return true;
}
return false;
} catch (Throwable e) {
throw e;
}
public void ClickShareViaEmailBtn() throws Throwable {
try {
Thread.sleep(1000);
// Utils.sleep(ShareViaEmail, 20, driver);
// Thread.sleep(1000);
panelShareObject.ShareViaEmail.click();
MobileUtils.swipeDown(driver);
} catch (Throwable e) {
MobileUtils.navigateBack(driver);
throw e;
}
}

If the button is hidden by the keyboard, then you can first hide the keyboard and then click on the button.
Hide Keyboard -
driver.getKeyboard().sendKeys(Keys.RETURN);
or
driver.hideKeyboard();

Related

Popup a compulsive window that the user can only interact with by Java Swing

So compulsive window here means like, I currently have interface(1) with a button, I click the button and it gives me a popup. I want this popup to be the only window that the user can interactive, so the user in this case cannot interact with interface(1). Think it like you are saving a Word doc, when you choose the file location to save this Word doc, you cannot modify the content of this Word doc. And that file saving window is what I want.
Currently I have a custom popup:
public class InputPopup {
private int closeflag;
private JFrame popup;
...
public int getCloseflag() {return closeflag;}
public void close(){
System.exit(0);
}
public void run() {
EventQueue.invokeLater(() -> {
try {
popup.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
});
}
}
And this is what I did in the button listener
InputPopup popup = new InputPopup(wordLabel.getText(), description.getText());
popup.run();
int flag = popup.getCloseflag();
while (flag != 1) {
flag = popup.getCloseflag();
}
popup.close();
Of course that does not work. Anyone has any idea on how to achieve that effect?

simulate button click according to jtextfield's changes

I'm facing problem with the simulation of the button click. I have JTextField that takes data from scanner (like in grocery stores). After that i need to push enter button, to activate function jTextField1ActionPerformed. Is there any way to do it without producing any button actions?
Or i need tip how to jButton1.doClick() every time jTextField is changed. Please help!:)
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
AddEmployee.add(jTextField1.getText());
jLabel7.setText(AddEmployee.name);
jLabel12.setText(AddEmployee.dep);
jLabel10.setText(AddEmployee.pos);
jLabel11.setText(AddEmployee.time);
num++;
jName.append("\n"+Integer.toString(num)+". "+AddEmployee.name);
jTime.append("\n"+Integer.toString(num)+". "+AddEmployee.time);
jTextField1.setText("");
}
catch (ClassNotFoundException | SQLException | ParseException ex) {
Logger.getLogger(MainMenu.class.getName()).log(Level.SEVERE, null, ex);
}
}
If you want to simulate the button press, including in the UI, you can call the following method:
myButton.doClick();
This will act as the user physically pressed it. Otherwise, you can create an ActionEvent and pass it to the button's listeners:
// Does not appear in the UI
for(ActionListener a: mybutton.getActionListeners()) {
a.actionPerformed(yourActionEvent);
}
In your case though(considering the code posted) I suggest making a method out of the button's code, and just call it wherever you want:
public void showData(){
try {
AddEmployee.add(jTextField1.getText());
jLabel7.setText(AddEmployee.name);
jLabel12.setText(AddEmployee.dep);
jLabel10.setText(AddEmployee.pos);
jLabel11.setText(AddEmployee.time);
num++;
jName.append("\n"+Integer.toString(num)+". "+AddEmployee.name);
jTime.append("\n"+Integer.toString(num)+". "+AddEmployee.time);
jTextField1.setText("");
}
catch (ClassNotFoundException | SQLException | ParseException ex) {
Logger.getLogger(MainMenu.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void myButtonActionPerformed(java.awt.event.ActionEvent evt) {
showData();
}
private void myOtherComponentEventOcurred(java.awt.event.ActionEvent evt) {
showData();
}

Codename One - Video Capture

Am using codename one to capture the video and upload it to Vimeo.
But I get errors when I click the button. What am I doing wrong ?
I get below error when the method is called.
I have a camera
java.lang.NullPointerException
at userclasses.StateMachine$1.actionPerformed(StateMachine.java:63)
protected void onMain_Button1Action(Component c, ActionEvent event) {
Capture.captureVideo(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
if(Capture.hasCamera()){
System.out.println("I have a camera");
}else{
System.out.println("I don't have a camera");
}
try {
String path = (String) evt.getSource();
Log.p("Path->" + path);
Vimeo.MyVimeo(path);
is.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
}
The event can be null if the operation is canceled.
You are not meant to select a file, The capture class is for capturing media files from the device. It brings out FileChooser if you are using the emulator, therefore test it on a device and see how it works.

JLabel text is not displayed

I added JLabel on JFrame and displayed frame on YES button click of JOptionPane, it displays frame but didn't display label text.
int yes = JOptionPane.showConfirmDialog(null,"Do you want to reactivate previous
schedule(s)","Reactivate Schedule",JOptionPane.OK_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE);
if(yes == JOptionPane.OK_OPTION) {
setVisible(false);
disp_wait.setVisible(true);
for(int i=0 ; i<options.taskList.size(); i++) {
dataList = Options.getInstance().getTaskList();
Task task=dataList.get(i);
boolean active = task.getActive();
if(active) {
task.setActive(true);
try {
Thread.sleep(5000);
} catch (InterruptedException ex) {
ex.getMessage();
}
}
}
}
All your code is performing some processing during an event handling. In Java this is a problem, the GUI only gets drawn once all the event handling is processed. Besides that, it would be great to see the code for your JFrame, it probably does not add the Label before calling pack()

Changing color before removing button

I'm trying to create a button that changes color of the background and then removes itself from the JFrame after a set amount of time, but instead of changing color it just stays pressed for the duration of wait.
public void actionPerformed(ActionEvent e) {
setBackground(Color.red);
try{
Thread.sleep(10000);
}
catch (InterruptedException iE) {
}
frame.remove(this);
}
Can anyone see what im doing wrong?
Your sleep is occurring in the main UI thread, hence the reason the button just stays pressed. If you want a sleep you should create a new thread, get that to sleep, then from within that thread you can get the frame to remove the button.
new Thread() {
public void run() {
try {
Thread.sleep(10000);
// Now do what is needed to remove the button.
} catch (InterruptedException e) {
e.printStackTrace();
}
};
}.start();

Categories

Resources