mhj9367
10
2021-04-08 12:17:45
1
100

Java 클래스 패널 가져오기 고수님들 좀 도와주십쇼..


1번 클래스


public class BookPane extends JPanel{


private Member member;

Connection con = null;

PreparedStatement pstmt = null;

ResultSet rs = null;

DefaultTableModel model;

JTextArea guestBookMyContent;

JTextArea guestBookContent;

JTextPane guestBookCommentWrite;

JTextArea guestBookCommentContent;

public BookPane() {

// frame = new JFrame();

// frame.setBounds(100, 100, 1280, 720);

// frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// frame.getContentPane().setLayout(null);

this.setBounds(40, 40, 910, 600);

this.setLayout(null);

// 방명록 스크롤 뒷 패널

JScrollPane guestBookScrollPane = new JScrollPane();

guestBookScrollPane.setBounds(260, 0, 650, 600);

// frame.getContentPane().add(guestBookScrollPane);

this.add(guestBookScrollPane);

// 방명록 레이아웃 패널

JPanel guestBookPane = new JPanel();

guestBookPane.setBackground(Color.WHITE);

guestBookScrollPane.setViewportView(guestBookPane);

guestBookPane.setLayout(null);

ImageIcon icon = new ImageIcon("images/home3.jpg");

Image img = icon.getImage();

Image changeImg = img.getScaledInstance(20, 20, Image.SCALE_SMOOTH);

ImageIcon changeIcon = new ImageIcon(changeImg);

// 첫번째 방명록 사진 라벨

ImageIcon icon1 = new ImageIcon("images/profile.jpg");

Image img2 = icon1.getImage();

Image changeImg2 = img2.getScaledInstance(130, 130, Image.SCALE_SMOOTH);

ImageIcon changeIcon2 = new ImageIcon(changeImg2);

JScrollBar scrollBar = new JScrollBar();

scrollBar.setForeground(Color.WHITE);

scrollBar.setBackground(Color.WHITE);

scrollBar.setBounds(631, 10, 17, 578);

guestBookPane.add(scrollBar);

// 방명록 기본 패널

JPanel guestBookInfoPane = new JPanel();

guestBookInfoPane.setBackground(Color.WHITE);

guestBookInfoPane.setBounds(12, 238, 611, 305);

guestBookPane.add(guestBookInfoPane);

guestBookInfoPane.setLayout(null);

// 첫번째 방명록 정보 및 메뉴 패널

JPanel guestBookInfoMenu_1 = new JPanel();

guestBookInfoMenu_1.setBackground(SystemColor.control);

guestBookInfoMenu_1.setForeground(SystemColor.control);


guestBookInfoMenu_1.setBounds(12, 20, 604, 37);

guestBookInfoPane.add(guestBookInfoMenu_1);

guestBookInfoMenu_1.setLayout(null);

// 첫번째 방명록 정보 라벨

JLabel guestBookNo = new JLabel("no 12345");

guestBookNo.setFont(new Font("맑은 고딕", Font.PLAIN, 12));

guestBookNo.setBounds(12, 10, 57, 15);

guestBookInfoMenu_1.add(guestBookNo);

RoundedButton guestBookName = new RoundedButton("문형준");

guestBookName.setFont(new Font("맑은 고딕", Font.BOLD, 12));

guestBookName.setBounds(71, 6, 71, 27);

guestBookInfoMenu_1.add(guestBookName);

JLabel guestBookWriteTime = new JLabel("2021.03.26 00:29");

guestBookWriteTime.setFont(new Font("맑은 고딕", Font.PLAIN, 12));

guestBookWriteTime.setBounds(173, 10, 117, 15);

guestBookInfoMenu_1.add(guestBookWriteTime);

// 첫번째 방명록 메뉴 버튼

RoundedButton guestBookSecretBt = new RoundedButton("방명록 보기");

guestBookSecretBt.setFont(new Font("맑은 고딕", Font.BOLD, 12));

guestBookSecretBt.setBounds(356, 7, 102, 23);

guestBookInfoMenu_1.add(guestBookSecretBt);

RoundedButton guestBookMoveBt = new RoundedButton(changeIcon);

guestBookMoveBt.setFont(new Font("맑은 고딕", Font.BOLD, 12));

guestBookMoveBt.setBounds(142, 6, 26, 27);

guestBookInfoMenu_1.add(guestBookMoveBt);

// 첫번째 방명록 내용

guestBookContent = new JTextArea();

guestBookContent.setBounds(189, 66, 387, 134);

guestBookInfoPane.add(guestBookContent);

JLabel guestBookPhoto = new JLabel(changeIcon2);

guestBookPhoto.setBounds(35, 66, 134, 134);

guestBookInfoPane.add(guestBookPhoto);

// 방명록 댓글 패널

JPanel guestBookCommentWritePane = new JPanel();

guestBookCommentWritePane.setBackground(Color.WHITE);

guestBookCommentWritePane.setBounds(12, 259, 587, 46);

guestBookInfoPane.add(guestBookCommentWritePane);

guestBookCommentWritePane.setLayout(null);

// 방명록 댓글

guestBookCommentWrite = new JTextPane();

guestBookCommentWrite.setBounds(12, 6, 492, 34);

guestBookCommentWritePane.add(guestBookCommentWrite);

// 방명록 댓글 쓰기 버튼

RoundedButton guestBookCommentWriteBt = new RoundedButton("쓰기");

guestBookCommentWriteBt.setBounds(516, 6, 65, 34);

guestBookCommentWriteBt.setFont(new Font("맑은 고딕", Font.BOLD, 12));

guestBookCommentWritePane.add(guestBookCommentWriteBt);

JPanel guestBookCommentbackPane = new JPanel();

guestBookCommentbackPane.setBackground(new Color(245, 245, 245));

guestBookCommentbackPane.setBounds(0, 198, 607, 61);

guestBookInfoPane.add(guestBookCommentbackPane);

guestBookCommentbackPane.setLayout(null);

JPanel guestBookCommentInfoPane = new JPanel();

guestBookCommentInfoPane.setBackground(new Color(245, 245, 245));

guestBookCommentInfoPane.setBounds(12, 10, 587, 47);

guestBookCommentbackPane.add(guestBookCommentInfoPane);

guestBookCommentInfoPane.setLayout(null);

RoundedButton guestBookCommentWriterBt = new RoundedButton("작성자1");

guestBookCommentWriterBt.setFont(new Font("맑은 고딕", Font.BOLD, 12));

guestBookCommentWriterBt.setBounds(12, 10, 89, 23);

guestBookCommentInfoPane.add(guestBookCommentWriterBt);

guestBookCommentContent = new JTextArea();

guestBookCommentContent.setBackground(new Color(245, 245, 245));

guestBookCommentContent.setBounds(107, 0, 480, 47);

guestBookCommentInfoPane.add(guestBookCommentContent);

// 방명록 쓰기

JPanel panel = new JPanel();

panel.setBackground(SystemColor.control);

panel.setBounds(12, 10, 611, 210);

guestBookPane.add(panel);

panel.setLayout(null);

JLabel guestBookMyPhoto = new JLabel((Icon) null);

guestBookMyPhoto.setBounds(35, 17, 134, 134);

panel.add(guestBookMyPhoto);

guestBookMyContent = new JTextArea();

guestBookMyContent.setBounds(181, 17, 387, 134);

panel.add(guestBookMyContent);

// 이벤트 처리

// 눌렀을때 작성한 사람의 방명록 내용이 보이게

guestBookSecretBt.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

connect();

guestbookselect();

}

});

// 이벤트처리

RoundedButton guestBookMyWriteBt = new RoundedButton("글쓰기");

guestBookMyWriteBt.setFont(new Font("맑은 고딕", Font.BOLD, 12));

guestBookMyWriteBt.setBounds(534, 161, 65, 34);

panel.add(guestBookMyWriteBt);

guestBookMyWriteBt.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent arg0) {

connect();

guestbookwrite();

guestbookselect();

}

});

RoundedButton guestBookDeleteBt = new RoundedButton("삭제");

guestBookDeleteBt.setFont(new Font("맑은 고딕", Font.BOLD, 12));

guestBookDeleteBt.setBounds(459, 7, 57, 23);

guestBookInfoMenu_1.add(guestBookDeleteBt);

guestBookDeleteBt.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

connect();

guestbookdelete();

}

});


}

private void connect() {

String driver = "oracle.jdbc.driver.OracleDriver";

String url = "jdbc:oracle:thin:@localhost:1521:xe";

String user = "web";

String password = "1234";

try {

Class.forName(driver);

con= DriverManager.getConnection(url, user, password);

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

private void guestbookselect() {

try {

String sql = "select content from guestbook where member_id = ?";

pstmt = con.prepareStatement(sql);

pstmt.setString(1, "dds4167");

rs = pstmt.executeQuery();

            while(rs.next()){

                String result = rs.getString("content");

                guestBookContent.append(result);

            }

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

private void guestbookwrite() {

try {

String sql = "insert into guestbook values(gb_no.nextval, 'n', 'dds4167', ?, sysdate, sysdate)";

pstmt = con.prepareStatement(sql);

String content = guestBookMyContent.getText();

pstmt.setString(1, content);

pstmt.executeUpdate();

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

private void guestbookdelete() {

try {

String sql = "delete from guestbook where gb_id=?";

pstmt = con.prepareStatement(sql);

} catch (SQLException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}


}


2번 클래스


package mainUI;


import java.awt.Color;

import java.awt.Font;

import java.awt.Image;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.io.FileInputStream;

import java.io.FileOutputStream;

import java.io.IOException;


import javax.swing.ImageIcon;

import javax.swing.JButton;

import javax.swing.JFileChooser;

import javax.swing.JLabel;

import javax.swing.JOptionPane;

import javax.swing.JPanel;

import javax.swing.JScrollPane;

import javax.swing.JTextArea;

import javax.swing.ScrollPaneConstants;

import javax.swing.SwingConstants;

import javax.swing.border.LineBorder;

import javax.swing.filechooser.FileNameExtensionFilter;


import db.DBConnection;

import model.Member;

import service.ImageResizeUpload;


public class ProfilePane extends JPanel{


// 매개변수

private Member member;

// 홈 메뉴 - 세부 프로필 컴포넌트

private JLabel profilePicLb;

private JTextArea profileMsgTa;

private JScrollPane profilestatusJs;

private JLabel profileInfoLb;

private JButton profileModifyBt;

private JButton profileModifyCBt;

private JButton profilePicModifyBt;

public ProfilePane(Member memberc) {

// 홈 메뉴 - 세부 프로필 패널

this.setBorder(new LineBorder(new Color(192, 192, 192)));

this.setBounds(0, 0, 260, 600);

this.setBackground(Color.WHITE);

this.setLayout(null);

this.member = memberc;

profileModifyBt = new JButton("");

profileModifyCBt = new JButton("");

profilePicLb = new JLabel("");

profileMsgTa = new JTextArea(5,19);

profileInfoLb = new JLabel(member.getMember_name()+" | "+

       member.getMember_gender()+" | "+

       member.getMember_birth());

profilePicModifyBt = new JButton("+");


//프로필 메시지 수정 들어가기

profileModifyBt.setText("+");

profileModifyBt.setBorder(new LineBorder(Color.LIGHT_GRAY));

profileModifyBt.setBackground(Color.WHITE);

profileModifyBt.setForeground(Color.WHITE);

profileModifyBt.setOpaque(false);

profileModifyBt.setContentAreaFilled(false);

profileModifyBt.setFocusPainted(false);

profileModifyBt.setFont(new Font("맑은 고딕", Font.PLAIN, 11));

profileModifyBt.setBounds(219, 419, 20, 20);

add(profileModifyBt);

profileModifyBt.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

profileMsgTa.setEnabled(true);

profileMsgTa.setEditable(true);

profileModifyBt.setVisible(false);

profileModifyCBt.setVisible(true);


}

});

add(profileModifyCBt);

//프로필 메시지 수정 완료 버튼

profileModifyCBt.setText("+");

profileModifyCBt.setBorder(new LineBorder(Color.LIGHT_GRAY));

profileModifyCBt.setBackground(Color.WHITE);

profileModifyCBt.setForeground(Color.WHITE);

profileModifyCBt.setOpaque(false);

profileModifyCBt.setContentAreaFilled(false);

profileModifyCBt.setFont(new Font("맑은 고딕", Font.PLAIN, 11));

profileModifyCBt.setBounds(219, 419, 20, 20);

profileModifyCBt.setVisible(false);

profileModifyCBt.setFocusPainted(false);

profileModifyCBt.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

member.setHome_profile_msg(profileMsgTa.getText());

DBConnection dbc = DBConnection.getInstance();

member = dbc.modifyMySetting("msg",member);

profileMsgTa.setText(member.getHome_profile_msg());

profileMsgTa.setEditable(false);

profileModifyBt.setVisible(true);

profileModifyCBt.setVisible(false);

}

});

// 프로필 사진 수정 버튼

profilePicModifyBt.setOpaque(false);

profilePicModifyBt.setFont(new Font("맑은 고딕", Font.PLAIN, 11));

profilePicModifyBt.setContentAreaFilled(false);

profilePicModifyBt.setBorder(new LineBorder(Color.LIGHT_GRAY));

profilePicModifyBt.setBackground(Color.WHITE);

profilePicModifyBt.setBounds(220, 205, 20, 20);

profilePicModifyBt.setForeground(Color.WHITE);

profilePicModifyBt.setFocusPainted(false);

add(profilePicModifyBt);


// 홈 메뉴 - 프로필 사진

Image Img = new ImageIcon(member.getHome_profile_pic()).getImage();

Image ImgResize = Img.getScaledInstance(220, 170, java.awt.Image.SCALE_SMOOTH);

ImageIcon resizeIcon = new ImageIcon(ImgResize);

profilePicLb.setIcon(resizeIcon);

profilePicLb.setHorizontalAlignment(SwingConstants.CENTER);

profilePicLb.setBounds(20, 55, 220, 170);

profilePicLb.setFocusable(true);

this.add(profilePicLb);

// 홈 메뉴 - 프로필 상태 메시지(원본)

profileMsgTa.setFont(new Font("맑은 고딕", Font.PLAIN, 13));

profileMsgTa.setForeground(Color.BLACK);

profileMsgTa.setEditable(false);

profileMsgTa.setText(member.getHome_profile_msg());

JScrollPane profileMsgJs = new JScrollPane(

profileMsgTa,

ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,

ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

profileMsgJs.setSize(220, 170);

profileMsgJs.setLocation(20, 270);

profileMsgJs.setForeground(Color.BLACK);

this.add(profileMsgJs);

// 홈 메뉴 - 프로필 정보

profileInfoLb.setFont(new Font("맑은 고딕", Font.BOLD, 14));

profileInfoLb.setForeground(new Color(9, 131, 178));

profileInfoLb.setHorizontalAlignment(SwingConstants.CENTER);

profileInfoLb.setBounds(20, 470, 220, 50);

this.add(profileInfoLb);


profilePicModifyBt.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

ImageResizeUpload iru = 

new ImageResizeUpload("img", member.getMember_id(), 220, 170);

profilePicLb.setIcon(iru.getResizeIcon());

member.setHome_profile_pic(iru.getUserImgPath());

DBConnection dbc = DBConnection.getInstance();

member = dbc.modifyMySetting("pic",member);


}

});

}

}


1번 클래스에다가 2번의 패널을 가져다가 쓰라는데 도저히 어떻게 하는지 모르겠습니다.
자바 공부한지 한달되었는데, 고수님들 제발 좀 도와주세요
0
  • 답변 1

  • 거신
    842
    2021-04-08 12:43:39 작성 2021-04-08 12:43:48 수정됨
    2번 클래스의 인스턴스를 생성해서 1번에서 변수로 생성 후에 불러오면 되지 않나요?
  • 로그인을 하시면 답변을 등록할 수 있습니다.