Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package science;
- import java.awt.*;
- import java.awt.event.*;
- import java.awt.im.InputContext;
- import java.io.IOException;
- import java.util.Scanner;
- import javafx.scene.Scene;
- import javafx.scene.chart.BarChart;
- import javafx.scene.chart.CategoryAxis;
- import javafx.scene.chart.NumberAxis;
- import javafx.scene.chart.XYChart;
- import javafx.stage.Stage;
- import javax.swing.*;
- public class GUI implements ActionListener
- {
- static JTextField gender;
- static JTextField password;
- JTextField output;
- GUI()
- {
- final JFrame jfrm = new JFrame("Password Security");
- jfrm.setLayout(new BorderLayout());
- jfrm.setSize(800, 450);
- jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- gender = new JTextField(10);
- password = new JTextField(10);
- output = new JTextField(10);
- output.setEditable(false);
- // Set first panel to retrive data from user
- JPanel inFieldPane = new JPanel();
- inFieldPane.setLayout(new GridLayout(2,2));
- inFieldPane.add(new JLabel("Gender"));
- inFieldPane.add(gender);
- gender.addActionListener(this);
- inFieldPane.add(new JLabel("Password"));
- inFieldPane.add(password);
- password.addActionListener(this);
- jfrm.add(inFieldPane,BorderLayout.NORTH);
- //Set second panel to submit data for processing
- JPanel submitPane = new JPanel();
- submitPane.setLayout(new FlowLayout());
- submitPane.add(new JLabel("Press button to submit results"));
- JButton submitButton = new JButton("Submit");
- submitButton.addActionListener(this);
- submitPane.add(submitButton);
- jfrm.add(submitPane,BorderLayout.CENTER);
- // Set third panel to display processed data
- JPanel outFieldPane= new JPanel();
- outFieldPane.setLayout(new GridLayout(1,2));
- outFieldPane.add(new JLabel("Output"));
- outFieldPane.add(output);
- jfrm.add(outFieldPane,BorderLayout.SOUTH);
- jfrm.setVisible(true);
- jfrm.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
- jfrm.setSize(800, 600);
- jfrm.addWindowListener(new WindowListener() {
- @Override
- public void windowClosing(WindowEvent e) {
- if(JOptionPane.showConfirmDialog(jfrm, "Are you sure ?") == JOptionPane.OK_OPTION){
- jfrm.setVisible(false);
- jfrm.dispose();
- }
- }
- @Override
- public void windowActivated(WindowEvent e) {
- }
- @Override
- public void windowClosed(WindowEvent e) {
- }
- @Override
- public void windowDeactivated(WindowEvent e) {
- }
- @Override
- public void windowDeiconified(WindowEvent e) {
- }
- @Override
- public void windowIconified(WindowEvent e) {
- }
- @Override
- public void windowOpened(WindowEvent e) {
- }
- });
- jfrm.setVisible(true);
- }
- public void actionPerformed(ActionEvent e)
- {
- if(e.getActionCommand().equals("Submit"))
- {
- try {
- pass();
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- }
- }
- public static void pass() throws IOException{
- // Initialize variable count to 0
- String st = password.getText().toString();
- int length = st.length();
- String g = gender.getText().toString();
- String gen = null;
- int count = 0;
- // Convert given string to char array
- char[] c = st.toCharArray();
- // Loop till end of string
- for(int i=0;i<st.length();i++)
- {
- // Get ascii value of each char and store it in k
- int k=(int)c[i];
- // Digits ascii values start from 48 till 57
- if((k>=48)&&(k<=57))
- {
- count++;
- }
- }
- // Print the no.of digits
- System.out.println("No. of digits are " + count);
- // You can also print no.of chars other than digits like..
- int chars = (st.length() - count);
- System.out.println("No. of chars other than digits are " + chars);
- System.out.println("" + st);
- if(g.equalsIgnoreCase("female")){
- gen = "female";
- }else if(g.equalsIgnoreCase("male")){
- gen = "male";
- }else{
- System.out.println("Invalid Gender!");
- }
- if(length > 18 && count >= 4){
- FetchData.main(gen + "5" + ".txt");
- }else if(length > 15 && count >= 3){
- FetchData.main(gen + "4" + ".txt");
- }else if(length > 12 && count >= 2){
- FetchData.main(gen + "3" + ".txt");
- }else if(length > 9 && count >= 1){
- FetchData.main(gen + "2" + ".txt");
- }else{
- FetchData.main(gen + "1" + ".txt");
- }
- BarGraphHandler.main(null);
- }
- public static void main(String[] args)
- {
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- new GUI();
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement