GUI multithreading and sockets - java

I'm writing simple GUI to my client server application. GUI client application worked OK but when I added simple Login Form before my client app, communication between client and server doesn't work. Here is the code which create my client GUI (the code is in the "Log in" button in Login Form - when I click the button Login Form is close and client app is open):
new testUI().setVisible(true);
dispose(); //close Login Form

If your login form is not modal, then method setVisible () will return instantly and you will dispose form before user will see it.
Make sure your login form extends JDialog and is created with modal=true parameter passed to constructor of JDialog class.

Related

Can I set a log-in as an #before process in Selenium?

Using IntelliJ to run Selenium tests using Chrome/Chromedriver.
There's a page I want to test but it is after the login screen ("localhost:port/dashboard"). When I set the driver to get that page the program stops at the login screen ("localhost:port/login") and does not navigate to the main page which has most of the elements I want to test. When learning Selenium I was navigating to either files held locally (so I just needed a folder path) or website front pages (like www.google.com).
Is there some way to just log-in as a "Before" condition or is there something I'm totally missing that makes doing this impossible?
I think doing login in before method for all the test would not be good. because there may be the cases where you don't require to do the login.
So better to create one method where implement the login functionality and call the same where you require login into the system.
e.g.
public void doLogin(String username, String password){
driver.navigate().to("https://www.siteurl.com/login");
driver.findElement(By.locator).sendKeys(username);
driver.findElement(By.locator).sendKeys(password);
....
// click login button
}
And call this method where you require login.
#Test
public void verifyDetailsOnDashboard(){
doLogin(username, password);
....
// perform rest of functionality here
}

Server, client - unsure how to implement functionality "If names are repeated a user is prompted to enter another"

I am working on a chatroom project with client - server functionality.
The last finishing touches is when a username is entered twice on the login screen it recognises the fact that is has already been entered twice and displays an error.
I've been working on this for a while and cannot seem to do it.
Steps to reproduce error:
Start server
Open client program
Enter a user name on login screen
Click enter and go to chatroom window
Start a new client window
Enter a user name of the same name on login screen
Click enter
Doesn't recognise that it is a duplicate user name and goes ahead and displays chatroom window anyways
Steps tried to try to resolve problem:
Tried to make a context class to pass objects between controllers before realising that this is a multi-threaded project
Put a getter for the user name list off the ChatClient class to access in the LoginController but cannot be accessed for some reason
Changed around the LoginController to implement Runnable and to store the threads to try and store username list but to no success
GitHub link: https://github.com/Runite618/ChatRoomVers2
Thanks for any replies.
Kind regards,
Matthew.

send data to running instance

Hello I am creating software which allow files to be uploaded, my software has a chat client which will create a instance of a file uploader class, this file uploader class will take the file from the file chooser, convert it to byte and upload it to the sql database. so essentially I have a main chat client which contains a text area for chat to be show in. I have main chat windows which displays contacts. when the user double clicks on a contact the chat client opens up:
private void jList1MouseClicked(java.awt.event.MouseEvent evt) {
// TODO add your handling code here:
if (evt.getClickCount() == 2) {
String userID = lbluserID.getText();
String selectedContact = jList1.getSelectedValue().toString();
ChatClient chatClientObject = new ChatClient(selectedContact, userID);
ChatClient.runchatClient(selectedContact, userID);
}
}
within this chat client I have placed a button which allows the selection of the file. the dbconnect class will upload the file to the server, once this is done I need a message to appear in the chat client text area displaying that the file has been uploaded. I have tried to make a instance of the chat client in the dbconnect class and then call a method to output the message how ever this gives me errors. what I really want to do is allow my program to open the chat client for the contact the user clicks on and also be able to return the message to the same chat client instead of creating a new instance.
I hope my question is clear as it is pretty hard to explain.... for example, If i click on "Ben" in the main client a chat client will open for "ben" this chat client contains a text area. when i have finished uploading the file which is done by the dbconnect class I want the string message "file sent" to be returned to the chat I have open with "ben".
you said 'I have tried to make a instance of the chat client in the dbconnect class and then call a method to output the message how ever this gives me errors.'
Don't create new instance of client to send file completion message, you need to be use the same instance that was created at the time of client instantiated. So that at the time of client instantiated 1st time you need to hold that reference in global variable. And call method using this instance to display message.
It could help you.

GWT: Problem with application's architecture

I'm in little trouble with designing GWT application. I am trying to develope RIA app (with just one main widget, lets call it Main). First, user must be logged. Here's my way to do that, but it does have a problem, you'll see.
Show login components on root panel
If login was successfull (checks database), show Main widget
Widget is added to root panel
Everything works, but when you press Refresh it shows again login components ... It all happens in onModuleLoad method.
How should I redesign this logic? I'd like to let user logged (that means RootPanel will hold Main widget) for certain amount of time.
http://code.google.com/p/google-web-toolkit-incubator/wiki/LoginSecurityFAQ
How to remember logins
Our login
system so far misses a useful feature:
For now it requires users to log in
again every time.
We can use Cookies to allow the user's
web browser to 'remember' the login.
In GWT, to set the cookie (which you'd
do right after your GWT code receives
the response as we did in the previous
code fragment):
String sessionID = /*(Get sessionID from server's response to your login request.)*/;
final long DURATION = 1000 * 60 * 60 * 24 * 14; //duration remembering login. 2 weeks in this example.
Date expires = new Date(System.currentTimeMillis() + DURATION);
Cookies.setCookie("sid", sessionID, expires, null, "/", false);
Now you can run the following code
right after your !EntryPoint begins
execution:
String sessionID = Cookies.getCookie("sid");
if ( sessionID != null ) checkWithServerIfSessionIdIsStillLegal();
else displayLoginBox();
Remember - you must never rely on the sessionID
sent to your server in the cookie
header ; look only at the sessionID
that your GWT app sends explicitly in
the payload of messages to your
server.
I'm not sure what how your GWT app implemented communication with the login service, but if you want to see another example, I followed the example here:
http://code.google.com/webtoolkit/doc/latest/tutorial/appengine.html#user
While it uses the Google App Engine as the backend authentication service, I think it's generic enough to be adapted to any server that supports the GWT RPC server side and has authentication services.
You need some kind of server-side support to do it.
For example, when user logs in, mark it in the server-side session. In onModuleLoad(), call the server to check whether user is logged in before showing the login form.
Other problems related to pressing Refresh can be solved with history tokens.

Java Swing with database connection

Can anyone please help me on how to create a login form in java swing by using a database connection.
Here's a tutorial to create a simple login form. Replace the pseudo pass check with a check of credentials retrieved via JDBC and you're done. The login form is nothing special...
Create a simple login form and add an event listener to the submit button; and in the handler method write jdbc code to connect to any database.

Categories

Resources