- Messages
- 81
- Reaction score
- 0
- Points
- 26
sa mga magaling sa java coding jan paki spot ung mali sa codes ko salamat po.
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
*
*/
public class Loginjava extends JFrame implements ActionListener{
//JPanels
JPanel panel1;
JPanel panel2;
JPanel panel3;
JPanel panel4;
//JLabels
JLabel unLabel;
JLabel pwLabel;
JLabel cpwLabel;
//JTextField
JTextField unJTextField;
JPasswordField pwJTextField;
JPasswordField cpwJTextField;
//JButton
JButton verifyJButton;
JButton createJButton;
JButton clearJButton;
public Loginjava() {
super("Login");
setLayout(new GridLayout(4,1));
//initialization
//JPanels
panel1 = new JPanel();
panel2 = new JPanel();
panel3 = new JPanel();
panel4 = new JPanel();
//JLabels
unLabel = new JLabel("Username:");
pwLabel = new JLabel("Password:");
cpwLabel = new JLabel("Confirm Password:");
//JTextFields
unJTextField = new JTextField();
pwJTextField = new JPasswordField();
cpwJTextField = new JPasswordField();
//JButtons
verifyJButton = new JButton("Verify");
createJButton = new JButton("Create");
clearJButton = new JButton("Clear");
//Add
//Panel
panel1.add(unLabel);
panel1.add(unJTextField);
panel2.add(pwLabel);
panel2.add(pwJTextField);
panel3.add(cpwLabel);
panel3.add(cpwJTextField);
panel4.add(verifyJButton);
panel4.add(createJButton);
panel4.add(clearJButton);
//Panel
panel1.setLayout(new GridLayout(1,2));
panel2.setLayout(new GridLayout(1,2));
panel3.setLayout(new GridLayout(1,2));
panel4.setLayout(new GridLayout(1,3));
add(panel1);
add(panel2);
add(panel3);
add(panel4);
createJButton.addActionListener(this);
verifyJButton.addActionListener(this);
clearJButton.addActionListener(this);
setSize(400,300);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
int a=0;
String[] accountUn = new String [10];
String accountPw[] = new String [10];
if(e.getSource()==createJButton){
String un = unJTextField.getText();
String pw = pwJTextField.getText();
String cpw = cpwJTextField.getText();
a++;
if (cpw.equals(pw)){
accountUn[a]= un;
accountPw[a]= pw;
a++;
JOptionPane.showMessageDialog(rootPane, "Login Successful","Succes", JOptionPane.INFORMATION_MESSAGE);
}
else{
JOptionPane.showMessageDialog(rootPane, "Try again","Sorry", JOptionPane.INFORMATION_MESSAGE);
}
}
else if(e.getSource()==verifyJButton){
String unLogin = unJTextField.getText();
String pwLogin = pwJTextField.getText();
int b=0;
if (unLogin.equals(accountUn)){
JOptionPane.showMessageDialog(rootPane, "Login Succes!","Succes", JOptionPane.INFORMATION_MESSAGE);
}
else
JOptionPane.showMessageDialog(rootPane, "Account does not exist!","Failed", JOptionPane.INFORMATION_MESSAGE);
}
//JOptionPane.showMessageDialog(rootPane, "Account does not exist!","Failed", JOptionPane.INFORMATION_MESSAGE);
else{
unJTextField.setText("");
pwJTextField.setText("");
cpwJTextField.setText("");
}
}
public static void main(String[] args){
new Loginjava();
}
}
TIA.
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
*
*/
public class Loginjava extends JFrame implements ActionListener{
//JPanels
JPanel panel1;
JPanel panel2;
JPanel panel3;
JPanel panel4;
//JLabels
JLabel unLabel;
JLabel pwLabel;
JLabel cpwLabel;
//JTextField
JTextField unJTextField;
JPasswordField pwJTextField;
JPasswordField cpwJTextField;
//JButton
JButton verifyJButton;
JButton createJButton;
JButton clearJButton;
public Loginjava() {
super("Login");
setLayout(new GridLayout(4,1));
//initialization
//JPanels
panel1 = new JPanel();
panel2 = new JPanel();
panel3 = new JPanel();
panel4 = new JPanel();
//JLabels
unLabel = new JLabel("Username:");
pwLabel = new JLabel("Password:");
cpwLabel = new JLabel("Confirm Password:");
//JTextFields
unJTextField = new JTextField();
pwJTextField = new JPasswordField();
cpwJTextField = new JPasswordField();
//JButtons
verifyJButton = new JButton("Verify");
createJButton = new JButton("Create");
clearJButton = new JButton("Clear");
//Add
//Panel
panel1.add(unLabel);
panel1.add(unJTextField);
panel2.add(pwLabel);
panel2.add(pwJTextField);
panel3.add(cpwLabel);
panel3.add(cpwJTextField);
panel4.add(verifyJButton);
panel4.add(createJButton);
panel4.add(clearJButton);
//Panel
panel1.setLayout(new GridLayout(1,2));
panel2.setLayout(new GridLayout(1,2));
panel3.setLayout(new GridLayout(1,2));
panel4.setLayout(new GridLayout(1,3));
add(panel1);
add(panel2);
add(panel3);
add(panel4);
createJButton.addActionListener(this);
verifyJButton.addActionListener(this);
clearJButton.addActionListener(this);
setSize(400,300);
setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
int a=0;
String[] accountUn = new String [10];
String accountPw[] = new String [10];
if(e.getSource()==createJButton){
String un = unJTextField.getText();
String pw = pwJTextField.getText();
String cpw = cpwJTextField.getText();
a++;
if (cpw.equals(pw)){
accountUn[a]= un;
accountPw[a]= pw;
a++;
JOptionPane.showMessageDialog(rootPane, "Login Successful","Succes", JOptionPane.INFORMATION_MESSAGE);
}
else{
JOptionPane.showMessageDialog(rootPane, "Try again","Sorry", JOptionPane.INFORMATION_MESSAGE);
}
}
else if(e.getSource()==verifyJButton){
String unLogin = unJTextField.getText();
String pwLogin = pwJTextField.getText();
int b=0;
if (unLogin.equals(accountUn)){
JOptionPane.showMessageDialog(rootPane, "Login Succes!","Succes", JOptionPane.INFORMATION_MESSAGE);
}
else
JOptionPane.showMessageDialog(rootPane, "Account does not exist!","Failed", JOptionPane.INFORMATION_MESSAGE);
}
//JOptionPane.showMessageDialog(rootPane, "Account does not exist!","Failed", JOptionPane.INFORMATION_MESSAGE);
else{
unJTextField.setText("");
pwJTextField.setText("");
cpwJTextField.setText("");
}
}
public static void main(String[] args){
new Loginjava();
}
}
TIA.
Last edited: