본문 바로가기

Study/Java

12. 09. 25

import java.awt.*;

import java.awt.event.*;

import java.text.DateFormat;

import java.text.DateFormat.*;

import java.util.Date;

import java.util.Date.*;

import javax.swing.*;




public class SecurityPanel extends JFrame

{

private JLabel securityCodeJLabel;

private JPasswordField securityCodeJPasswordField;

private JButton aJButton;

private JButton bJButton;

private JButton cJButton;

private JButton dJButton;

private JButton eJButton;

private JButton fJButton;

private JButton gJButton;

private JButton hJButton;

private JButton iJButton;

private JButton clearJButton;

private JButton zeroJButton;

private JButton enterJButton;

private JLabel accessLogJLabel;

private JTextArea accessLogJTextArea;

private JScrollPane accessLogJScrollpane;

public SecurityPanel()

{

createUserInterface();

}

private void createUserInterface()

{

JPanel panel = new JPanel();

panel.setLayout(null);

securityCodeJLabel = new JLabel();

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

securityCodeJLabel.setText("Security code:");

panel.add(securityCodeJLabel);

securityCodeJPasswordField = new JPasswordField();

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

securityCodeJPasswordField.setEditable (false);

panel.add(securityCodeJPasswordField);

aJButton = new JButton();

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

aJButton.setText("1");

panel.add(aJButton);

aJButton.addActionListener(

new ActionListener()

{

public void actionPerformed(ActionEvent event)

{

aJButtonActionPerformed(event);

}

}

);

bJButton = new JButton();

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

bJButton.setText("2");

panel.add(bJButton);

bJButton.addActionListener(

new ActionListener()

{

public void actionPerformed(ActionEvent event)

{

bJButtonActionPerformed(event);

}

}

);

cJButton = new JButton();

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

cJButton.setText("3");

panel.add(cJButton);

cJButton.addActionListener(

new ActionListener()

{

public void actionPerformed(ActionEvent event)

{

cJButtonActionPerformed(event);

}

}

);

dJButton = new JButton();

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

dJButton.setText("4");

panel.add(dJButton);

dJButton.addActionListener(

new ActionListener()

{

public void actionPerformed(ActionEvent event)

{

dJButtonActionPerformed(event);

}

}

);

eJButton = new JButton();

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

eJButton.setText("5");

panel.add(eJButton);

eJButton.addActionListener(

new ActionListener()

{

public void actionPerformed(ActionEvent event)

{

eJButtonActionPerformed(event);

}

}

);

fJButton = new JButton();

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

fJButton.setText("6");

panel.add(fJButton);

fJButton.addActionListener(

new ActionListener()

{

public void actionPerformed(ActionEvent event)

{

fJButtonActionPerformed(event);

}

}

);

gJButton = new JButton();

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

gJButton.setText("7");

panel.add(gJButton);

gJButton.addActionListener(

new ActionListener()

{

public void actionPerformed(ActionEvent event)

{

gJButtonActionPerformed(event);

}

}

);

hJButton = new JButton();

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

hJButton.setText("8");

panel.add(hJButton);

hJButton.addActionListener(

new ActionListener()

{

public void actionPerformed(ActionEvent event)

{

hJButtonActionPerformed(event);

}

}

);

iJButton = new JButton();

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

iJButton.setText("9");

panel.add(iJButton);

iJButton.addActionListener(

new ActionListener()

{

public void actionPerformed(ActionEvent event)

{

iJButtonActionPerformed(event);

}

}

);


clearJButton = new JButton();

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

clearJButton.setText("C");

panel.add(clearJButton);

clearJButton.addActionListener(

new ActionListener()

{

public void actionPerformed(ActionEvent event)

{

clearJButtonActionPerformed(event);

}

}

);


zeroJButton = new JButton();

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

zeroJButton.setText("0");

panel.add(zeroJButton);

zeroJButton.addActionListener(

new ActionListener()

{

public void actionPerformed(ActionEvent event)

{

zeroJButtonActionPerformed(event);

}

}

);


enterJButton = new JButton();

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

enterJButton.setText("#");

panel.add(enterJButton);

enterJButton.addActionListener(

new ActionListener()

{

public void actionPerformed(ActionEvent event)

{

enterJButtonActionPerformed(event);

}

}

);

accessLogJLabel = new JLabel();

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

accessLogJLabel.setText("Access log:");

panel.add(accessLogJLabel);

accessLogJTextArea = new JTextArea();

accessLogJScrollpane = new JScrollPane(accessLogJTextArea);

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

panel.add(accessLogJScrollpane);

add(panel);

setTitle("Security Panel");

setSize(310,450);

setVisible(true);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

private void aJButtonActionPerformed(ActionEvent event)

{

securityCodeJPasswordField.setText(String.valueOf(

securityCodeJPasswordField.getPassword())+"1");

}

private void bJButtonActionPerformed(ActionEvent event)

{

securityCodeJPasswordField.setText(String.valueOf(

securityCodeJPasswordField.getPassword())+"2");

}

private void cJButtonActionPerformed(ActionEvent event)

{

securityCodeJPasswordField.setText(String.valueOf(

securityCodeJPasswordField.getPassword())+"3");

}

private void dJButtonActionPerformed(ActionEvent event)

{

securityCodeJPasswordField.setText(String.valueOf(

securityCodeJPasswordField.getPassword())+"4");

}

private void eJButtonActionPerformed(ActionEvent event)

{

securityCodeJPasswordField.setText(String.valueOf(

securityCodeJPasswordField.getPassword())+"5");

}

private void fJButtonActionPerformed(ActionEvent event)

{

securityCodeJPasswordField.setText(String.valueOf(

securityCodeJPasswordField.getPassword())+"6");

}

private void gJButtonActionPerformed(ActionEvent event)

{

securityCodeJPasswordField.setText(String.valueOf(

securityCodeJPasswordField.getPassword())+"7");

}

private void hJButtonActionPerformed(ActionEvent event)

{

securityCodeJPasswordField.setText(String.valueOf(

securityCodeJPasswordField.getPassword())+"8");

}

private void iJButtonActionPerformed(ActionEvent event)

{

securityCodeJPasswordField.setText(String.valueOf(

securityCodeJPasswordField.getPassword())+"9");

}

private void clearJButtonActionPerformed(ActionEvent event)

{

securityCodeJPasswordField.setText("");

}

private void zeroJButtonActionPerformed(ActionEvent event)

{

securityCodeJPasswordField.setText(String.valueOf(

securityCodeJPasswordField.getPassword())+"0");

}

private void enterJButtonActionPerformed(ActionEvent event)

{

String message;

int accessCode = Integer.parseInt(String.valueOf(

securityCodeJPasswordField.getPassword()));

securityCodeJPasswordField.setText("");

switch (accessCode)

{

case 7:

case 8:

case 9:

message = "Restricted Access";

break;

case 1645:

message = "Techvician";

break;

case 8345:

message = "Custodian";

break;

case 9998:

case 1006:

case 1007:

case 1008:

message = "Scientist";

break;

default:

message = "Access Denied";

}

DateFormat formatter =  DateFormat.getDateTimeInstance();

accessLogJTextArea.append(formatter.format(new Date() )+

" " + message + "\n");

}

public static void main(String[] args) {

SecurityPanel application = new SecurityPanel();

}


}


'Study > Java' 카테고리의 다른 글

12. 09. 26 테스트  (0) 2012.10.01
12. 09. 26 과제  (0) 2012.09.26
12. 09. 25 과제  (0) 2012.09.25
12. 09. 19 실습( 월급 계산기 )  (0) 2012.09.23
12. 09. 19( 쪽지시험 )  (0) 2012.09.19