일단 제작 화면을 올린다...
일단 우섭이의 소스를 가져와서 JDialog로 변경했다. 메인프레임과 연결 시키기 위해 JDialog를 사용했다.
로그인창에서 쓰던 기존 id 와 password JPasswordField 를 회원가입창으로 그대로 가져왔다.
우선 클래스를 생성해 jdialog 를 상속받는다.. ActionListener도 추가 시켜주고...
메인 프레임에서 jdialog 를 호출시켰다.
우선 생성자로 2개를 생성했다. 하나의 생성자는 로그인 화면을 다른 하나의 생성자는 회원가입 화면을 만들었다.
class P2pLogin extends JDialog implements ActionListener
{
private JPanel loginPane = null;
private JTextField id = null;
private JTextField name = null;
private JPasswordField password = null;
private JPasswordField password1 = null;
private JTextField e_mail = null;
private JTextField phone = null;
private JTextField phone1 = null;
private JTextField phone2 = null;
private JTextField address1 = null;
private JTextField address2 = null;
private JFrame mainFrame = null;
private boolean bexit = true;
private Connection conn = null;
private Statement stmt = null;
private JButton login_ok = null;
private JButton login_cancel = null;
private JButton login_gaib = null;
private JButton join_ok = null;
private JButton join_cancel = null;
private String[] id_check = {"아이디를 적어주세요","사용가능합니다.","중복입니다. 다시해주세요"};
private KeyAdapter ka = null;
private boolean keybool = false;
private int kf = 0;
private ResultSet rs = null;
private UserData ud = null;
private JLabel idshow;
//////////////////////////////////////////////////////////////
// 로그인 창 만들기
//////////////////////////////////////////////////////////////
public P2pLogin(JFrame j,JLabel show,UserData ud)
{
super(j,"P2P Login",true);
mainFrame = j;
idshow = show;
this.setLayout(new BorderLayout());
kf = 0;
this.ud = ud;
JLabel loginLabel = new JLabel(" ID와 비밀번호를 입력해주세요",JLabel.CENTER);
this.add(loginLabel,BorderLayout.NORTH);
this.add(getloginPane(),BorderLayout.CENTER);
JPanel loginButton = new JPanel();
login_ok = new JButton("로그인");
login_cancel = new JButton("취소");
login_gaib = new JButton("회원가입");
loginButton.add(login_ok);
loginButton.add(login_cancel);
loginButton.add(login_gaib);
this.add(loginButton,BorderLayout.SOUTH);
this.pack();
int x = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth()/2 - this.getWidth()/2;
int y = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight()/2 - this.getHeight()/2;
this.setLocation(x,y);
this.start();
this.setVisible(true);
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE,bexit);
}
//////////////////////////////////////////////////////////////
// 회원 가입창 생성
//////////////////////////////////////////////////////////////
public P2pLogin(JFrame j,String s)
{
super(j,s,true);
mainFrame = j;
kf = 1;
this.setLayout(new BorderLayout());
this.add(new JLabel("정확한 정보를 입력해주세요"),BorderLayout.NORTH);
JPanel joinPane = new JPanel();
joinPane.setLayout(null);
JPanel login = getloginPane();
login.setBounds(0,0,400,60);
password1 = new JPasswordField(10);
JPanel jj = new JPanel(new GridLayout(6,2));
jj.add(new JLabel("비밀번호확인",JLabel.CENTER));
JPanel ps = new JPanel(new FlowLayout(FlowLayout.LEFT));
ps.add(password1);
jj.add(ps);
name = new JTextField(10);
jj.add(new JLabel("이름",JLabel.CENTER));
JPanel jn = new JPanel(new FlowLayout(FlowLayout.LEFT));
jn.add(name);
jj.add(jn);
jj.add(new JLabel("E-Mail",JLabel.CENTER));
JPanel ps1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
e_mail = new JTextField(15);
ps1.add(e_mail);
jj.add(ps1);
jj.add(new JLabel("핸 드 폰",JLabel.CENTER));
JPanel ps2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
JPanel ps3 = new JPanel(new FlowLayout(FlowLayout.LEFT));
ps3.setPreferredSize(new Dimension(40,30));
JPanel ps4 = new JPanel(new FlowLayout(FlowLayout.LEFT));
phone = new JTextField(3);
phone1 = new JTextField(4);
phone2 = new JTextField(4);
ps2.add(phone);
ps2.add(new JLabel("-"));
ps2.add(phone1);
ps2.add(new JLabel("-"));
ps2.add(phone2);
jj.add(ps2);
address1 = new JTextField(17);
ps3.add(address1);
address2 = new JTextField(17);
ps4.add(address2);
jj.add(new JPanel(new FlowLayout(FlowLayout.CENTER)).add(new JLabel("주 소",JLabel.CENTER)));
jj.add(ps3);
jj.add(new JPanel(new FlowLayout(FlowLayout.CENTER)).add(new JLabel("",JLabel.CENTER)));
jj.add(ps4);
jj.setBounds(0,60,400,200);
joinPane.add(login);
joinPane.add(jj);
join_ok = new JButton("가입하기");
join_cancel = new JButton("가입취소");
JPanel okButton = new JPanel(new FlowLayout(FlowLayout.CENTER));
okButton.setBounds(30,260,400,50);
okButton.add(join_ok);
okButton.add(join_cancel);
joinPane.add(okButton);
this.add(joinPane,BorderLayout.CENTER);
this.setSize(500,400);
this.setLocation((int)(Toolkit.getDefaultToolkit().getScreenSize().getWidth()/2 - this.getWidth()/2),(int)(Toolkit.getDefaultToolkit().getScreenSize().getHeight()/2 - this.getHeight()/2));
this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
this.start();
this.setVisible(true);
}
//////////////////////////////////////////////////////////////
// 로그인 패널 만들기
//////////////////////////////////////////////////////////////
private JPanel getloginPane()
{
if(loginPane == null){
id = new JTextField(10);
password = new JPasswordField(10);
loginPane = new JPanel(new GridLayout(2,2));
loginPane.add(new JLabel("아 이 디",JLabel.CENTER));
JPanel idPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
idPane.add(id,JTextField.CENTER);
loginPane.add(idPane);
loginPane.add(new JLabel("비 밀 번 호",JLabel.CENTER));
JPanel passwordPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
passwordPane.add(password);
loginPane.add(passwordPane);
}
return loginPane;
}
기초 소스 이다. 여기는 많은 변수를 사용한다 회원가입도 해야되기 때문에....
각종 정보를 저장 하는 변수와 db를 연결하기 와한 conn변수 , stmt 변수등도 있고 ...
kf 변수는 0과 1을 저장한다. 로그인창을 생성할때는 0을 나타내고 회원가입창을 나타낼때는 1을 나타낸다.
각종 이벤트를 위해 나누었다.
UserData 클래스는 db에서 로그인할시 가져오는 자료를 저장하기 위해 사용한 클래스 이다.
기초 외관은 이렇게 만들었다.