Java 10일차 자기소개 GUI DB 연동2

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Vector;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

public class MemberTest extends JFrame implements ActionListener, ListSelectionListener
{
JPanel leftPanel, rightPanel;
JPanel left1, left2, left3, left4, left5, left6, left7;
JLabel left1lb, left2lb,left3lb, left4lb, left5lb, left6lb, left7lb, rightlb;
JTextField left1tf, left2tf, left3tf, left4tf;

JRadioButton left1rb, left2rb;
ButtonGroup group;

JComboBox<String> leftcb;
String[] data = {"등산", "여행"};

JButton b1, b2, b3, b4;

JList<String> list;
Vector<String> listdata = new Vector<>();

String url = "jdbc:oracle:thin:@localhost:1521:XE";
String id = "system";
String password = "nam";
Connection con;
PreparedStatement ps;
ResultSet rs;

public MemberTest()
{
leftPanel = new JPanel();
rightPanel = new JPanel();
left1 =  new JPanel();
left2 =  new JPanel();
left3 =  new JPanel();
left4 =  new JPanel();
left5 =  new JPanel();
left6 =  new JPanel();
left7 =  new JPanel();

left1lb = new JLabel(" 회원가입 ");
left2lb = new JLabel(" 아 이 디   : ");
left3lb = new JLabel(" 비밀번호: ");
left4lb = new JLabel(" 전화번호: ");
left5lb = new JLabel(" 주소        : ");
left6lb = new JLabel(" 취미      : ");
left7lb = new JLabel(" 성별      : ");
rightlb = new JLabel(" 모든 회원 보기 ");

left1tf = new JTextField(8);
left2tf = new JTextField(8);
left3tf = new JTextField(8);
left4tf = new JTextField(8);

leftcb = new JComboBox<String>(data);

left1rb = new JRadioButton("남");
left2rb = new JRadioButton("여");
group = new ButtonGroup();
group.add(left1rb);
group.add(left2rb);

b1 = new JButton("입력");
b2 = new JButton("수정");
b3 = new JButton("삭제");
b4 = new JButton("검색");

list = new JList<String>(listdata);

left1.add(left2lb);
left1.add(left1tf);
left2.add(left3lb);
left2.add(left2tf);
left3.add(left4lb);
left3.add(left3tf);
left4.add(left5lb);
left4.add(left4tf);
left5.add(left6lb);
left5.add(leftcb);
left6.add(left7lb);
left6.add(left1rb);
left6.add(left2rb);
left7.add(b1);
left7.add(b2);
left7.add(b3);
left7.add(b4);

b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);

list.addListSelectionListener(this);

leftPanel.setLayout(new GridLayout(8,1));
leftPanel.add(left1lb);
leftPanel.add(left1);
leftPanel.add(left2);
leftPanel.add(left3);
leftPanel.add(left4);
leftPanel.add(left5);
leftPanel.add(left6);
leftPanel.add(left7);

rightPanel.setLayout(new BorderLayout());
rightPanel.add("North", rightlb);
rightPanel.add(list);

setLayout(new GridLayout(1,2));

this.add(leftPanel);
this.add(rightPanel);

connection();
getAllMember();

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(600, 300);
setVisible(true);
}

public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();

if(source == b1)
this.insertMember();
else if(source == b2)
this.updataMember();
else if(source == b3)
this.deleteMember();
}

public void valueChanged(ListSelectionEvent le)
{
String data = list.getSelectedValue();

String split[] = data.split(" ");
left1tf.setText(split[0]);
left2tf.setText(split[1]);
left3tf.setText(split[2]);
left4tf.setText(split[3]);
leftcb.setSelectedItem(split[4]);
if(split[5].equals("m"))
left1rb.setSelected(true);
else if(split[5].equals("f"))
left2rb.setSelected(true);
}

public void connection()
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(url, id, password);
}
catch(Exception e)
{
}
}

public void insertMember()
{
String sql = "INSERT into member values(?,?,?,?,?,?)";

try
{
ps = con.prepareStatement(sql);

ps.setString(1, left1tf.getText().trim());
ps.setInt(2, Integer.parseInt(left2tf.getText().trim()));
ps.setString(3, left3tf.getText().trim());
ps.setString(4, left4tf.getText().trim());
ps.setString(5, leftcb.getSelectedItem().toString());

if(left1rb.isSelected())
ps.setString(6, "m");
else if(left2rb.isSelected())
ps.setString(6, "f");

ps.executeUpdate();

ps.close();
}
catch(Exception e)
{
}

this.getAllMember();
}

public void updataMember()
{
String sql = "UPDATE member set phone=?, address=? where id=?";

try
{
ps = con.prepareStatement(sql);

ps.setString(1, left3tf.getText().trim());
ps.setString(2, left4tf.getText().trim());
ps.setString(3, left1tf.getText().trim());

ps.executeUpdate();

ps.close();
}
catch(Exception e)
{
}

this.getAllMember();
}

public void deleteMember()
{
String sql = "DELETE from member where id=?";

try
{
ps = con.prepareStatement(sql);
ps.setString(1, left1tf.getText());

ps.executeUpdate();

ps.close();
}
catch(Exception e)
{
}

this.getAllMember();
}

public void getAllMember()
{
String sql = "SELECT * from member";
listdata.removeAllElements();

try
{
ps = con.prepareStatement(sql);

rs = ps.executeQuery();

while(rs.next())
{
String AllMember = "";

AllMember += rs.getString(1)+" ";
AllMember += rs.getInt(2)+" ";
AllMember += rs.getString(3)+" ";
AllMember += rs.getString(4)+" ";
AllMember += rs.getString(5)+" ";
AllMember += rs.getString(6)+"\n";

listdata.add(AllMember);
}

rs.close();
ps.close();

list.setListData(listdata);
}
catch(Exception e)
{
}
}

public static void main(String[] args)
{
new MemberTest();
}
}

Java 9일차 자기소개 GUI DB 연동

import java.awt.Event;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

public class TotalTest extends JFrame implements ActionListener
{
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
JPanel panel3 = new JPanel();
JPanel panel4 = new JPanel();
JPanel panel5 = new JPanel();
JPanel panel6 = new JPanel();

JLabel id, password, name, gender, hobby, hp, intro, etc1, etc2, bar1, bar2;
JTextField tf_id, tf_pw, tf_name, tf_hp1, tf_hp2, tf_intro;
JRadioButton male, female;
ButtonGroup bg;
JCheckBox trip, reading;
JComboBox<String> hp_cb;
String hp_num[] = {"010","011","016","019"};
JButton send, cancel;

String url = "jdbc:oracle:thin:@localhost:1521:XE";
String c_id = "system";
String c_password = "nam";
Connection con;
PreparedStatement ps;
ResultSet rs;

public TotalTest()
{
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(400, 300);
this.setVisible(true);

GridLayout grid = new GridLayout(6, 1);
setLayout(grid);

id = new JLabel("아이디");
tf_id = new JTextField(8);
etc1 = new JLabel("*8자 이내");
panel1.add(id);
panel1.add(tf_id);
panel1.add(etc1);

password = new JLabel("비밀번호");
tf_pw = new JTextField(8);
name = new JLabel("성명");
tf_name = new JTextField(8);
panel2.add(password);
panel2.add(tf_pw);
panel2.add(name);
panel2.add(tf_name);

gender = new JLabel("성별");
male = new JRadioButton("남");
female = new JRadioButton("여");
bg = new ButtonGroup();
bg.add(male);
bg.add(female);
hobby = new JLabel("취미");
trip = new JCheckBox("여행");
reading = new JCheckBox("독서");
panel3.add(gender);
panel3.add(male);
panel3.add(female);
panel3.add(hobby);
panel3.add(trip);
panel3.add(reading);

hp = new JLabel("H.P");
hp_cb = new JComboBox<>(hp_num);
tf_hp1 = new JTextField(3);
tf_hp2 = new JTextField(3);
bar1 = new JLabel("-");
bar2 = new JLabel("-");
etc2 = new JLabel("*필수입력");
panel4.add(hp);
panel4.add(hp_cb);
panel4.add(bar1);
panel4.add(tf_hp1);
panel4.add(bar2);
panel4.add(tf_hp2);
panel4.add(etc2);

intro = new JLabel("자기소개");
tf_intro = new JTextField(20);
panel5.add(intro);
panel5.add(tf_intro);

send = new JButton("전송");
cancel = new JButton("취소");
send.addActionListener(this);
cancel.addActionListener(this);
panel6.add(send);
panel6.add(cancel);


this.add(panel1);
this.add(panel2);
this.add(panel3);
this.add(panel4);
this.add(panel5);
this.add(panel6);
}

public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();

if(source==send)
{
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(url, c_id, c_password);

System.out.println("접속 완료");

String sql = "INSERT into member values(?,?,?,?,?,?,?)";

ps = con.prepareStatement(sql);

ps.setString(1, tf_id.getText());
ps.setString(2, tf_pw.getText());
ps.setString(3, tf_name.getText());
if(male.isSelected())
ps.setInt(4, 1);
else if(female.isSelected())
ps.setInt(4, 2);

if(trip.isSelected() && reading.isSelected())
ps.setString(5, "trip, reading");
else if(trip.isSelected() && !reading.isSelected())
ps.setString(5, "trip");
else if(!trip.isSelected() && reading.isSelected())
ps.setString(5, "reading");

ps.setString(6, hp_cb.getItemAt(hp_cb.getSelectedIndex())
+tf_hp1.getText()+tf_hp2.getText());
ps.setString(7, tf_intro.getText());

ps.executeUpdate();

ps.close();
con.close();
}
catch(Exception e2)
{
e2.printStackTrace();
}
}
if(source==cancel)
{
tf_id.setText("");
tf_pw.setText("");
tf_name.setText("");
tf_hp1.setText("");
tf_hp2.setText("");
tf_intro.setText("");
male.setSelected(true);
trip.setSelected(false);
reading.setSelected(false);
}
}

public static void main(String[] args)
{
new TotalTest();
}
}

result)


Java #3-2 배열

배열 접근

/* 5개의 수 입력받아 배열에 저장한 뒤 가장 큰 수를 화면에 출력하는 프로그램 */
import java.util.Scanner;

public class ArrayAccess
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int number[] = new int[5];
int max = Integer.MIN_VALUE;

for(int i=0; i<number.length; i++)
{
System.out.print(i+1+"번째 수 입력 : ");
number[i] = sc.nextInt();

if(max<number[i])
max = number[i];
}
System.out.println("입력하신 수 중 가장 큰 수는 "+max+"입니다.");
}
}










배열을 이용한 반복문 (for-each문)

/* int, String, enum 타입을 이용한 반복문 활용 프로그램 */
public class ForEachSample
{
enum Week {월, 화, 수, 목, 금, 토, 일}

public static void main(String[] args)
{
int num[] = {1, 2, 3, 4, 5};
String alpha[] = {"a", "b", "c", "d", "e", "f"};
int sum = 0;

for(int i : num)
sum += i;
System.out.println(sum);

for(String s : alpha)
System.out.print(s+" ");
System.out.println();

for(Week day : Week.values())
System.out.print(day+" ");
System.out.println();
}
}


Java 9일차 JDBC 테스트2

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class JDBCTest
{
public static void main(String[] args)
{
String url = "jdbc:oracle:thin:@localhost:1521:XE";
String id = "system";
String password = "nam";
Connection con;
PreparedStatement ps;
ResultSet rs;

try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(url, id, password);

System.out.println("접속 완료");

String sql = "SELECT * from member";
// String sql = "INSELET into member values(?,?,?,?,?,?,?)";

ps = con.prepareStatement(sql);
/*
ps.setString(1, "jykim");
ps.setString(2, "2222");
ps.setInt(3, 2);
ps.setString(4, "K. Jiyeon");
ps.setString(5, "study");
ps.setString(6, "01090374417");
ps.setString(7, "jykim");
*/
rs = ps.executeQuery();

while(rs.next())
{
System.out.print(rs.getString(1)+" ");
System.out.print(rs.getString(2)+" ");
System.out.print(rs.getString(3)+" ");
System.out.print(rs.getInt(4)+" ");
System.out.print(rs.getString(5)+" ");
System.out.print(rs.getString(6)+" ");
System.out.println(rs.getString(7)+" ");
}

rs.close();
ps.close();
con.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

result)





Java 9일차 JDBC 테스트

import java.sql.Connection;
import java.sql.DriverManager;

public class JDBCTest
{
public static void main(String[] args)
{
String url = "jdbc:oracle:thin:@127.0.01:1521:XE";
String id = "system";
String password = "nam";
Connection con;

try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(url, id, password);
System.out.println("접속 완료");
}
catch(Exception e)
{

}
}
}

Java 9일차 eclipse에서 오라클 DB 연동 (ojdbc14.jar)

Java 9일차 Oracle Database 설치

Java 9일차 계산기 GUI (수정중)

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class CalculatorTest2 extends JFrame implements ActionListener
{
JTextField tf;
JPanel p;
JButton[] button;

String str_num;
String temp1, temp2;
double result;
boolean check_point;

public CalculatorTest2()
{
this.setSize(300, 250);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

tf = new JTextField("0");
tf.setHorizontalAlignment(JTextField.RIGHT);
add(tf, "North");

p = new JPanel(new GridLayout(5, 4, 5, 5));

String str_button[] = {
"←", "CE", "C", "+",
"7", "8", "9" , "/",
"4", "5", "6" , "*",
"1", "2", "3" , "-",
"0", ".", "=" };

button = new JButton[str_button.length];

for(int i=0; i<str_button.length; i++)
{
button[i] = new JButton(str_button[i]);
button[i].addActionListener(this);
p.add(button[i]);
}

this.add(p);
}

public void actionPerformed(ActionEvent e)
{
String source = e.getActionCommand();
str_num = tf.getText();

if(source == "C")
{
tf.setText("0");
temp1=temp2 ="";
}
if(source == "CE")
{
tf.setText("0");
}
if(source == "←")
{
String temp = null;
if(!str_num.equals("0"))
{
try
{
temp = tf.getText();
tf.setText(temp.substring(0, temp.length()-1));
}
catch(StringIndexOutOfBoundsException se)
{
tf.setText("0");
}
}
}

if(source=="+" || source=="-" || source=="*" || source=="/")
{
tf.setText(""+result);
temp1 = str_num;
temp2 = source;

tf.setText("0");
}
if(source == "=")
{
if(temp2=="+")
result = Double.parseDouble(temp1)+Double.parseDouble(str_num);
if(temp2=="-")
result = Double.parseDouble(temp1)-Double.parseDouble(str_num);
if(temp2=="*")
result = Double.parseDouble(temp1)*Double.parseDouble(str_num);
if(temp2=="/")
result = Double.parseDouble(temp1)/Double.parseDouble(str_num);

tf.setText(""+result);
}

if(source=="0" || source=="1" || source == "2" || source == "3"
|| source == "4" || source == "5" || source == "6"
|| source == "7" || source == "8" || source == "9")
{
if(str_num.equals("0"))
tf.setText(source);
else
tf.setText(str_num+source);
}

if(source=="." && check_point)
{
tf.setText(str_num+source);
check_point = false;
}
}

public static void main(String[] args)
{
new CalculatorTest2();
}
}


Java 9일차 계산기 GUI (초안)

import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class CalculatorTest extends JFrame
{
JTextField tf;
JPanel p;
JButton b_back, b_ce, b_c, b_add, b_7, b_8, b_9,
b_div, b_4, b_5, b_6, b_mul, b_1, b_2, b_3,
b_sub, b_0, b_point, b_equ;

public CalculatorTest()
{
this.setSize(300, 250);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

tf = new JTextField("0");
tf.setHorizontalAlignment(JTextField.RIGHT);
add(tf, "North");

p = new JPanel(new GridLayout(5, 4, 5, 5));

b_back = new JButton("←"); p.add(b_back);
b_ce = new JButton("CE"); p.add(b_ce);
b_c = new JButton("C"); p.add(b_c);
b_add = new JButton("+"); p.add(b_add);
b_7 = new JButton("7"); p.add(b_7);
b_8 = new JButton("8"); p.add(b_8);
b_9 = new JButton("9"); p.add(b_9);
b_div = new JButton("/"); p.add(b_div);
b_4 = new JButton("4"); p.add(b_4);
b_5 = new JButton("5"); p.add(b_5);
b_6 = new JButton("6"); p.add(b_6);
b_mul = new JButton("*"); p.add(b_mul);
b_1 = new JButton("1"); p.add(b_1);
b_2 = new JButton("2"); p.add(b_2);
b_3 = new JButton("3"); p.add(b_3);
b_sub = new JButton("-"); p.add(b_sub);
b_0 = new JButton("0"); p.add(b_0);
b_point = new JButton("."); p.add(b_point);
b_equ = new JButton("="); p.add(b_equ);

this.add(p);
}

public static void main(String[] args)
{
new CalculatorTest();
}
}


Java #3-1 반복문

for문

/* 1부터 10까지 덧셈을 표시하고 합을 구하는 프로그램 */
public class ForSample
{
public static void main(String[] args)
{
int sum = 0;
for(int i=1; i<=10; i++)
{
sum += i;
System.out.print(i);
if(i==10)
System.out.println("="+sum);
else
System.out.print("+");
}
}
}





while문

/* 숫자를 여러 개 입력받고 그 수의 평균을 출력하는 프로그램(0이 입력되면 종료) */
import java.util.Scanner;

public class WhileSample
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int number;
double sum = 0;
int count = 0;
while((number=sc.nextInt()) != 0)
{
sum += number;
count++;
}
System.out.println("입력하신 모든 수의 평균은 "+sum/count+"입니다.");
}
}









do-while문

/* 'a'부터 'z'까지 출력하는 프로그램 */
public class DoWhileSample
{
public static void main(String[] args)
{
char alpha = 'a';

do
{
System.out.print(alpha++);
}
while(alpha<='z');
}
}





중첩 반복문

/* 구구단 출력 프로그램(가로방향, 세로방향) */
public class NestedLoop
{
public static void main(String[] args)
{
for(int i=2; i<10; i++, System.out.println())
for(int j=1; j<10; j++, System.out.print('\t'))
System.out.print(i+"*"+j+"="+i*j);
System.out.println();
for(int i=1; i<10; i++, System.out.println())
for(int j=2; j<10; j++, System.out.print('\t'))
System.out.print(j+"*"+i+"="+i*j);
}
}




Java 9일차 ActionListener 테스트4 (버튼 2개의 경우)

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;

public class EventTest extends JFrame implements ActionListener
{
JTextArea ta;
JButton button_top, button_bot;

public EventTest()
{
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(400, 300);
this.setVisible(true);

ta = new JTextArea();

button_top = new JButton("클릭");
button_bot = new JButton("클릭");
button_top.addActionListener(this);
button_bot.addActionListener(this);

add(ta);
add("North", button_top);
add("South", button_bot);
}

public static void main(String[] args)
{
new EventTest();
}

public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();

if(source==button_top)
ta.append("윗쪽 버튼"+'\n');
else if(source==button_bot)
ta.append("아래쪽 버튼"+'\n');
}
}


Java 9일차 ActionListener 테스트3 (외부이벤트)

EvetnTest3.java

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;

public class EventTest3 extends JFrame
{
static JTextArea ta;
JButton button;

public EventTest3()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400,300);
setVisible(true);

ta = new JTextArea();

button = new JButton("클릭");

InheritanceEventTest ie =new InheritanceEventTest();
button.addActionListener(ie);

add(ta);
add("North", button);
}

public static void main(String[] args)
{
new EventTest3();
}
}

InheritanceEventTest.java

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class InheritanceEventTest implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
EventTest3.ta.append("외부이벤트"+'\n');
}
}


Java 9일차 ActionListener 테스트2 (내부무명이벤트)

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;

public class EventTest2 extends JFrame
{
JTextArea ta;
JButton button;

public EventTest2()
{
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(400, 300);
this.setVisible(true);

ta = new JTextArea();

button = new JButton("클릭");
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
ta.append("내부 무명 클래스"+'\n');
}
});

add(ta);
add("North", button);
}

public static void main(String[] args)
{
new EventTest2();
}
}


Java 9일차 ActionListener 테스트

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextArea;

public class EventTest extends JFrame implements ActionListener
{
JTextArea ta;
JButton button;

public EventTest()
{
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(400, 300);
this.setVisible(true);

ta = new JTextArea();

button = new JButton("클릭");
button.addActionListener(this);

add(ta);
add("North", button);
}

public static void main(String[] args)
{
new EventTest();
}

public void actionPerformed(ActionEvent e)
{
//ta.setText("버튼 클릭");
ta.append("한번 더"+'\n');
}
}


Java 8일차 자기소개 GUI

import java.awt.GridLayout;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

public class TotalTest extends JFrame
{
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
JPanel panel3 = new JPanel();
JPanel panel4 = new JPanel();
JPanel panel5 = new JPanel();
JPanel panel6 = new JPanel();

JLabel id, password, name, sex, hobby, hp, intro, etc1, etc2, bar1, bar2;
JTextField tf_id, tf_pw, tf_name, tf_hp1, tf_hp2, tf_intro;
JRadioButton male, female;
ButtonGroup bg;
JCheckBox trip, reading;
JComboBox<String> hp_cb;
String hp_num[] = {"010","011","016","019"};
JButton send, cancel;

public TotalTest()
{
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(400, 300);
this.setVisible(true);

GridLayout grid = new GridLayout(6, 1);
setLayout(grid);

id = new JLabel("아이디");
tf_id = new JTextField(8);
etc1 = new JLabel("*8자 이내");
panel1.add(id);
panel1.add(tf_id);
panel1.add(etc1);

password = new JLabel("비밀번호");
tf_pw = new JTextField(8);
name = new JLabel("성명");
tf_name = new JTextField(8);
panel2.add(password);
panel2.add(tf_pw);
panel2.add(name);
panel2.add(tf_name);

sex = new JLabel("성별");
male = new JRadioButton("남");
female = new JRadioButton("여");
bg = new ButtonGroup();
bg.add(male);
bg.add(female);
hobby = new JLabel("취미");
trip = new JCheckBox("여행");
reading = new JCheckBox("독서");
panel3.add(sex);
panel3.add(male);
panel3.add(female);
panel3.add(hobby);
panel3.add(trip);
panel3.add(reading);

hp = new JLabel("H.P");
hp_cb = new JComboBox<>(hp_num);
tf_hp1 = new JTextField(3);
tf_hp2 = new JTextField(3);
bar1 = new JLabel("-");
bar2 = new JLabel("-");
etc2 = new JLabel("*필수입력");
panel4.add(hp);
panel4.add(hp_cb);
panel4.add(bar1);
panel4.add(tf_hp1);
panel4.add(bar2);
panel4.add(tf_hp2);
panel4.add(etc2);

intro = new JLabel("자기소개");
tf_intro = new JTextField(20);
panel5.add(intro);
panel5.add(tf_intro);

send = new JButton("전송");
cancel = new JButton("취소");
panel6.add(send);
panel6.add(cancel);

this.add(panel1);
this.add(panel2);
this.add(panel3);
this.add(panel4);
this.add(panel5);
this.add(panel6);
}

public static void main(String[] args)
{
new TotalTest();
}
}