HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavaMinor

Login for desktop application

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
loginforapplicationdesktop

Problem

I am building a login using an API call to a URL that returns JSON data. The login works and is functional but in terms of "correctness" and "professionalism", I am looking to get input from some of the devs here. Please give me an tips that could possibly aide in making the most functional program here possible. (Please note I am using MATISSE to create the GUI)

This section is the Login GUI. Left out Matisse generate text:

```
public class LogIn extends javax.swing.JFrame {
ImageIcon imageIcon;
/**
* Creates new form LogIn
*/
public LogIn()
{
imageIcon = new ImageIcon(LogIn.this.getClass().getResource("/Res/loading.gif"));
initComponents();
}

/*
This actually completes the login and displays the LOADING dialog box.
*/
class loginAction extends AbstractAction {
LoginHandle lh = new LoginHandle();
String devid = "&t2mdeveloperid=#####-####-####-####-#######";
String account, username, password;
String[] loginDataArr;

@Override
public void actionPerformed(ActionEvent evt)
{
SwingWorker mySwingWorker = new SwingWorker()
{
@Override
protected Void doInBackground() throws Exception
{
account = "&t2maccount=" + txtAccount.getText();
username = "&t2musername=" + txtUsername.getText();
password = "&t2mpassword=" + txtPassword.getText();
loginDataArr = lh.loginData(account, username, password, devid);
return null;
}
};

Window win = SwingUtilities.getWindowAncestor((AbstractButton)evt.getSource());
mySwingWorker.addPropertyChangeListener(new PropertyChangeListener()
{
@Override
public void propertyChange(PropertyChangeEvent evt)
{

if (evt.getPropertyName().equals("state"))
{
if (evt.getNewValue() == SwingWorker.StateValue.DONE)
{
loadingDialog.dispose();
}
}
}

Solution

-
lh isn't a clear variable name (unless it's used in immediate context only, but it isn't here). I'd rather call it loginHandle.

-
devid misses camel case. I'd name it developerId.

-
String[] loginDataArr;: It's obvious that this is an array. I'd not state it extra.

-
Why is your URLConnection called yc?

-
brreminds me of
every time I look at it. And it refers to a technical aspect. I rather like to see where I get data from or where I put them to. I prefer to call my streams/readers/writers inSomething/outSomething. So it'd be inUrlConnection (or inUC if you like it short) in your case. But that might be personal taste.

-
I'd rename strTemp to line since this is what it is supposed to contain.

Context

StackExchange Code Review Q#93096, answer score: 6

Revisions (0)

No revisions yet.