import javax.swing.*;
import javax.swing.text.*;
import java.awt.*;
import javax.swing.border.*;
import java.awt.event.*;
import javax.swing.event.*;
public class Jumin extends JPanel implements ActionListener,KeyListener
{
JPanel top,middle,bottom;
JPanel top_top,top_down;
JLabel jumin_title,jumin_result_title;
JTextField jumin_result;
JTextField jumin_left,jumin_right;
JButton reset;
static int changeLength;
public Jumin(){
setLayout(new GridLayout(2,1));
top=new JPanel();
setBackground(new Color(204,204,204));
top.setBorder(new TitledBorder(new EtchedBorder(),"(주)BIT DataSystems Corp.",TitledBorder.LEFT,TitledBorder.TOP,MyFont.sans()));
setLayout(new FlowLayout());
top_top=new JPanel();
jumin_title=new JLabel("쭌 민증번호를 입력해줘..");
jumin_title.setFont(new Font("Serif",Font.LAYOUT_LEFT_TO_RIGHT,12));
top_top.add(jumin_title);
top.add(top_top);
top_down=new JPanel();
setLayout(new FlowLayout());
jumin_left=new JTextField();
jumin_left.setColumns(6);
jumin_left.setBackground(new Color(221,221,221));
jumin_left.setForeground(new Color(57,86,147));
jumin_left.addActionListener(this); //...
jumin_left.getDocument().addDocumentListener(new MyDocumentListener()); //...
top_down.add(jumin_left);
jumin_right=new JTextField(7);
jumin_right.setBackground(new Color(221,221,221));
jumin_right.setForeground(new Color(57,86,147));
jumin_right.addActionListener(this);
top_down.add(jumin_right);
top.add(top_down);
add(top);
middle=new JPanel();
middle.setBorder(new TitledBorder(new EtchedBorder(),"조회 결과",TitledBorder.LEFT,TitledBorder.TOP,MyFont.sans()));
setLayout(new FlowLayout());
jumin_result_title=new JLabel("간첩일까 아닐까..");
jumin_result_title.setFont(new Font("Serif",Font.LAYOUT_LEFT_TO_RIGHT,12));
jumin_result=new JTextField(11);
jumin_result.setEditable(false); //입력못하게
jumin_result.setBackground(new Color(221,221,221));
jumin_result.setForeground(new Color(57,86,147));
reset=new JButton("새로고침");
reset.setFont(new Font("Serif",Font.LAYOUT_LEFT_TO_RIGHT,12));
reset.addActionListener(this);
reset.addKeyListener(this);
middle.add(jumin_result_title);
middle.add(jumin_result);
middle.add(reset);
add(middle);
jumin_left.requestFocus();
}
public void keyPressed(KeyEvent e){ //======================
if(e.getSource() == reset){
jumin_left.setText("");
jumin_right.setText("");
jumin_result.setText("");
jumin_left.requestFocus();
}
}
public void keyTyped(KeyEvent e){}
public void keyReleased(KeyEvent e){}
class MyDocumentListener implements DocumentListener {
public void insertUpdate(DocumentEvent e) {
updateLog(e, "inserted into");
}
public void removeUpdate(DocumentEvent e) {
updateLog(e, "removed from");
}
public void changedUpdate(DocumentEvent e) { }
public void updateLog(DocumentEvent e, String action) {
Document doc = (Document)e.getDocument();
changeLength = doc.getLength();
abc(changeLength);
}
public void abc(int i){
i++;
if(i == 7) jumin_right.requestFocus();
}
}
public void actionPerformed(ActionEvent ae){
if(ae.getSource()==reset){
jumin_left.setText("");
jumin_right.setText("");
jumin_result.setText("");
jumin_left.requestFocus();
}
else if(ae.getSource() == jumin_left){
jumin_result.setText("");
jumin_right.requestFocus();
}
else if(ae.getSource() == jumin_right){
String str1 = jumin_left.getText().trim();
String str2 = jumin_right.getText().trim();
if(CheckID.check(str1,str2)){
jumin_result.setText("");
jumin_result.setText("간첩아이네.."+"\n");
jumin_result.requestFocus();
}
else {
jumin_result.setText("");
jumin_result.setText("우쒸.. 너 간첩이지.."+"\n");
jumin_result.requestFocus();
}
}
}
public static void main(String[] args) {
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("주민검사");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(new Jumin());
frame.setSize(390,190);
frame.setLocation(300,150);
frame.setVisible(true);
}
}
--------------------------------------------------------------
class CheckID {
public static boolean check(String str1, String str2){
String str_sum=str1+str2;
if(str_sum.length()>13){
return false;
}
String index="2345678923456";
char[] arry = str_sum.toCharArray();
int last= Integer.parseInt(String.valueOf(arry[12]));
int sum=0;
int [] juminNo = new int[13];
int [] juminNoo=new int[13];
int magicky,magicky1;
for(int i=0;i<12;i++){
juminNo[i]=str_sum.charAt(i)-`0`;
juminNoo[i]=index.charAt(i)-`0`;
sum+=juminNo[i]*juminNoo[i];
}
magicky=sum%11;
magicky1=11-magicky;
if(last==magicky1){
return true;
}
else{
return false;
}
}
}
--------------------------------------------------------------
import java.awt.*;
public class MyFont{
public static Font sans(){
Font sans = new Font("Sans Serif", Font.LAYOUT_LEFT_TO_RIGHT, 12);
return sans;
}
}
'프로그래밍 > 자바(JAVA)' 카테고리의 다른 글
[자바/JAVA] 자바 빈삼각형 만들기 (0) | 2012.05.04 |
---|---|
[자바/JAVA] 자바 업그레이드 구구단 (0) | 2012.05.04 |
[자바/JAVA] 자바 탐색기 만들기 (1) | 2012.05.04 |
[자바/JAVA] 자바 로또, Swing로 구현 (1) | 2012.05.04 |
[자바/JAVA] 자바 메모장 만들기 (2) | 2012.05.04 |
[자바/JAVA] 자바 계산기 만들기 (뷰어만) (0) | 2012.05.04 |
[자바/JAVA] 자바 골뱅이, 역골뱅이 만들기. (0) | 2012.05.04 |
[자바/JAVA] 자바 줄바꿈, 개행문자를 다른문자로 치환하는 방법 (1) | 2012.05.04 |
[자바/JAVA] 자바 화폐단위로 점찍어주기 (0) | 2012.05.03 |