검색결과 리스트
글
열혈강의 자바 22장 과제 2
//아 점점 게을러지내... 급하게 하긴햇으...
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Vector;
import javax.swing.*;
import javax.swing.border.BevelBorder;
import javax.swing.border.SoftBevelBorder;
import javax.swing.border.TitledBorder;
class write {
private String author;
private String title;
private String pass;
private String content;
public write(String author1,String title2,String pass3,String content4){
author=author1;
title=title2;
pass=pass3;
content=content4;
}
public String getauthor(){
return author;
}
public String gettitle(){
return title;
}
public String getpass(){
return pass;
}
public String getcontent(){
return content;
}
}
class Ex2 extends JFrame implements ActionListener, MouseListener{
private Vector vc=new Vector();
private write wr;
private Container con;
private JButton jbt1=new JButton("리스트보기");
private JButton jbt2=new JButton("글쓰기");
private JButton jbt3=new JButton("저장");
private JButton jbt4=new JButton("취소");
private JButton jbt5=new JButton("선택항목보기");
private JButton jbt6=new JButton("닫기");
private JButton jbt7=new JButton("확인");
private JPanel jp1=new JPanel();
private JPanel jp2=new JPanel();
private JPanel jp3=new JPanel();
private JPanel jp4=new JPanel();
private JPanel jp5=new JPanel();
private JPanel jp6=new JPanel();
private JPanel jp7=new JPanel();
private JPanel jp8=new JPanel();
private JPanel jp9=new JPanel();
private JLabel jl1=new JLabel("작성자 : ",JLabel.RIGHT);
private JLabel jl2=new JLabel("제목 : ",JLabel.RIGHT);
private JLabel jl3=new JLabel("비밀번호 : ",JLabel.RIGHT);
private JLabel jl4=new JLabel("리스트목록",JLabel.CENTER);
private JLabel jl5=new JLabel("제목 : ",JLabel.RIGHT);
private JLabel jl6=new JLabel("작성자 : ",JLabel.RIGHT);
private JLabel jl7=new JLabel("",JLabel.LEFT);
private JLabel jl8=new JLabel("",JLabel.LEFT);
private JTextField jtf1=new JTextField();
private JTextField jtf2=new JTextField();
private TextField jtf3=new TextField();
private JTextArea jta1=new JTextArea();
private JTextArea jta2=new JTextArea();
private List List=new List();
private JDialog jd1=new JDialog(this,"글쓰기",false);
private JDialog jd2=new JDialog(this,"리스트목록",false);
private JDialog jd3=new JDialog(this,"글보기",false);
public Ex2(){
super("게시판");
this.setSize(250,80);
this.init();
this.start();
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frm=this.getSize();
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(new BorderLayout());
jp1.add(jbt1);
jp1.add(jbt2);
con.add("Center",jp1);
}
public void start(){
jbt1.addActionListener(this);
jbt2.addActionListener(this);
jbt3.addActionListener(this);
jbt4.addActionListener(this);
jbt5.addMouseListener(this);
jbt6.addActionListener(this);
jbt7.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==jbt7){
jd3.setVisible(false);
}
if(e.getSource()==jbt5){
jd3.setVisible(true);
jd3.setLayout(new BorderLayout());
jd3.setSize(350, 200);
}
if(e.getSource()==jbt3){
jd1.setVisible(false);
String author1 = jtf1.getText();
String title2 = jtf2.getText();
String pass3 = jtf3.getText();
String content4 = jta1.getText();
wr=new write(author1, title2, pass3, content4);
vc.addElement(wr);
jtf1.setText("");
jtf2.setText("");
jtf3.setText("");
jta1.setText("");
}
if(e.getSource()==jbt6){
jd2.setVisible(false);
List.removeAll();
}
if(e.getSource()==jbt4){
jd1.setVisible(false);
jtf1.setText("");
jtf2.setText("");
jtf3.setText("");
jta1.setText("");
}
if(e.getSource()==jbt1){
jd2.setVisible(true);
jd2.setLayout(new BorderLayout());
jd2.setSize(450, 400);
jd2.setLocation(700,200);
jd2.add("North",jl4);
jd2.add("Center",List);
jp7.setLayout(new FlowLayout(FlowLayout.RIGHT));
jp7.add(jbt5);
jp7.add(jbt6);
jd2.add("South",jp7);
Font font =new Font("SansSerif",Font.BOLD,20);
List.setFont(font);
for(int i=0;i<vc.size();++i){
int num=i+1;
wr = (write)vc.elementAt(i);
List.add(num+":"+wr.gettitle()+":"+wr.getauthor());
}
}
if(e.getSource()==jbt2){
jd1.setVisible(true);
jd1.setSize(450, 400);
jd1.setLocation(200,200);
jd1.setLayout(new BorderLayout());
jp2.setLayout(new BorderLayout());
jp2.setBorder(new TitledBorder(new SoftBevelBorder(SoftBevelBorder.RAISED), "기본정보"));
jp3.setLayout(new GridLayout(3,1,5,5));
jp3.add(jl1);
jp3.add(jl2);
jp3.add(jl3);
jp2.add("West",jp3);
jp4.setLayout(new GridLayout(3,1,5,5));
jp4.add(jtf1);
jp4.add(jtf2);
jtf3.setEchoChar('*');
jp4.add(jtf3);
jp2.add("Center",jp4);
jd1.add("North",jp2);
jp5.setLayout(new BorderLayout());
jp5.setBorder(new TitledBorder(new SoftBevelBorder(SoftBevelBorder.RAISED), "내용작성"));
jp5.add(jta1);
jd1.add("Center",jp5);
jp6.setLayout(new FlowLayout(FlowLayout.RIGHT));
jp6.add(jbt3);
jp6.add(jbt4);
jd1.add("South",jp6);
jbt3.setBorder(new BevelBorder(BevelBorder.RAISED));
jbt4.setBorder(new BevelBorder(BevelBorder.RAISED));
}
}
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==jbt5){
int index=List.getSelectedIndex();
jd3.setVisible(true);
jd3.setSize(300, 200);
jd3.setLocation(400,200);
jd3.setLayout(new BorderLayout());
jp8.setLayout(new GridLayout(2,1,5,5));
wr = (write)vc.elementAt(index);
jl7.setText("제목 : "+wr.gettitle());
jl8.setText("작성자 : "+wr.getauthor());
jp8.add(jl7);
jp8.add(jl8);
jd3.add("North",jp8);
jta2.setText(wr.getcontent());
jd3.add("Center",jta2);
jd3.add("South",jbt7);
}
}
@Override
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}
}
public class Ex02 {
public static void main(String [] ar){
Ex2 ex=new Ex2();
}
}
'JAVA > 소스' 카테고리의 다른 글
Hello Java (0) | 2014.01.13 |
---|---|
열혈강의 자바 24장 과제 1 [미완성] (2) | 2012.02.03 |
열혈강의 자바 22장 과제 1 (1) | 2012.01.11 |
자바 21장 과제 2 (0) | 2011.12.15 |
자바 문자열 숫자로 바꾸는 방법 (0) | 2011.12.12 |