반응형
public class ShowDefaultDalog extends JDialog implements WindowListener { private static final long serialVersionUID = 1L; /* * imageHeight : 이미지 세로값 imageWidth : 이미지 가로값 */ private static int imageHeight = 30; private static int imageWidth = 30; private JPanel jDalog_Main_Panel; private JPanel jDalog_North_Panel; private JPanel jDalog_Center_Panel; private JPanel jDalog_South_Panel; private JPanel jDalog_West_Panel; private JPanel jDalog_East_Panel; private JButton yes_Btn; private JButton no_Btn; private JButton wait_Btn; private String yseBtnText; private String noBtnText; private String waitBtnText; private String imagePath; private String message; private int type; private int result; /** * 기본 다이얼로그설정 * * @author Leesangjun * @param title * 타이틀 message 다이얼로그 메시지, imagePath 설정 이미지 Path, type : 1,2,3 버튼 갯수 * @return 객체 생성 */ public ShowDefaultDalog(String title, String message, String imagePath, int type) { this.message = message; this.imagePath = imagePath; this.type = type; setTitle(title); } /** * 기본 다이얼로그설정 * * @author Leesangjun * @return Dialog View */ public void createView() { createNorthPanel(); createCenterPanel(); createSouthPanel(); createWestPanel(); createEastPanel(); jDalog_Main_Panel = new JPanel(); jDalog_Main_Panel.setLayout(new BorderLayout()); jDalog_Main_Panel.add("North", jDalog_North_Panel); jDalog_Main_Panel.add("Center", jDalog_Center_Panel); jDalog_Main_Panel.add("South", jDalog_South_Panel); jDalog_Main_Panel.add("West", jDalog_West_Panel); jDalog_Main_Panel.add("East", jDalog_East_Panel); addWindowListener(this); setAlwaysOnTop(true); setResizable(false); setModal(true); setType(Type.POPUP); add(jDalog_Main_Panel); pack(); Dimension frameSize = getSize(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); } private void createNorthPanel() { jDalog_North_Panel = new JPanel(); jDalog_North_Panel.setPreferredSize(new Dimension(0, 5)); } private void createCenterPanel() { jDalog_Center_Panel = new JPanel(new FlowLayout(FlowLayout.LEFT)); JPanel center = new JPanel(); ImagePanel imagePanel = new ImagePanel(new ImageIcon(getImagePath()).getImage()); imagePanel.setHeight(imageHeight); imagePanel.setWidth(imageWidth); imagePanel.setPreferredSize(new Dimension(imageWidth, imageHeight)); JLabel label = new JLabel(getMessage()); JPanel messagePanel = new JPanel(); messagePanel.add(label); center.add(imagePanel); center.add(messagePanel); jDalog_Center_Panel.add(center); } private void createWestPanel() { jDalog_West_Panel = new JPanel(); jDalog_West_Panel.setPreferredSize(new Dimension(5, 0)); } private void createSouthPanel() { jDalog_South_Panel = new JPanel(); String btnText = ""; if (yseBtnText == null) { btnText = UICode.DEFAULT_DIALOG_BUTTON_YES; } else { btnText = yseBtnText; } yes_Btn = new JButton(btnText); if (noBtnText == null) { btnText = UICode.DEFAULT_DIALOG_BUTTON_NO; } else { btnText = noBtnText; } no_Btn = new JButton(btnText); if (waitBtnText == null) { btnText = UICode.DEFAULT_DIALOG_BUTTON_WAIT; } else { btnText = waitBtnText; } wait_Btn = new JButton(btnText); switch (type) { case 1: jDalog_South_Panel.add(yes_Btn); break; case 2: jDalog_South_Panel.add(yes_Btn); jDalog_South_Panel.add(no_Btn); break; case 3: jDalog_South_Panel.add(yes_Btn); jDalog_South_Panel.add(no_Btn); jDalog_South_Panel.add(wait_Btn); break; default: break; } yes_Btn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub result = 1; setVisible(false); } }); no_Btn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub result = 2; setVisible(false); } }); wait_Btn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub result = 3; setVisible(false); } }); } private void createEastPanel() { jDalog_East_Panel = new JPanel(); } public String getImagePath() { return imagePath; } public void setImagePath(String imagePath) { this.imagePath = imagePath; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public int getResult() { return result; } public void setYseBtnText(String yseBtnText) { this.yseBtnText = yseBtnText; } public void setNoBtnText(String noBtnText) { this.noBtnText = noBtnText; } public void setWaitBtnText(String waitBtnText) { this.waitBtnText = waitBtnText; } @Override public void windowOpened(WindowEvent e) { // TODO Auto-generated method stub } @Override public void windowClosing(WindowEvent e) { // TODO Auto-generated method stub result = 2; setVisible(false); } @Override public void windowClosed(WindowEvent e) { // TODO Auto-generated method stub } @Override public void windowIconified(WindowEvent e) { // TODO Auto-generated method stub } @Override public void windowDeiconified(WindowEvent e) { // TODO Auto-generated method stub } @Override public void windowActivated(WindowEvent e) { // TODO Auto-generated method stub } @Override public void windowDeactivated(WindowEvent e) { // TODO Auto-generated method stub } } //////////////////////////////////////////////////////// //호출시 /////////////////////////////////////////////////////// String message = "길이길이길이길이ㅁㄴㅇㅁㄴㅇㅁㄴㅇㅁㄴㅇㅂㅈㄷㅂㅈㄷㅂㅈㄷㅂㅈㄷㅂㅈㄷㅂㅈㄷㅂㅈㄷㅂㅈㄷㅂㅈㄷㅂㅈㄷ"; String imagePath = "image/tray.png"; ShowDefaultDalog frame = new ShowDefaultDalog("타이틀!!", message, imagePath, 3); frame.setYseBtnText("asd"); frame.createView(); frame.setVisible(true); System.out.println("결과값: " + frame.getResult());
'JAVA > Java' 카테고리의 다른 글
eclipse에 github 연결해서 웹저장소에서 버전관리(repository)하기 (0) | 2016.05.20 |
---|---|
AES128 파일 암복호화 (0) | 2016.05.20 |
AES, SHA256 암 복호화 (0) | 2016.03.02 |
java String Calss (0) | 2015.03.18 |
[JAVA] SocketServer (0) | 2014.11.18 |