검색결과 리스트
글
열혈강의 자바 24장 과제 1 [미완성]
//기본틀만 대충 잡아낫는데... 언제 완성할지...딴거 할게 너무 많으...
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
class Ex1 extends JFrame implements ActionListener{
private Container con;
private JPanel p1=new JPanel();
private JPanel p2=new JPanel();
private JPanel p3=new JPanel();
private JPanel p4=new JPanel();
private JPanel p5=new JPanel();
private JPanel p6=new JPanel();
private JPanel p7=new JPanel();
private JPanel p8=new JPanel();
private JPanel p9=new JPanel();
private JPanel p10=new JPanel();
private JPanel p11=new JPanel();
private JPanel p12=new JPanel();
private JPanel p13=new JPanel();
private JPanel p14=new JPanel();
private JPanel p15=new JPanel();
private JPanel p16=new JPanel();
private JPanel p17=new JPanel();
private CardLayout cl=new CardLayout();
private JTextField tf1=new JTextField();
private JTextField tf2=new JTextField();
private JTextField tf3=new JTextField(30);
private JTextField tf4=new JTextField(30);
private JTextField tf5=new JTextField(5);
private JTextArea tfa1=new JTextArea();
private JList list1=new JList();
private JButton bt1=new JButton("회원가입");
private JButton bt2=new JButton("로그인");
private JButton bt3=new JButton("대화시작");
private JButton bt4=new JButton("전송");
private JButton bt5=new JButton("종료");
private JRadioButton rb1=new JRadioButton("귓속말 설정");
private JRadioButton rb2=new JRadioButton("귓속말 해체");
private ButtonGroup bg1=new ButtonGroup();
private ImageIcon im1 =new ImageIcon("background.jpg");
private JLabel jl1=new JLabel(im1);
private JLabel jl2=new JLabel("명");
public Ex1(String title){
super(title);
this.init();
this.start();
this.setSize(600,400);
Dimension screen =Toolkit.getDefaultToolkit().getScreenSize(); //화면 크기 구함
Dimension frm=super.getSize(); //f사이즈
//f를 중앙에 출력하기위해 x,y좌표 구함
int xpos =(int)(screen.getWidth()/2 -frm.getWidth()/2);
int ypos =(int)(screen.getHeight()/2 -frm.getHeight()/2);
this.setLocation(xpos,ypos);
this.setResizable(false);
this.setVisible(true);
}
public void init(){
con=this.getContentPane();
con.setLayout(cl);
p1.setLayout(new BorderLayout());
p1.add("North",p2);
p2.setLayout(new BorderLayout());
p2.setBorder(new TitledBorder(new SoftBevelBorder(SoftBevelBorder.RAISED), "Login Module"));
tf1.setBorder(new TitledBorder(new SoftBevelBorder(SoftBevelBorder.LOWERED), "ID"));
p2.add("North",tf1);
tf2.setBorder(new TitledBorder(new SoftBevelBorder(SoftBevelBorder.LOWERED), "PASS"));
p2.add("Center",tf2);
p4.setLayout(new FlowLayout());
p4.add(bt1);
p4.add(bt2);
p2.add("South",p4);
p8.setLayout(new BorderLayout());
p8.add("Center",jl1);
p5.setLayout(new GridLayout(1,3,5,5));
p5.add(p6);
p5.add(p7);
p5.add(p1);
p8.add("South",p5);
con.add("login",p8);
p9.setLayout(new BorderLayout());
p10.setLayout(new FlowLayout());
p10.setBorder(new TitledBorder(new SoftBevelBorder(SoftBevelBorder.LOWERED), "Nick Name"));
p10.add(tf3);
p10.add(bt3);
p11.setLayout(new BorderLayout());
p11.add("North",p10);
p12.setLayout(new BorderLayout());
p12.setBorder(new TitledBorder(new SoftBevelBorder(SoftBevelBorder.LOWERED), "View Pane"));
p12.add(tfa1);
p11.add("Center",p12);
p13.setLayout(new FlowLayout());
p13.setBorder(new TitledBorder(new SoftBevelBorder(SoftBevelBorder.LOWERED), "Talk Data"));
p13.add(tf4);
p13.add(bt4);
p11.add("South",p13);
p9.add("West",p11);
p14.setLayout(new FlowLayout());
p14.setBorder(new TitledBorder(new SoftBevelBorder(SoftBevelBorder.LOWERED), "총인원"));
p14.add(tf5);
p14.add(jl2);
p15.setLayout(new GridLayout(3,1));
p15.setBorder(new TitledBorder(new SoftBevelBorder(SoftBevelBorder.LOWERED), "Option"));
bg1.add(rb1);
bg1.add(rb2);
p15.add(rb1);
p15.add(rb2);
p15.add(bt5);
p16.setLayout(new BorderLayout());
p16.add("North",p14);
p16.add("Center",list1);
p16.add("South",p15);
p9.add("Center",p16);
con.add("chatting",p9);
}
public void start(){
bt2.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==bt2){
String id = tf1.getText();
String pass = tf2.getText();
if(id == null || pass == null || id.trim().length() == 0 || pass.trim().length() == 0) {
JOptionPane.showMessageDialog(this,
"ID나 PASS가 비었습니다.", "경고",
JOptionPane.ERROR_MESSAGE);
return;
}
cl.show(con, "chatting");
}
}
}
public class Ex01 {
public static void main(String [] ar){
Ex1 ex=new Ex1("Chatting~!");
}
}
'JAVA > 소스' 카테고리의 다른 글
자바 구조 예제 (0) | 2014.01.13 |
---|---|
Hello Java (0) | 2014.01.13 |
열혈강의 자바 22장 과제 2 (3) | 2012.01.11 |
열혈강의 자바 22장 과제 1 (1) | 2012.01.11 |
자바 21장 과제 2 (0) | 2011.12.15 |