Need help on setting the values of username and password for my log-in menu:
import javax.swing.*;
import java.awt.*;
class Profile extends JFrame
{
private JPanel p,p1,p2,p3;
private JTextField tf;
private JPasswordField pf;
private JLabel l1,l2;
private JButton b;
Profile()
{
p = new JPanel();
p1 = new JPanel();
p2 = new JPanel();
p3 = new JPanel();
tf = new JTextField(10);
pf = new JPasswordField(10);
l1 = new JLabel("Enter username: ");
l2 = new JLabel("Enter password: ");
b = new JButton("Log-in");
getContentPane().setLayout(new BoxLayout(getContentPane(),BoxLayout.Y_AXIS));
add(p);
p.add(p1,BorderLayout.CENTER);
p.add(p2,BorderLayout.CENTER);
p.add(p3,BorderLayout.CENTER);
p1.add(l1);
p1.add(tf);
p2.add(l2);
p2.add(pf);
p3.add(b);
}
}
public class TestProject {
public static void main(String[] args) {
Profile p = new Profile();
p.setBounds(200,200,270,165);
p.setVisible(true);
p.setResizable(false);
p.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
and... is it possible that when I clicked the log-in button this will appear:
import javax.swing.*;
import java.awt.*;
class Profile extends JFrame
{
private JPanel p,p1,p2,p3,p4,p5;
private JLabel l1,l2,l3,l4;
private JTextField tf1,tf2,tf3,tf4;
private JButton b1,b2,b3;
private JTextArea ta;
Profile()
{
p = new JPanel();
p.setLayout(new BoxLayout(p,BoxLayout.Y_AXIS));
p1 = new JPanel();
p1.setLayout(new GridLayout(2,2));
p2 = new JPanel();
p2.setLayout(new BorderLayout());
p3 = new JPanel();
p4 = new JPanel();
p4.setLayout(new BorderLayout());
p5 = new JPanel();
l1 = new JLabel("Name: ");
l2 = new JLabel("CWA: ");
l3 = new JLabel("Course/Year: ");
l4 = new JLabel("ID number: ");
tf1 = new JTextField(17);
tf2 = new JTextField(17);
tf3 = new JTextField(17);
tf4 = new JTextField(17);
b1 = new JButton(" OK ");
b2 = new JButton(" ADD ");
b3 = new JButton(" DELETE ");
String x = "";
ta = new JTextArea(x,30,72);
ta.setEditable(false);
add(p);
p.add(p1);
p.add(p2);
p.add(p3);
p.add(p4);
p1.add(l1);
p1.add(tf1);
p1.add(l2);
p1.add(tf2);
p1.add(l3);
p1.add(tf3);
p1.add(l4);
p1.add(tf4);
p2.add(b1,BorderLayout.EAST);
p3.add(ta);
p4.add(p5,BorderLayout.EAST);
p5.add(b2);
p5.add(b3);
}
}
public class TestProject1 {
public static void main(String[] args) {
Profile p = new Profile();
p.setBounds(270,100,800,600);
p.setVisible(true);
p.setResizable(false);
p.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
I'm just new to java and only know how to code for the GUI :)
Thanks in advance :)