Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

JAVA !!need help

Status
Not open for further replies.

xxdxxaxxrxxyxxlxx

Apprentice
Advanced Member
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.
 
Last edited:
* Wag mo i-declare yung accountUn at accountPw na array sa loob ng ActionPerformed na method, sa loob lang siya ng class pero wag mo isama sa loob ng actionperformed method. Pati na rin yung "a at "b" na variable. dapat wala na rin yung unang "a++" kasi nag increment ka na pag successs yung condition
 
Status
Not open for further replies.
Back
Top Bottom