Created
January 4, 2018 14:30
-
-
Save Kishy-nivas/60f3242e4e348ba5a2c1a8ec0f49523a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.swing.*; | |
import java.awt.*; | |
import java.awt.event.*; | |
class Student { | |
private String username; | |
private String pwd; | |
private String cnfm_pwd; | |
private int maths; | |
private int chemistry; | |
private int physics; | |
public Student(String username, String pwd, String cnfm_pwd){ | |
this.username = username; | |
this.pwd = pwd; | |
this.cnfm_pwd = cnfm_pwd; | |
System.out.println("student record created successfully "); | |
} | |
public void setMarks(int maths,int chemistry, int physics){ | |
this.maths = maths; | |
this.chemistry = chemistry; | |
this.physics = physics; | |
} | |
public double getAverage(){ | |
return (double )(this.maths + this.chemistry +this.physics)/3.0; | |
} | |
} | |
class NextPage extends JFrame | |
{ | |
NextPage() | |
{ | |
setDefaultCloseOperation(javax.swing. | |
WindowConstants.DISPOSE_ON_CLOSE); | |
setTitle("Welcome"); | |
setSize(400, 200); | |
} | |
} | |
class Login extends JFrame implements ActionListener | |
{ | |
JButton SUBMIT; | |
JPanel panel; | |
JLabel label1,label2,label3, label4,label5,label6; | |
final JTextField text1,text2,text3,mark1,mark2,mark3; | |
Login() | |
{ | |
label1 = new JLabel(); | |
label1.setText("Username:"); | |
text1 = new JTextField(15); | |
label2 = new JLabel(); | |
label2.setText("Password:"); | |
text2 = new JPasswordField(15); | |
label3 = new JLabel(); | |
label3.setText("confirm Password:"); | |
text3 = new JPasswordField(15); | |
label4 = new JLabel(); | |
label4.setText("Physics "); | |
mark1 = new JTextField(15); | |
label5 = new JLabel(); | |
label5.setText("Chemistry "); | |
mark2 = new JTextField(15); | |
label6 = new JLabel(); | |
label6.setText("maths :"); | |
mark3 = new JTextField(15); | |
SUBMIT=new JButton("SUBMIT"); | |
panel=new JPanel(new GridLayout(15,4)); | |
panel.add(label1); | |
panel.add(text1); | |
panel.add(label2); | |
panel.add(text2); | |
panel.add(label3); | |
panel.add(text3); | |
panel.add(label4); | |
panel.add(mark1); | |
panel.add(label5); | |
panel.add(mark2); | |
panel.add(label6); | |
panel.add(mark3); | |
panel.add(SUBMIT); | |
add(panel,BorderLayout.CENTER); | |
SUBMIT.addActionListener(this); | |
setTitle("LOGIN FORM"); | |
} | |
public void actionPerformed(ActionEvent ae) | |
{ | |
String value1=text1.getText(); | |
String value2=text2.getText(); | |
String value3 =text3.getText(); | |
int physics = Integer.parseInt(mark1.getText()) ; | |
int chemistry = Integer.parseInt(mark2.getText()) ; | |
int maths = Integer.parseInt(mark3.getText()) ; | |
boolean password_check = true ; | |
if(!value3.equals(value2)){ | |
JOptionPane.showMessageDialog(this,"passwords do not match ", | |
"Error",JOptionPane.ERROR_MESSAGE); | |
password_check = false; | |
} | |
if (password_check) | |
{ | |
if (!value1.isEmpty()) { | |
Student s = new Student(value1,value2,value3); | |
s.setMarks(physics,chemistry,maths); | |
NextPage page=new NextPage(); | |
page.setVisible(true); | |
JLabel label = new JLabel("Welcome:"+value1 + "\n account created successfully!" + "your average mark is " + s.getAverage()); | |
page.getContentPane().add(label); | |
} | |
else{ | |
System.out.println("enter the valid username and password"); | |
JOptionPane.showMessageDialog(this,"username can't be blank", | |
"Error",JOptionPane.ERROR_MESSAGE); | |
} | |
} | |
} | |
} | |
class LoginDemo | |
{ | |
public static void main(String arg[]) | |
{ | |
try | |
{ | |
Login frame=new Login(); | |
frame.setSize(500,200); | |
frame.setVisible(true); | |
} | |
catch(Exception e) {JOptionPane.showMessageDialog(null, e.getMessage()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment