Study/Java

12. 09. 25 과제

Houkibosi 2012. 9. 25. 15:17

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;


import javax.swing.*;


class test extends JFrame

{

private static final long serialVersionUID = 1L;

JButton ButtonOne, ButtonTwo, ButtonThree, ButtonFour, ButtonFive, ButtonSix, 

ButtonSeven, ButtonEight, ButtonNine, ButtonZero, ButtonC, ButtonSharpe;

JTextField SecurityCodePassword = new JTextField();

JTextField Security = new JTextField();

JTextArea AccessLogTextArea = new JTextArea();

JScrollPane AccessLogScrollPane = new JScrollPane( AccessLogTextArea );

String total = null;

public test()

{

setSize(310, 450);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setTitle("Security Panel");

this.setLayout(null);

JLabel SecurityCodeLabel = new JLabel("Security Code");

SecurityCodeLabel.setBounds(16, 16, 90, 21);

this.add(SecurityCodeLabel);

JLabel AccessLogLabel = new JLabel("Access Log : ");

AccessLogLabel.setBounds(16, 285, 100, 16);

this.add(AccessLogLabel);

AccessLogScrollPane.setBounds(16, 309, 270, 95);

SecurityCodePassword.setBounds(114, 16, 172, 26);

SecurityCodePassword.setEditable(false);

ButtonZero.setText("0");

ButtonZero.setBounds(130, 214, 50, 50);

ButtonZero.addActionListener(new MyListener());

this.add(ButtonZero);

ButtonOne.setText("1");

ButtonOne.setBounds(80, 64, 50, 50);

ButtonOne.addActionListener(new MyListener());

this.add(ButtonZero);

ButtonTwo.setText("2");

ButtonTwo.setBounds(130, 64, 50, 50);

ButtonTwo.addActionListener(new MyListener());

this.add(ButtonTwo);

ButtonThree.setText("3");

ButtonThree.setBounds(180, 64, 50, 50);

ButtonThree.addActionListener(new MyListener());

this.add(ButtonThree);

ButtonFour.setText("4");

ButtonFour.setBounds(80, 114, 50, 50);

ButtonFour.addActionListener(new MyListener());

this.add(ButtonFour);

ButtonFive.setText("5");

ButtonFive.setBounds(130, 114, 50, 50);

ButtonFive.addActionListener(new MyListener());

this.add(ButtonFive);

ButtonSix.setText("6");

ButtonSix.setBounds(180, 114, 50, 50);

ButtonSix.addActionListener(new MyListener());

this.add(ButtonSix);

ButtonSeven.setText("7");

ButtonSeven.setBounds(80, 164, 50, 50);

ButtonSeven.addActionListener(new MyListener());

this.add(ButtonSeven);

ButtonEight.setText("8");

ButtonEight.setBounds(130, 164, 50, 50);

ButtonEight.addActionListener(new MyListener());

this.add(ButtonEight);

ButtonNine.setText("9");

ButtonNine.setBounds(180, 164, 50, 50);

ButtonNine.addActionListener(new MyListener());

this.add(ButtonNine);

ButtonC.setText("c");

ButtonC.setBounds(80, 214, 50, 50);

ButtonC.addActionListener(new MyListener());

this.add(ButtonC);

ButtonSharpe.setText("#");

ButtonSharpe.setBounds(180, 214, 50, 50);

ButtonSharpe.addActionListener(new MyListener());

this.add(ButtonSharpe);

/*

for(int i=1, valueX=80, valueY=64; i<13; i++, valueX+=50)

{

if(i%3 == 0)

{ valueX = 80; valueY+=50; }

if(i==10)

button[i].setText("C");

if(i==11)

button[i].setText("0");

if(i==12)

button[i].setText("#");

button[i].setText(Integer.toString(i));

button[i].setBounds(valueX, valueY, 50, 50);

button[i].addActionListener(new MyListener());

this.add(button[i]);

}

*/

this.add(SecurityCodePassword);

this.add(AccessLogScrollPane);

setVisible(true);

}

private class MyListener implements ActionListener

{

public void actionPerfomed(ActionEvent e)

{

if(e.getSource() == ButtonZero)

total += "0";

if(e.getSource() == ButtonOne)

total += "1";

if(e.getSource() == ButtonTwo)

total += "2";

if(e.getSource() == ButtonThree)

total += "3";

if(e.getSource() == ButtonFour)

total += "4";

if(e.getSource() == ButtonFive)

total += "5";

if(e.getSource() == ButtonSix)

total += "6";

if(e.getSource() == ButtonSeven)

total += "7";

if(e.getSource() == ButtonEight)

total += "8";

if(e.getSource() == ButtonNine)

total += "9";

if(e.getSource() == ButtonC)

total = null;

if(e.getSource() == ButtonSharpe)

{

if(Integer.parseInt(total) == 7 || Integer.parseInt(total) == 8 || Integer.parseInt(total) == 9)

AccessLogTextArea.setText("Restricted Access");

if(Integer.parseInt(total) == 1645)

AccessLogTextArea.setText("Technician");

if(Integer.parseInt(total) == 8345)

AccessLogTextArea.setText("Custodian");

if(Integer.parseInt(total) == 9998 || Integer.parseInt(total) == 1006 || Integer.parseInt(total) == 1007 || Integer.parseInt(total) == 1008)

AccessLogTextArea.setText("Scientist");

else

AccessLogTextArea.setText("Access Denied");

}

}

}

}


public class asd 

{

public static void main(String[] args) 

{

test ts = new test();

}


}