JFrame 입문 예시

5019 단어 자바
import java.awt.Button;
import java.awt.Label;
import java.awt.TextField;

import javax.swing.GroupLayout;
import javax.swing.JFrame;

class LoginFrame extends JFrame {

    Label nameLabel = new Label("name");
    Label passLabel = new Label("password");
    TextField nameInput = new TextField();
    TextField passInput = new TextField();


    public LoginFrame() {
        this.setBounds(300, 300, 300, 300);
        this.setVisible(true);
        GroupLayout groupLayout = new GroupLayout(this.getContentPane());// this.getContentPane()  
        this.getContentPane().setLayout(groupLayout);
        this.add(nameLabel);
        this.add(nameInput);
        this.add(passLabel);
        this.add(passInput);
        groupLayout.setHorizontalGroup(groupLayout
                .createParallelGroup()
                .addGroup(
                        groupLayout.createSequentialGroup()
                                .addComponent(nameLabel, 100, 100, 100)
                                .addComponent(nameInput, 200, 200, 200))
                .addGroup(
                        groupLayout.createSequentialGroup()
                                .addComponent(passLabel, 100, 100, 100)
                                .addComponent(passInput, 200, 200, 200)));
        groupLayout.setVerticalGroup(groupLayout
                .createParallelGroup()
                .addGroup(
                        groupLayout.createSequentialGroup()
                                .addComponent(nameLabel, 50, 50, 50)
                                .addComponent(passLabel, 50, 50, 50))
                .addGroup(
                        groupLayout.createSequentialGroup()
                                .addComponent(nameInput, 50, 50, 50)
                                .addComponent(passInput, 50, 50, 50)));

    }

}

좋은 웹페이지 즐겨찾기