File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes SWING GUI  ADVICE,PLEASE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "SWING GUI  ADVICE,PLEASE" Watch "SWING GUI  ADVICE,PLEASE" New topic
Author

SWING GUI ADVICE,PLEASE

nitin sharma
Ranch Hand

Joined: Feb 24, 2001
Posts: 290
Hello swing expert's,
I need your experienced adivice.I have created a GUI, code of which i will show to u in a moment.
Have a look at the given code and tell me whether that gui will look good in a real project or not.Any suggestions are most welcome.
import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
class lap extends JFrame
{

boolean b=true;
JPanel p,p1,p3,p4;
GridBagLayout g;
GridBagConstraints c;
JLabel l2,l3,l4;
JButton b1,b2,b3;
JTextField f;
JPasswordField j;
JLabel h;
public lap()
{
g=new GridBagLayout();
c=new GridBagConstraints();
l2=new JLabel("GRAPHICAL USER INTERFACE");
l2.setForeground(Color.black);
p=new JPanel();
getContentPane().add(p,"North");
p.setLayout(g);
//c.gridx=;
p.add(l2,c);
setSize(700,700);
setVisible(true);
p.setBackground(Color.yellow);
l3=new JLabel("USER NAME");
p1=new JPanel();
getContentPane().add(p1,"Center");
c.gridx=100;
c.gridy=250;
//c.insets=new Insets(0,5,0,0);
l3.setForeground(Color.black);
p1.setLayout(g);
p1.add(l3,c);
p1.setBackground(Color.white);
l4=new JLabel("PASSWORD");
c.gridx=100;
c.gridy=350;
//c.insets=new Insets(30,0,0,0);
l4.setForeground(Color.black);
p1.add(l4,c);
f=new JTextField(20);
c.gridx=200;
c.gridy=250;
c.insets=new Insets(0,10,0,0);
f.setForeground(Color.white);
f.setBackground(Color.black);
p1.add(f,c);
j=new JPasswordField(20);
c.gridx=200;
c.gridy=350;
//c.insets=new Insets(0,10,0,0);
c.insets=new Insets(0,10,0,0);
j.setForeground(Color.white);
j.setBackground(Color.black);
//p1.setBackground(Color.white);
p1.add(j,c);

p3=new JPanel();
getContentPane().add(p3,"South");
b1=new JButton("CHECK PASSWORD");
p3.setLayout(g);
c.gridx=200;
c.gridy=400;
b1.setForeground(Color.white);
b1.setBackground(Color.black);
p3.add(b1,c);
b2=new JButton("CANCEL");
c.gridx=400;
c.gridy=400;
b2.setForeground(Color.white);
b2.setBackground(Color.black);
p3.add(b2,c);
p3.setBackground(Color.pink);

p4=new JPanel();
getContentPane().add(p4,"West");
p4.setLayout(g);
h=new JLabel("YOUR PASSWORD SHOULD BE NITIN");
p4.add(h);
h.setForeground(Color.white);
p4.setBackground(Color.black);

for(;
{
if(b)
{
l2.setVisible(false);
b=false;
try
{
Thread.sleep(2000);
}
catch(Exception e)
{
}
}
else
{
l2.setVisible(true);
b=true;
try
{
Thread.sleep(2000);
}
catch(Exception e)
{
}
}
}
}
public static void main(String[]args)
{
lap l=new lap();
}
}
Ashwin Desai
Ranch Hand

Joined: Jul 17, 2000
Posts: 124
Hi,
It is difficult to visualize a GUI just looking at the code. A better way would be to run the program and check it out.
Ashwin.
[This message has been edited by Ashwin Desai (edited May 15, 2001).]
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Nitin,
In my opinion, no.
Having the textfields background being black is annoying because the user has no feedback on focus. Since the cursor is shown in black you should always have a light background and a dark foreground. Users are used to that color scheme and having something else will just cause immediate judgements that won't go in your favor a majority of the time.
Also no user wants to see something constantly flashing that doesn't require immediate attention. Your top label flashing, might be fun to program, but a user doesn't want it. Trust me on this. In the late 80s I was involved in a UI training session with DARPA that proved that flashing on monitors could cause temporary insanity if done at a certain frequency and amount.
Also, I would get rid of the check password button. Use the action event generated from the textfields. For example:
ActionEvent for user name:
If we have user name
If we have password
run check
ActionEvent for password:
If we have user name
If we have password
run check
IMO, I would limit the use of color because most people are used to windows specific colors (set in control panel) which will be passed around through the java heirarchy if you don't specify them.
Good Luck,
Manfred.
nitin sharma
Ranch Hand

Joined: Feb 24, 2001
Posts: 290
Thank's a lot manfred for a wonderful advice,please tell why yahoo is having so many thing's which are very flashy.?Where actually we can use all these flashy thing's..?
jeremy hull
Greenhorn

Joined: Jan 18, 2001
Posts: 10
Usually in production code you want to have meaningful variable names like okButton, or the like. Also take advantage of JavaDoc, it is a great tool. Your code may be easy to work on, but in a large and comlicated system, or one where many engineers are involved there should be copious documentation.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Yahoo is trying to sell things to make money. Flashing things catch peoples eye.
An application is not supposed to divert your attention to something else.


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: SWING GUI ADVICE,PLEASE