• 전화하지 마셈
  • hyungseob@ssim.pe.kr
Codeigniter 3.x에서 4.x로 갈아 엎느라 기존 게시판 주소로 접근시 새 주소로 리다이렉션 된다.

Developerment [JAVA]

열혈강의 자바 18장 AWT 콤퍼넌트의 필수과제1 - 로그인 폼 만들기

  • 빛그림
  • 1,936

5~6년 전쯤 자바를 다시 배우기 위해서 구입했던 "열혈강의 자바" 도서를 구입만 하고 읽지 않다가 최근에 필요한 내용이 있어서 부분적으로 읽게 되면서 해본 과제입니다. 

다양한 언어의 개발도서를 접하면서 매번 느끼는건 그냥 읽고 머릿속으로 기억만 하지 말고 꼭 예제를 따라서 작성해봐야만 제대로된 학습이 되는 것 같습니다.


소스는 아래와 같습니다.
실제 사용하기 위해서는 리사이징이 안되도록 폼을 고정하고, 최소화, 최대화 버튼을 삭제해야 하지만 지금은 AWT로 폼을 구성하는 것만을 요구하는 것이므로 넘어가도록 하겠습니다.

import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.Toolkit;


public class LoginFrm {

	public static void main(String[] args) {
		LoginFrm_Sub f = new LoginFrm_Sub();
	}

}


class LoginFrm_Sub extends Frame {
	private Dimension dimen_scr, dimen_frm;
	private int xpos, ypos;
	private Label lblId = new Label("아이디 :", Label.LEFT);
	private Label lblPw = new Label("비밀번호 :", Label.LEFT);
	private TextField txtFieldId = new TextField();
	private TextField txtFieldPw = new TextField();
	private Button btnLogin = new Button("로그인");
	private Button btnJoin = new Button("회원가입");
	private Button btnPw = new Button();


	public LoginFrm_Sub() {
		super("로그인");
		init();

		this.setSize(220, 140);

		dimen_scr = Toolkit.getDefaultToolkit().getScreenSize();
		dimen_frm = this.getSize();

		xpos = (dimen_scr.width / 2) - (dimen_frm.width / 2);
		ypos = (dimen_scr.height / 2) - (dimen_frm.height / 2);

		this.setLocation(xpos, ypos);
		this.setVisible(true);

	}

	private void init() {
		BorderLayout borderLayout = new BorderLayout(0, 0);
		this.setLayout(borderLayout);

		GridBagLayout gridBagLayout = new GridBagLayout();
		GridBagConstraints gc = new GridBagConstraints();
		this.setLayout(gridBagLayout);

		gc.gridx = 0;
		gc.gridy = 0;
		gc.weightx = 0;
		gc.fill = GridBagConstraints.HORIZONTAL;
		gridBagLayout.setConstraints(lblId, gc);
		this.add(lblId);

		gc.gridx = 1;
		gc.gridy = 0;
		gc.weightx = 5;
		gc.insets = new Insets(0, 0, 5, 5);
		gc.fill = GridBagConstraints.HORIZONTAL;
		gridBagLayout.setConstraints(txtFieldId, gc);
		this.add(txtFieldId);

		gc.gridx = 0;
		gc.gridy = 1;
		gc.weightx = 0;
		gc.fill = GridBagConstraints.HORIZONTAL;
		gridBagLayout.setConstraints(lblPw, gc);
		this.add(lblPw);

		gc.gridx = 1;
		gc.gridy = 1;
		gc.weightx = 5;
		gc.insets = new Insets(0, 0, 5, 5);
		gc.fill = GridBagConstraints.HORIZONTAL;
		gridBagLayout.setConstraints(txtFieldPw, gc);
		this.add(txtFieldPw);


		gc.gridx = 1;
		gc.gridy = 2;
		GridLayout gridLayout = new GridLayout(1, 2, 5, 0);
		Panel panel = new Panel(gridLayout);
		panel.add(btnLogin);
		panel.add(btnJoin);
		gridBagLayout.setConstraints(panel, gc);
		this.add(panel);

	}
}

 


새댓글 등록