관리 메뉴

moozi

Swing 2 본문

자바

Swing 2

moozi 2015. 4. 30. 14:53

import java.awt.Color;

import java.awt.Container;

import java.awt.FlowLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;


import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JTextField;




public class Student extends JFrame{

//생성자

Student(){

setTitle("학생관리");//타이틀

Container c=getContentPane();//컨테이너생성

c.setBackground(Color.orange);//배경색

c.setLayout(new FlowLayout(FlowLayout.LEFT,10,10));//레이아웃설정

c.add(new JLabel("이름"));

JTextField tfName=new JTextField(20);

c.add(tfName);

c.add(new JLabel("학과"));

JTextField tfDepartment=new JTextField(20);

c.add(tfDepartment);

c.add(new JLabel("주소"));

JTextField tfAddress=new JTextField(20);

c.add(tfAddress);

JButton btnOK=new JButton("OK");

c.add(btnOK);

btnOK.addActionListener(new ActionListener(){

@Override

public void actionPerformed(ActionEvent e) {

if(tfName.getText().equals("")){

JOptionPane.showMessageDialog(null, "이름을 입력하세요!", "확인", JOptionPane.WARNING_MESSAGE);

return;//함수종료

}

System.out.println("OK버튼이 클릭됨");

}});

JButton btnCancel=new JButton("Cancel");

c.add(btnCancel);

btnCancel.addActionListener(new ActionListener(){

@Override

public void actionPerformed(ActionEvent e) {

System.out.println("Cancel버튼이 클릭됨");

}});

setSize(300,300);//사이즈

setVisible(true);//보이게하기

setResizable(false);//사이즈고정

//종료

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

/*private class MyActionListener implements ActionListener{

@Override

public void actionPerformed(ActionEvent e) {

JButton btn=(JButton)e.getSource();//클릭한버튼구하기

if(btn.getText().equals("OK")){

System.out.println("OK버튼이 클릭됨");

}else if(btn.getText().equals("Cancel")){

System.out.println("Cancel버튼이 클릭됨");

}

}

}*/


public static void main(String[] args) {

new Student();//생성자호출.인스턴스생성


}


}





'자바' 카테고리의 다른 글

jar실행시 cmd창 바로 종료하는 배치파일 만들기  (0) 2017.01.02
스윙 5.6 컴보2B  (0) 2015.05.06
swing1  (0) 2015.04.29
12/24 Swing03  (0) 2014.12.24
JSmooth 사용하기  (0) 2014.12.24
Comments