File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SWING GUI ADVICE,PLEASE

 
nitin sharma
Ranch Hand
Posts: 290
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 124
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1492
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 290
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic