-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainMenu.java
More file actions
146 lines (114 loc) · 4.12 KB
/
Copy pathMainMenu.java
File metadata and controls
146 lines (114 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package mainframe;
//Required packages
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import sun.audio.*;
public class MainMenu extends JFrame implements ActionListener
{
private static final Dimension MAIN_SIZE = new Dimension(100, 100);
private JPanel mainPanel = new JPanel();//The main panel
public static String uname;
private JButton submit;
private JButton mainMenu;
private JLabel name= new JLabel("ENTER THE USERNAME:");
private JLabel pass= new JLabel("ENTER THE PASSWORD:");
private JLabel conPass= new JLabel("RE-ENTER THE PASSWORD:");
private JTextField username = new JTextField(10);
private JPasswordField password = new JPasswordField( 10 );
private JPasswordField conPassword = new JPasswordField(10);
private JTextField comment= new JTextField("Fill the above to ceate account");
itineraryDBManager IDBM = new itineraryDBManager();
public MainMenu() throws SQLException{
super("LOGIN");//The title bar display text
submit = new JButton("SUBMIT");
mainMenu = new JButton("BACK TO MAIN?");
comment.setEditable(false);
mainPanel.setLayout(new GridLayout(5,2,5,5));
mainPanel.add(name);
mainPanel.add(username);
mainPanel.add(pass);
mainPanel.add(password);
mainPanel.add(conPass);
mainPanel.add(conPassword);
mainPanel.add(submit);
mainPanel.add(mainMenu);
mainPanel.add(comment);
mainPanel.setPreferredSize(MAIN_SIZE);
mainMenu.addActionListener(this);
submit.addActionListener(this);
uname = username.getText();
setLocation(200,200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
getContentPane().add(mainPanel);
setSize(400,400);
setVisible(true);
}
//Function describing the various action events related to the different buttons
public void actionPerformed(ActionEvent evt){
/* the mainMenu button on being clicked
* re directs the user to the main page
*/
if(evt.getSource()==mainMenu){
MainFrame mm= new MainFrame();
mm.setVisible(true);
this.setVisible(false);
}
/*the submit button analyses the input data
* and accordingly creates a new account
* for the end user.It is kept in a try block to
* check for SQLException
*/
try
{
if(evt.getSource()==submit)
{
String check;
String uname;
AudioPlayer MGP = AudioPlayer.player;
AudioStream BGP;
AudioData BP;
ContinuousAudioDataStream loop = null;
try {
BGP = new AudioStream(new FileInputStream("applause.wav"));
BP = BGP.getData();
loop = new ContinuousAudioDataStream(BP);
} catch (IOException ex) {
Logger.getLogger(MainMenu.class.getName()).log(Level.SEVERE, null, ex);
}
MGP.start(loop);
char[] pass1 = password.getPassword();
char[] pass2 = conPassword.getPassword();
uname = username.getText();
String newPass=new String(pass1);
check = IDBM.userCheckTable(uname);
if(!pass2.equals(pass1) && "***".equals(check))
{
IDBM.userTable(uname,newPass);
optionPanel op= new optionPanel(uname);
op.setVisible(true);
this.setVisible(false);
JOptionPane.showMessageDialog(this, "WELCOME! YOUR ACCOUNT HAS BEEN SUCCESSFULLY SET UP.");
}
else if(pass2.equals(pass1) && check == "***")
{
comment.setText("Passwords mis-match!!!");
JOptionPane.showMessageDialog(this,"Passwords mis-match!!!");
}
else
{
comment.setText("Username already exists,please try some other!");
JOptionPane.showMessageDialog(this, "Username already exists,please try some other!");
}
}}
catch (SQLException ex)
{
ex.printStackTrace();
System.exit(0);
}
}}