I am trying to reposition a password field inside my JFrame using the method setBounds but it doesn't seem to be doing anything. Here is the code, I am completely new to this stuff so I have no idea if the order of any of this matters or what...
Code:
package atm;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeEvent;
public class ATM_Main
{
static Customer customer;
static JFormattedTextField pinField;
static int pinEntered;
public static void main(String[] args)
{
pinEntered = 0;
customer = new Customer();
welcomeScreen();
}
public static void welcomeScreen()
{
JFrame frame = new JFrame("welcome");
Container content = frame.getContentPane();
content.setLayout(new FlowLayout());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
frame.setResizable(false);
frame.setBounds(0, 0, 640, 480);
content.setBackground(Color.black);
Font font = new Font("Arial", Font.PLAIN, 100);
content.setFont(font);
String labelText1 = "<html><FONT COLOR=WHITE SIZE=6>Welcome to Group 8 Bank</FONT></html>";
String labelText2 = "Please Swipe Your Card to Begin";
//JLabel label1 = new JLabel(labelText1, JLabel.CENTER);
JLabel label1 = new JLabel(labelText1);
label1.setForeground(Color.white);
label1.setBounds(300, 0, 400, 20);
content.add(label1);
JPasswordField pinField = new JPasswordField(4);
pinField.setBounds(170, 100, 200, 20);
pinField.setBackground(Color.white);
pinField.setEchoChar('*');
pinField.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JPasswordField input = (JPasswordField)e.getSource();
char[] password = input.getPassword();
if(checkPin(password))
{
//JOptionPane.showMessageDialog(frame, "Correct password.");
//Continue to next screen
}
else
{
//JOptionPane.showMessageDialog(frame, "Incorrect PIN.", "Error Message", JOptionPane.ERROR_MESSAGE);
}
}
});
content.add(pinField);
frame.validate();
}
private static boolean checkPin(char[] inputPassword)
{
char[] actualPassword = {'1', '1', '1', '1'};
if(inputPassword.length != actualPassword.length)
{
return false; //Return false if lengths are unequal
}
for (int i = 0; i < inputPassword.length; i ++)
{
if (inputPassword[i] != actualPassword[i])
{
return false;
}
}
return true;
}
}