i have a problem in my application.it has no syntax error but my
button can't work..my first two buttons work pretty well but my last
button dun seems to work.i have the same codes as the two
butons...can anyone help look at my codes..thanks.my button s cant
work.
class PasswordBox extends JFrame
{
private JTextField username;
private JPasswordField password;
private JButton ok, cancel, s;
private JFrame PasswordBox;
public PasswordBox()
{
super("Unlock Screensaver"); //set the frame size
setSize(310,120);
JPanel backPanel = new JPanel();
backPanel.setLayout(new BorderLayout());
backPanel.setBackground(Color.blue);
JPanel panel = new JPanel();
username = new JTextField(5);
panel.add(new JLabel("Username:", JLabel.RIGHT));
panel.add(username);
password = new JPasswordField(5);
panel.add(new JLabel("Password:", JLabel.RIGHT));
panel.add(password);
backPanel.add(panel, BorderLayout.CENTER);
JPanel OKPanel = new JPanel();
ok = new JButton("OK");
OKPanel.add(ok, BorderLayout.WEST);
//add listener to the 'ok' button
ok.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == ok)
{
if(username.getText().trim().equals
("fyp"))
{
if(password.getText().trim
().equals("fyp"))
{
System.exit(0);
}
}
else
{
clearInputFields();
}
}
}
});
JPanel CANCELPanel = new JPanel();
cancel = new JButton("CANCEL");
CANCELPanel.add(cancel, BorderLayout.CENTER);
//add listener to the 'cancel' button
cancel.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == cancel)
{
setVisible(false);
dispose();
}
}
});
JPanel SCREENPanel = new JPanel();
s = new JButton("SCREENSAVER");
SCREENPanel.add(s, BorderLayout.EAST);
//add listener to the 'screensaver' button
s.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == s)
{
//PasswordBox pSaver = new PasswordBox
();
setVisible(false);
dispose();
}
}
});
JPanel buttonPanelss = new JPanel();
buttonPanelss.add(OKPanel);
buttonPanelss.add(CANCELPanel);
buttonPanelss.add(SCREENPanel);
backPanel.add(buttonPanelss, BorderLayout.SOUTH);
setContentPane(backPanel);
// Center the box
Dimension screenDim =
Toolkit.getDefaultToolkit().getScreenSize();
Rectangle frameDim = getBounds();
setLocation((screenDim.width - frameDim.width)
/ 2,(screenDim.height - frameDim.height) / 2);
}
public void clearInputFields()
{
username.setText("");
password.setText("");
}
}