Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.67 KB | None | 0 0
  1. package interfaceprojecto;
  2.  
  3. import java.awt.Dimension;
  4. import java.awt.FlowLayout;
  5. import java.awt.GridLayout;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8. import java.awt.event.WindowEvent;
  9. import java.util.Arrays;
  10. import javax.swing.JFrame;
  11. import javax.swing.JPasswordField;//Esconder password
  12. import javax.swing.JFileChooser; //Escolher ficheiro
  13. import javax.swing.*;
  14.  
  15.  
  16. class MenuInicial extends JFrame{ //O que por no registar? (opcoes)
  17.  
  18. private final JLabel welcome; //Texto a dar as boas vindas
  19. private final JButton botLogin;
  20. private final JButton botRegistar;
  21. private final JButton botSair;
  22.  
  23. public MenuInicial(){
  24. this.setPreferredSize (new Dimension(450,300));
  25. this.setTitle("Menu Inicial");
  26. this.setLocation (600,300); //Mais ou menos centrado
  27. this.setVisible(true);
  28. this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
  29. this.setLayout (new GridLayout (4,2,20,20));
  30.  
  31. welcome = new JLabel (" Bem vindo ao Mega Convivio do DEI");
  32. this.add (welcome);
  33.  
  34. botLogin = new JButton("Login");
  35. this.add(botLogin);
  36. botLogin.addActionListener(new ActionListener() {
  37. @Override
  38. public void actionPerformed(ActionEvent e) {
  39. Login Interface = new Login();
  40. dispose();
  41. }
  42. });
  43.  
  44. botRegistar = new JButton("Registar");
  45. this.add(botRegistar);
  46. botRegistar.addActionListener(new ActionListener() {
  47. @Override
  48. public void actionPerformed(ActionEvent e) {
  49. Registar r = new Registar();
  50. dispose();
  51. }
  52. });
  53.  
  54. botSair = new JButton("Sair");
  55. this.add(botSair);
  56. botSair.addActionListener(new ActionListener() {
  57. @Override
  58. public void actionPerformed(ActionEvent e) {
  59. System.exit(0);
  60. }
  61. });
  62.  
  63. this.pack();
  64. }
  65. }
  66.  
  67.  
  68.  
  69. /***************************REGISTAR**************************************************************************************************/
  70.  
  71. class Registar extends JFrame{
  72.  
  73. private final JTextField nome;
  74. private final JTextField username;
  75. private final JPasswordField password;
  76. private final JPasswordField confirmapass;
  77.  
  78. private final JComboBox showpass;
  79.  
  80. private final JLabel label0;
  81. private final JLabel label1;
  82. private final JLabel label2;
  83. private final JLabel label3;
  84.  
  85.  
  86. private final JButton botEntrar; //Para fazer login
  87. private final JButton botLimpa; //Decidir se limpa tudo ou apenas um dos campos
  88. private final JButton botSai;
  89. private final JButton botRetroceder;
  90.  
  91.  
  92. public Registar() {
  93. this.setPreferredSize (new Dimension(600,450));
  94. this.setTitle("Registar");
  95. this.setLocation (600,300); //Mais ou menos centrado
  96. this.setVisible(true);
  97. this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
  98. //this.setLayout(new FlowLayout());
  99.  
  100.  
  101. //final JPanel grid = new JPanel(new FlowLayout());
  102. this.setLayout (new GridLayout (7,2,15,15));
  103. //this.add(grid);
  104.  
  105.  
  106. label0 = new JLabel ("Nome");
  107. this.add (label0);
  108.  
  109. nome = new JTextField();
  110. this.add(nome);
  111. nome.setPreferredSize (new Dimension(100,20));
  112. nome.addActionListener (new ActionListener() {
  113. @Override
  114. public void actionPerformed(ActionEvent e) {
  115. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  116. }
  117. }); //Mudar o método abstrato
  118.  
  119. label1 = new JLabel ("Escolher Username");
  120. this.add (label1);
  121.  
  122. username = new JTextField();
  123. this.add(username);
  124. username.setPreferredSize (new Dimension(100,20));
  125. username.addActionListener (new ActionListener() {
  126. @Override
  127. public void actionPerformed(ActionEvent e) {
  128. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  129. }
  130. }); //Mudar o método abstrato
  131.  
  132.  
  133. label2 = new JLabel ("Escolher Password");
  134. this.add (label2);
  135.  
  136. password = new JPasswordField(); //cria novo objeto
  137. this.add(password); //adiciona ao container
  138. password.setPreferredSize (new Dimension(100,20));
  139. password.addActionListener (new ActionListener() {
  140. @Override
  141. public void actionPerformed(ActionEvent e) {
  142.  
  143. password.setToolTipText("A password tem que ter pelo menos 5 carateres");
  144.  
  145. }
  146. }); //Mudar o método abstrato
  147.  
  148.  
  149. label3 = new JLabel ("Confirmar Password");
  150. this.add (label3);
  151.  
  152. confirmapass = new JPasswordField();
  153. this.add(confirmapass);
  154. confirmapass.setPreferredSize (new Dimension(100,20));
  155. confirmapass.addActionListener (new ActionListener() {
  156. @Override
  157. public void actionPerformed(ActionEvent e) {
  158.  
  159. if ((password.getPassword()).equals(confirmapass)){
  160.  
  161. }
  162. else{
  163. System.out.println("As passwords tem que ser iguais");
  164. }
  165. }
  166. }); //Mudar o método abstrato
  167.  
  168. //SHOW PASSWORDDDDDDDDDDDDDDDD
  169.  
  170. //char[] pass = password.getPassword();
  171. //String pass = new String(password.getPassword());
  172. char[] correctpass = {'b','a','t','a','t','a'};
  173. //String correctpass = "batata";
  174.  
  175. botEntrar = new JButton("Entrar");
  176. this.add(botEntrar);
  177. botEntrar.addActionListener(new ActionListener() {
  178. @Override
  179. public void actionPerformed(ActionEvent e) {
  180. username.getText();
  181. password.getPassword();
  182. confirmapass.getPassword();
  183.  
  184. if (Arrays.equals(password.getPassword(),confirmapass.getPassword())) {
  185. System.out.println("Registo bem sucedido");
  186. EscolhaLocais escolhe = new EscolhaLocais();
  187. dispose();
  188. } else {
  189. JOptionPane.showMessageDialog(rootPane, "As passwords têm que ser iguais", "Erro", JOptionPane.ERROR_MESSAGE);
  190. }
  191.  
  192.  
  193. }
  194. });
  195. //Dentro do metodo abstrato, verificar se o username esta nos registados
  196. //e se a password corresponde a password desse username
  197. //Se sim, login successful Se nao, erro
  198.  
  199.  
  200. botLimpa = new JButton("Limpa");
  201. this.add(botLimpa);
  202. botLimpa.addActionListener(new ActionListener() {
  203. @Override
  204. public void actionPerformed(ActionEvent e) {
  205. username.setText("");
  206. password.setText("");
  207. }
  208. });
  209.  
  210.  
  211. botSai = new JButton ("Sai");
  212. this.add(botSai);
  213. botSai.addActionListener(new ActionListener() {
  214. @Override
  215. public void actionPerformed(ActionEvent e) {
  216. System.exit(0);
  217. }
  218. });
  219.  
  220.  
  221. botRetroceder = new JButton ("Retroceder");
  222. this.add(botRetroceder);
  223. botRetroceder.addActionListener(new ActionListener() {
  224. @Override
  225. public void actionPerformed(ActionEvent e) {
  226. MenuInicial m = new MenuInicial();
  227. dispose();
  228. }
  229. });
  230.  
  231.  
  232. JFrame self = this;
  233.  
  234. String [] opcao = new String []{"Mostrar Password","Esconder Password"};
  235. // JComboBox<String> oplist = new JComboBox<>(opcao);
  236.  
  237.  
  238. showpass = new JComboBox (opcao);
  239. showpass.addActionListener(new ActionListener(){
  240. @Override
  241. public void actionPerformed(ActionEvent event) {
  242. JComboBox <String> oplist = (JComboBox<String>)event.getSource();
  243. String opcao = (String) oplist.getSelectedItem();
  244.  
  245. if (opcao.equals("Mostrar Password")){
  246. password.setEchoChar((char)0);
  247. confirmapass.setEchoChar((char)0);
  248. }
  249. else{
  250. password.setEchoChar('•');
  251. confirmapass.setEchoChar('•');
  252. }
  253.  
  254.  
  255.  
  256. }
  257. });
  258. this.add(showpass);
  259.  
  260.  
  261.  
  262. this.pack();
  263. }
  264. }
  265.  
  266.  
  267. /***************************LOGIN********************************************************************************************/
  268.  
  269. class Login extends JFrame{
  270.  
  271. private final JTextField username;
  272. //private final JTextField password;
  273.  
  274. private final JPasswordField password;
  275.  
  276. private final JComboBox showpass;
  277.  
  278. private final JLabel label1;
  279. private final JLabel label2;
  280.  
  281. private final JButton botEntrar; //Para fazer login
  282. private final JButton botLimpa; //Decidir se limpa tudo ou apenas um dos campos
  283. private final JButton botSai;
  284. private final JButton botRetroceder;
  285.  
  286. public Login() {
  287. this.setPreferredSize (new Dimension(600,450));
  288. this.setTitle("Login");
  289. this.setLocation (600,300); //Mais ou menos centrado
  290. this.setVisible(true);
  291. this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
  292. //this.setLayout(new FlowLayout());
  293.  
  294.  
  295. //final JPanel grid = new JPanel(new FlowLayout());
  296. this.setLayout (new GridLayout (7,2,15,15));
  297. //this.add(grid);
  298.  
  299.  
  300. label1 = new JLabel ("Username");
  301. this.add (label1);
  302. username = new JTextField();
  303. this.add(username);
  304. username.setPreferredSize (new Dimension(100,20));
  305. username.addActionListener (new ActionListener() {
  306. @Override
  307. public void actionPerformed(ActionEvent e) {
  308. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  309. }
  310. }); //Mudar o método abstrato
  311.  
  312.  
  313. label2 = new JLabel ("Password");
  314. this.add (label2);
  315. password = new JPasswordField(); //cria novo objeto
  316.  
  317. //password.setEchoChar((char)0);
  318. //password = new JTextField();
  319. this.add(password); //adiciona ao container
  320. password.setPreferredSize (new Dimension(100,20));
  321. password.addActionListener (new ActionListener() {
  322. @Override
  323. public void actionPerformed(ActionEvent e) {
  324.  
  325. password.setToolTipText("A password tem que ter pelo menos 5 carateres");
  326.  
  327. }
  328. }); //Mudar o método abstrato
  329.  
  330. //char[] pass = password.getPassword();
  331. //String pass = new String(password.getPassword());
  332. char[] correctpass = {'b','a','t','a','t','a'};
  333. //String correctpass = "batata";
  334.  
  335. botEntrar = new JButton("Entrar");
  336. this.add(botEntrar);
  337. botEntrar.addActionListener(new ActionListener() {
  338. @Override
  339. public void actionPerformed(ActionEvent e) {
  340. username.getText();
  341. password.getPassword();
  342.  
  343.  
  344. if(Arrays.equals(password.getPassword(), correctpass)){
  345. System.out.println("Password correta");
  346. dispose();
  347. EscolhaLocais escolhe = new EscolhaLocais();
  348. } else {
  349. System.out.println ("Password incorreta");
  350. }
  351.  
  352.  
  353. }
  354. });
  355. //Dentro do metodo abstrato, verificar se o username esta nos registados
  356. //e se a password corresponde a password desse username
  357. //Se sim, login successful Se nao, erro
  358.  
  359.  
  360. botLimpa = new JButton("Limpa");
  361. this.add(botLimpa);
  362. botLimpa.addActionListener(new ActionListener() {
  363. @Override
  364. public void actionPerformed(ActionEvent e) {
  365. username.setText("");
  366. password.setText("");
  367. }
  368. });
  369.  
  370. botSai = new JButton ("Sai");
  371. this.add(botSai);
  372. botSai.addActionListener(new ActionListener() {
  373. @Override
  374. public void actionPerformed(ActionEvent e) {
  375. System.exit(0);
  376. }
  377. });
  378.  
  379. botRetroceder = new JButton ("Retroceder");
  380. this.add(botRetroceder);
  381. botRetroceder.addActionListener(new ActionListener() {
  382. @Override
  383. public void actionPerformed(ActionEvent e) {
  384. MenuInicial m = new MenuInicial();
  385. //this.dispose(); //Remove JFrame 1
  386. //JFrame2.setVisible(true) //Show other frame
  387. dispose();
  388. }
  389. });
  390.  
  391.  
  392. JFrame self = this;
  393.  
  394. String [] opcao = new String []{"Mostrar Password","Esconder Password"};
  395. // JComboBox<String> oplist = new JComboBox<>(opcao);
  396.  
  397. showpass = new JComboBox (opcao);
  398. showpass.addActionListener(new ActionListener(){
  399. @Override
  400. public void actionPerformed(ActionEvent event) {
  401. JComboBox <String> oplist = (JComboBox<String>)event.getSource();
  402. String opcao = (String) oplist.getSelectedItem();
  403.  
  404. if (opcao.equals("Mostrar Password")){
  405. password.setEchoChar((char)0);
  406. }
  407. else{
  408. password.setEchoChar('•');
  409. }
  410. }
  411. });
  412. this.add(showpass);
  413.  
  414. this.pack();
  415. }
  416. }
  417.  
  418.  
  419. /***************************ESCOLHA_LOCAIS************************************************************************************/
  420.  
  421. class EscolhaLocais extends JFrame{
  422.  
  423. private final JComboBox locais;
  424.  
  425. private final JButton botEscolheLocal;
  426. private final JButton botShowGuest;
  427. private final JButton botReceitaMin;
  428. private final JButton botRetroceder;
  429.  
  430. public EscolhaLocais(){
  431. this.setPreferredSize (new Dimension(500,400));
  432. this.setTitle("Escolha Locais");
  433. this.setLocation (600,300); //Mais ou menos centrado
  434. this.setVisible(true);
  435. this.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
  436. this.setLayout(new GridLayout (5,1,30,30));
  437.  
  438.  
  439.  
  440. botEscolheLocal = new JButton ("Escolhe locais");
  441. this.add(botEscolheLocal);
  442.  
  443. botShowGuest = new JButton ("Show Guest Lists");
  444. this.add(botShowGuest);
  445.  
  446. botReceitaMin = new JButton ("Receita Minima Prevista");
  447. this.add(botReceitaMin);
  448.  
  449. botRetroceder = new JButton ("Retroceder");
  450. this.add(botRetroceder);
  451. botRetroceder.addActionListener(new ActionListener() {
  452. @Override
  453. public void actionPerformed(ActionEvent e) {
  454. Login Interface = new Login();
  455. dispose();
  456. }
  457. });
  458.  
  459.  
  460.  
  461.  
  462. JFrame self = this;
  463. locais = new JComboBox (new String[] {"Jardim", "Exposicao", "Bar"});
  464. locais.addActionListener(new ActionListener() {
  465. @Override
  466. public void actionPerformed(ActionEvent e) {
  467. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
  468. }
  469. }); //Mudar metodo abstrato
  470. this.add (locais);
  471.  
  472. this.pack();
  473. }
  474.  
  475.  
  476. }
  477.  
  478. interface Filter{
  479. int convert (int x);
  480. }
  481.  
  482. public class InterfaceProjecto {
  483. public static void main(String[] args) {
  484. MenuInicial m = new MenuInicial();
  485.  
  486. //Login Interface = new Login();
  487. //Registar r = new Registar();
  488. //EscolhaLocais escolhe = new EscolhaLocais();
  489.  
  490. }
  491.  
  492. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement