Skip to content

Commit 5434f2e

Browse files
authored
Update index.jsp
1 parent 38f35e0 commit 5434f2e

File tree

1 file changed

+120
-3
lines changed

1 file changed

+120
-3
lines changed

webapp/src/main/webapp/index.jsp

Lines changed: 120 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,120 @@
1-
<h1> Hello !! Welcome to DevOps Project-2 !! </h1>
2-
<h2> By Mr.Shubham </h2>
3-
<h2> Project done </h2>
1+
//<h1> Hello !! Welcome to DevOps Project-2 !! </h1>
2+
//<h2> By Mr.Shubham </h2>
3+
//<h2> Project done </h2>
4+
//import required classes and packages
5+
import javax.swing.*;
6+
import java.awt.*;
7+
import java.awt.event.*;
8+
import java.lang.Exception;
9+
10+
//create CreateLoginForm class to create login form
11+
//class extends JFrame to create a window where our component add
12+
//class implements ActionListener to perform an action on button click
13+
class CreateLoginForm extends JFrame implements ActionListener
14+
{
15+
//initialize button, panel, label, and text field
16+
JButton b1;
17+
JPanel newPanel;
18+
JLabel userLabel, passLabel;
19+
final JTextField textField1, textField2;
20+
21+
//calling constructor
22+
CreateLoginForm()
23+
{
24+
25+
//create label for username
26+
userLabel = new JLabel();
27+
userLabel.setText("Username"); //set label value for textField1
28+
29+
//create text field to get username from the user
30+
textField1 = new JTextField(15); //set length of the text
31+
32+
//create label for password
33+
passLabel = new JLabel();
34+
passLabel.setText("Password"); //set label value for textField2
35+
36+
//create text field to get password from the user
37+
textField2 = new JPasswordField(15); //set length for the password
38+
39+
//create submit button
40+
b1 = new JButton("SUBMIT"); //set label to button
41+
42+
//create panel to put form elements
43+
newPanel = new JPanel(new GridLayout(3, 1));
44+
newPanel.add(userLabel); //set username label to panel
45+
newPanel.add(textField1); //set text field to panel
46+
newPanel.add(passLabel); //set password label to panel
47+
newPanel.add(textField2); //set text field to panel
48+
newPanel.add(b1); //set button to panel
49+
50+
//set border to panel
51+
add(newPanel, BorderLayout.CENTER);
52+
53+
//perform action on button click
54+
b1.addActionListener(this); //add action listener to button
55+
setTitle("LOGIN FORM"); //set title to the login form
56+
}
57+
58+
//define abstract method actionPerformed() which will be called on button click
59+
public void actionPerformed(ActionEvent ae) //pass action listener as a parameter
60+
{
61+
String userValue = textField1.getText(); //get user entered username from the textField1
62+
String passValue = textField2.getText(); //get user entered pasword from the textField2
63+
64+
//check whether the credentials are authentic or not
65+
if (userValue.equals("[email protected]") && passValue.equals("test")) { //if authentic, navigate user to a new page
66+
67+
//create instance of the NewPage
68+
NewPage page = new NewPage();
69+
70+
//make page visible to the user
71+
page.setVisible(true);
72+
73+
//create a welcome label and set it to the new page
74+
JLabel wel_label = new JLabel("Welcome: "+userValue);
75+
page.getContentPane().add(wel_label);
76+
}
77+
else{
78+
//show error message
79+
System.out.println("Please enter valid username and password");
80+
}
81+
}
82+
}
83+
//create the main class
84+
class LoginFormDemo
85+
{
86+
//main() method start
87+
public static void main(String arg[])
88+
{
89+
try
90+
{
91+
//create instance of the CreateLoginForm
92+
CreateLoginForm form = new CreateLoginForm();
93+
form.setSize(300,100); //set size of the frame
94+
form.setVisible(true); //make form visible to the user
95+
}
96+
catch(Exception e)
97+
{
98+
//handle exception
99+
JOptionPane.showMessageDialog(null, e.getMessage());
100+
}
101+
}
102+
}
103+
NewPage.java
104+
105+
//import required classes and packages
106+
import javax.swing.*;
107+
import java.awt.*;
108+
109+
//create NewPage class to create a new page on which user will navigate
110+
class NewPage extends JFrame
111+
{
112+
//constructor
113+
NewPage()
114+
{
115+
setDefaultCloseOperation(javax.swing.
116+
WindowConstants.DISPOSE_ON_CLOSE);
117+
setTitle("Welcome");
118+
setSize(400, 200);
119+
}
120+
}

0 commit comments

Comments
 (0)