Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.util.*;
- import java.io.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class test extends JFrame
- {
- private JPanel nameHolder,colorHolder, option, numHolder,placeHolder,occupationHolder,autoHolder;
- private JLabel names,cars,nums,occupations,places, choice;
- private JTextField name1,name2,name3,name4;
- private JTextField color1,color2,color3,color4;
- private JTextField place1,place2,place3,place4;
- private JTextField oc1,oc2,oc3,oc4;
- private JTextField auto1,auto2,auto3,auto4;
- private JTextField num1,num2,num3,num4;
- private String m ="M";
- private String a ="A";
- private String s ="S";
- private String h ="H";
- private String input1,input2,input3,input4,input5,input6,input7,input8;
- private String input9,input10,input11,input12,input13,input14,input15,input16;
- private String input17,input18,input19,input20,input21,input22,input23, input24;
- private String []array, apple;
- private boolean [] bitarray;
- private int selectednum;
- char ch;
- private final int val = 7;
- private final int val2 = 4;
- private JButton Ok, Cancel, Send;
- private JRadioButton b1,b2,b3,b4;
- private ButtonGroup radioGroup;
- // private int B1,B2,B3;
- public test()
- {
- setTitle("M*A*S*H - Can you handle your future?");
- setBackground(Color.orange);
- setLayout(new GridLayout(2,3));
- setPreferredSize(new Dimension(900,400));
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- buildPanel();
- pack();
- setVisible(true);
- }
- private void buildPanel()
- {
- //Panel to respective sides
- nameHolder = new JPanel();
- autoHolder = new JPanel();
- colorHolder = new JPanel();
- placeHolder = new JPanel();
- numHolder = new JPanel();
- occupationHolder = new JPanel();
- //Panel holds Ok and Cancel button
- option = new JPanel();
- Ok = new JButton("Ok");
- // Action when pressed Ok button
- Ok.addActionListener(new OKButtonListener());
- option.add(Ok);
- Cancel = new JButton("Cancel");
- // Action when pressed Cancel button
- Cancel.addActionListener(new CancelButtonListener());
- option.add(Cancel);
- choice= new JLabel("Pick a number\t");
- radioGroup = new ButtonGroup();
- b1= new JRadioButton("1");
- b2= new JRadioButton("2");
- b3= new JRadioButton("3");
- b4= new JRadioButton("4");
- radioGroup.add(b1);
- radioGroup.add(b2);
- radioGroup.add(b3);
- radioGroup.add(b4);
- b1.addItemListener(new RadioButtonHandler(1));
- b2.addItemListener(new RadioButtonHandler(2));
- b3.addItemListener(new RadioButtonHandler(3));
- b4.addItemListener(new RadioButtonHandler(4));
- option.add(choice);
- option.add(b1);
- option.add(b2);
- option.setBackground(Color.orange);
- option.add(b3);
- option.add(b4);
- nameHolder();
- add(nameHolder);
- colorHolder();
- add(colorHolder);
- autoHolder();
- add(autoHolder);
- placeHolder();
- add(placeHolder);
- occupationHolder();
- add(occupationHolder);
- numHolder();
- add(numHolder);
- add(option);
- }
- public void nameHolder()
- {
- nameHolder.setBackground(Color.orange);
- names = new JLabel("Names");
- name1 = new JTextField(15);
- name2 = new JTextField(15);
- name3 = new JTextField(15);
- name4 = new JTextField(15);
- nameHolder.add(names);
- nameHolder.add(name1);
- nameHolder.add(name2);
- nameHolder.add(name3);
- nameHolder.add(name4);
- }
- public void colorHolder()
- {
- colorHolder.setBackground(Color.orange);
- JLabel colors = new JLabel("Colors");
- color1 = new JTextField(15);
- color2 = new JTextField(15);
- color3 = new JTextField(15);
- color4 = new JTextField(15);
- colorHolder.add(colors);
- colorHolder.add(color1);
- colorHolder.add(color2);
- colorHolder.add(color3);
- colorHolder.add(color4);
- }
- public void autoHolder()
- {
- autoHolder.setBackground(Color.orange);
- cars = new JLabel(" Cars ");
- auto1 = new JTextField(15);
- auto2 = new JTextField(15);
- auto3 = new JTextField(15);
- auto4 = new JTextField(15);
- autoHolder.add(cars);
- autoHolder.add(auto1);
- autoHolder.add(auto2);
- autoHolder.add(auto3);
- autoHolder.add(auto4);
- }
- public void occupationHolder()
- {
- occupationHolder.setBackground(Color.orange);
- occupations = new JLabel("Careers");
- oc1 = new JTextField(15);
- oc2 = new JTextField(15);
- oc3 = new JTextField(15);
- oc4 = new JTextField(15);
- occupationHolder.add(occupations);
- occupationHolder.add(oc1);
- occupationHolder.add(oc2);
- occupationHolder.add(oc3);
- occupationHolder.add(oc4);
- }
- public void numHolder()
- {
- numHolder.setBackground(Color.orange);
- nums = new JLabel("Numbers");
- num1 = new JTextField(15);
- num2 = new JTextField(15);
- num3 = new JTextField(15);
- num4 = new JTextField(15);
- numHolder.add(nums);
- numHolder.add(num1);
- numHolder.add(num2);
- numHolder.add(num3);
- numHolder.add(num4);
- }
- public void placeHolder()
- {
- placeHolder.setBackground(Color.orange);
- places = new JLabel("Places");
- place1= new JTextField(15);
- place2= new JTextField(15);
- place3= new JTextField(15);
- place4= new JTextField(15);
- placeHolder.add(places);
- placeHolder.add(place1);
- placeHolder.add(place2);
- placeHolder.add(place3);
- placeHolder.add(place4);
- }
- /* public void check(char ch)
- {
- if(!Character.isLetter(ch))
- {
- JOptionPane.showMessageDialog(null,"ERROR: Invalid inputs found! \n {Tip: Check inputs in Names,Cars,Careers,Places.}");
- }
- else if(!Character.isDigit(ch))
- {
- JOptionPane.showMessageDialog(null,"ERROR:Invalid inputs found! \n Check Numbers section.}");
- }
- }
- */
- public void addValue()
- {
- input5 = name1.getText();
- input6 = name2.getText();
- input7 = name3.getText();
- input8 = name4.getText();
- input1 = auto1.getText();
- input2 = auto2.getText();
- input3 = auto3.getText();
- input4 = auto4.getText();
- input9 = color1.getText();
- input10 = color2.getText();
- input11 = color3.getText();
- input12 = color4.getText();
- input13 = oc1.getText();
- input14 = oc2.getText();
- input15 = oc3.getText();
- input16 = oc4.getText();
- input17 = num1.getText();
- input18 = num2.getText();
- input19 = num3.getText();
- input20 = num4.getText();
- input21 = place1.getText();
- input22 = place2.getText();
- input23 = place3.getText();
- input24 = place4.getText();
- /* ArrayList list = new ArrayList();
- list.add(input20);
- list.add(input21);
- list.add(input22);
- list.add(input23);
- list.add(input24);
- */
- String []info = {m,a,s,h,input1,input2,input3,input4,input5,input6,input7,input8,
- input9,input10,input11,input12,input13,input14,input15,input16,
- input17,input18,input19,input20,input21,input22,input23, input24};
- bitarray = new boolean[24];
- for(int i=0;i<24;i++)
- {
- bitarray[i] = false;
- }
- int index = -1;
- for(int i=0;i<18;i++)
- {
- for(int j=selectednum;j>0;j--)
- {
- do
- {
- index++;
- if(index==24)
- index=0;
- }while(bitarray[index]==false);
- }
- bitarray[index]=true;
- for(int j=0;j<6;j++)
- {
- int totaleliminated = 0;
- if(bitarray[j*4]==true)
- totaleliminated++;
- if(bitarray[j*4+1]==true)
- totaleliminated++;
- if(bitarray[j*4+2]==true)
- totaleliminated++;
- if(bitarray[j*4+3]==true)
- totaleliminated++;
- if(totaleliminated==3)
- {
- if(bitarray[j*4]==false)
- {
- // extract answer for group
- bitarray[j*4]=true;
- }
- if(bitarray[j*4+1]==false)
- {
- // extract answer for group
- bitarray[j*4+1]=true;
- }
- if(bitarray[j*4+2]==false)
- {
- // extract answer for group
- bitarray[j*4+2]=true;
- }
- if(bitarray[j*4+3]==false)
- {
- // extract answer for group
- // example: answerarray[j]=info[j*4+3];
- bitarray[j*4+3]=true;
- }
- }
- }
- }
- }
- public class RadioButtonHandler implements ItemListener
- {
- private int skipnum;
- public RadioButtonHandler(int n)
- {
- skipnum = n;
- }
- public void itemStateChanged( ItemEvent event)
- {
- selectednum = skipnum;
- }
- }
- public class CancelButtonListener implements ActionListener
- {
- public void actionPerformed(ActionEvent e)
- {
- JOptionPane.showMessageDialog(null,"Bye");
- System.exit(0);
- }
- }
- public class OKButtonListener implements ActionListener
- {
- public void actionPerformed(ActionEvent e)
- {
- //add inputs into array
- addValue();
- }
- }
- public static void main(String[]args)
- {
- // Scanner input = new Scanner(System.in);
- //System.out.print("enter number");
- //int nw = input.nextInt();
- new test();
- }
- }
Add Comment
Please, Sign In to add comment