Advertisement
Guest User

GUI

a guest
Dec 14th, 2013
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.43 KB | None | 0 0
  1. package science;
  2.  
  3. import java.awt.*;
  4. import java.awt.event.*;
  5. import java.awt.im.InputContext;
  6. import java.io.IOException;
  7. import java.util.Scanner;
  8.  
  9. import javafx.scene.Scene;
  10. import javafx.scene.chart.BarChart;
  11. import javafx.scene.chart.CategoryAxis;
  12. import javafx.scene.chart.NumberAxis;
  13. import javafx.scene.chart.XYChart;
  14. import javafx.stage.Stage;
  15.  
  16. import javax.swing.*;
  17.  
  18. public class GUI implements ActionListener
  19. {
  20.     static JTextField gender;
  21.     static JTextField password;
  22.     JTextField output;
  23.  
  24.     GUI()      
  25.     {      
  26.         final JFrame jfrm = new JFrame("Password Security");
  27.         jfrm.setLayout(new BorderLayout());
  28.         jfrm.setSize(800, 450);
  29.         jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  30.         gender = new JTextField(10);
  31.         password = new JTextField(10);
  32.         output = new JTextField(10);
  33.         output.setEditable(false);
  34.  
  35.         // Set first panel to retrive data from user
  36.         JPanel inFieldPane = new JPanel();
  37.         inFieldPane.setLayout(new GridLayout(2,2));
  38.         inFieldPane.add(new JLabel("Gender"));
  39.         inFieldPane.add(gender);
  40.         gender.addActionListener(this);
  41.         inFieldPane.add(new JLabel("Password"));
  42.         inFieldPane.add(password);
  43.         password.addActionListener(this);
  44.         jfrm.add(inFieldPane,BorderLayout.NORTH);
  45.  
  46.         //Set second panel to submit data for processing
  47.         JPanel submitPane = new JPanel();
  48.         submitPane.setLayout(new FlowLayout());
  49.         submitPane.add(new JLabel("Press button to submit results"));
  50.         JButton submitButton = new JButton("Submit");
  51.         submitButton.addActionListener(this);
  52.         submitPane.add(submitButton);
  53.         jfrm.add(submitPane,BorderLayout.CENTER);
  54.  
  55.         // Set third panel to display processed data
  56.         JPanel outFieldPane= new JPanel();
  57.         outFieldPane.setLayout(new GridLayout(1,2));
  58.         outFieldPane.add(new JLabel("Output"));
  59.         outFieldPane.add(output);
  60.         jfrm.add(outFieldPane,BorderLayout.SOUTH);     
  61.  
  62.        
  63.        
  64.         jfrm.setVisible(true);
  65.  
  66.         jfrm.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
  67.  
  68.         jfrm.setSize(800, 600);
  69.  
  70.         jfrm.addWindowListener(new WindowListener() {
  71.  
  72.             @Override
  73.             public void windowClosing(WindowEvent e) {
  74.                 if(JOptionPane.showConfirmDialog(jfrm, "Are you sure ?") == JOptionPane.OK_OPTION){
  75.                     jfrm.setVisible(false);
  76.                     jfrm.dispose();
  77.                 }
  78.             }
  79.  
  80.             @Override
  81.             public void windowActivated(WindowEvent e) {
  82.             }
  83.  
  84.             @Override
  85.             public void windowClosed(WindowEvent e) {
  86.             }
  87.  
  88.             @Override
  89.             public void windowDeactivated(WindowEvent e) {
  90.             }
  91.  
  92.             @Override
  93.             public void windowDeiconified(WindowEvent e) {
  94.             }
  95.  
  96.             @Override
  97.             public void windowIconified(WindowEvent e) {
  98.             }
  99.  
  100.             @Override
  101.             public void windowOpened(WindowEvent e) {
  102.             }
  103.         });
  104.  
  105.         jfrm.setVisible(true);
  106.  
  107.     }
  108.  
  109.     public void actionPerformed(ActionEvent e)
  110.     {
  111.         if(e.getActionCommand().equals("Submit"))
  112.         {
  113.             try {
  114.                 pass();
  115.             } catch (IOException e1) {
  116.                 e1.printStackTrace();
  117.             }
  118.         }
  119.     }
  120.  
  121.     public static void pass() throws IOException{
  122.         // Initialize variable count to 0
  123.         String st = password.getText().toString();
  124.         int length = st.length();
  125.         String g = gender.getText().toString();
  126.         String gen = null;     
  127.         int count = 0;
  128.  
  129.         // Convert given string to char array
  130.         char[] c = st.toCharArray();
  131.  
  132.         // Loop till end of string
  133.         for(int i=0;i<st.length();i++)
  134.         {
  135.             // Get ascii value of each char and store it in k
  136.             int k=(int)c[i];
  137.  
  138.             // Digits ascii values start from 48 till 57
  139.             if((k>=48)&&(k<=57))
  140.             {
  141.                 count++;
  142.             }
  143.         }
  144.  
  145.         // Print the no.of digits
  146.         System.out.println("No. of digits are " + count);
  147.  
  148.         // You can also print no.of chars other than digits like..
  149.  
  150.         int chars = (st.length() - count);
  151.         System.out.println("No. of chars other than digits are " + chars);
  152.  
  153.         System.out.println("" + st);
  154.  
  155.         if(g.equalsIgnoreCase("female")){
  156.             gen = "female";
  157.         }else if(g.equalsIgnoreCase("male")){
  158.             gen = "male";
  159.         }else{
  160.             System.out.println("Invalid Gender!");
  161.         }
  162.  
  163.         if(length > 18 && count >= 4){
  164.             FetchData.main(gen + "5" + ".txt");
  165.         }else if(length > 15 && count >= 3){
  166.             FetchData.main(gen + "4" + ".txt");
  167.         }else if(length > 12 && count >= 2){
  168.             FetchData.main(gen + "3" + ".txt");
  169.         }else if(length > 9 && count >= 1){
  170.             FetchData.main(gen + "2" + ".txt");
  171.         }else{
  172.             FetchData.main(gen + "1" + ".txt");
  173.         }
  174.        
  175.         BarGraphHandler.main(null);
  176.     }
  177.    
  178.     public static void main(String[] args)
  179.     {
  180.         SwingUtilities.invokeLater(new Runnable()
  181.         {
  182.             public void run()
  183.             {
  184.                 new GUI();
  185.             }
  186.         });
  187.     }
  188. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement