Article View: borland.public.jbuilder.java.swing
Article #11876Re: JPasswordField
From: Vasudevan Srinivasan
Date: Fri, 09 Apr 1999 00:00
Date: Fri, 09 Apr 1999 00:00
124 lines
4290 bytes
4290 bytes
Hi,
I dont understand why your JPasswordField is active. I have been successfully
using it both in appletviewer, applet and application. here is the part of
code, may be its useful:
public class Applet2 extends JApplet {
boolean isStandalone = false;
//Get a parameter value
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
//Construct the applet
public Applet2() {
}
//Initialize the applet
public void init() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
static {
try {
// //UIManager.setLookAndFeel(new
com.sun.java.swing.plaf.metal.MetalLookAndFeel());
// //UIManager.setLookAndFeel(new
com.sun.java.swing.plaf.motif.MotifLookAndFeel());
UIManager.setLookAndFeel(new
com.sun.java.swing.plaf.windows.WindowsLookAndFeel());
}
catch (Exception e) {}
}
//Component initialization
private void jbInit() throws Exception {
UserLogin up = new UserLogin();
this.getContentPane().add(up);
this.setSize(400,300);
}
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo() {
return null;
}
}
class UserLogin extends JPanel {
JPanel pnlTop = new JPanel();
GridLayout gridLayout1 = new GridLayout(2,2,5,4);
JLabel lblUser = new JLabel("User Name");
JTextField txtUser = new JTextField("");
JLabel lblPassword = new JLabel("Password");
JPasswordField txtPassword = new JPasswordField("");
JPanel pnlBottom = new JPanel();
FlowLayout flowLayout1 = new FlowLayout();
JButton btnOK = new JButton("OK");
JButton btnCancel = new JButton("Cancel");
public UserLogin() {
try { init(); } catch (Exception x) { }
}
private void init() throws Exception {
//pnlTop
pnlTop.setLayout(gridLayout1);
pnlTop.add(lblUser);
pnlTop.add(txtUser);
pnlTop.add(lblPassword);
pnlTop.add(txtPassword);
//pnlBottom
pnlBottom.setLayout(flowLayout1);
pnlBottom.add(btnOK);
pnlBottom.add(btnCancel);
//Add pnls
this.add(pnlTop,BorderLayout.CENTER);
this.add(pnlBottom,BorderLayout.SOUTH);
//getContentPane().pack();//reduce to preferred sizes
txtUser.requestFocus();
//Event Listeners
btnOK.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
btnOK_actionPerformed(e);
}
});
btnCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
btnCancel_actionPerformed(e);
}
});
}
void btnOK_actionPerformed(ActionEvent e) {
txtUser.setText("OK");
}
//Cancel
void btnCancel_actionPerformed(ActionEvent e) {
setVisible(false);
}
}
Hilde wrote:
> My problem is that the JPasswordField will not work even within the applet
> viewer for JBuilder2. While running my applet within JBuilder, the
> JPasswordField seems to be passive/not activated.
> The program I am working with, is a small applet where the user is asked
> to type in his username (here I use a textfield), and later a password
> (JPasswordField). But the problem is that the field is passive, and I am
> not allowed to write any password in it. I made the same program as an
> application, and there I had no problems. What could be wrong?
Technical Details
Message-ID:
<370DFD35.F2988E6B@netrisk.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<370B22D9.C69A56A4@ifi.ntnu.no> <MPG.1175e9a8751b0a8d989b47@forums.inprise.com> <370C717A.34D86808@ifi.ntnu.no> <MPG.1176cffc3f2cedbc989b53@forums.inprise.com> <370DCCE2.DA20CE94@ifi.ntnu.no>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,543b534ddbe059 X-Google-Attributes: gid111d45,public From: Vasudevan Srinivasan <vasudevan@netrisk.com> Subject: Re: JPasswordField Date: 1999/04/09 Message-ID: <370DFD35.F2988E6B@netrisk.com> X-Deja-AN: 464423559 Content-Transfer-Encoding: 7bit References: <370B22D9.C69A56A4@ifi.ntnu.no> <MPG.1175e9a8751b0a8d989b47@forums.inprise.com> <370C717A.34D86808@ifi.ntnu.no> <MPG.1176cffc3f2cedbc989b53@forums.inprise.com> <370DCCE2.DA20CE94@ifi.ntnu.no> To: Hilde <hildepilde@ifi.ntnu.no> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: NetRisk Inc Mime-Version: 1.0 Newsgroups: borland.public.jbuilder.java.swing