일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
- flask
- SQL
- Django
- graphene-django
- array
- GraphQL
- FastAPI
- Django-allauth
- numpy
- allauth
- python
- check_password
- for loop
- tkinter Radio 동적버튼
- Today
- Total
객
[ Swing ] Dialog예제 본문
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Iterator;
import java.util.List;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
public class ComplaintsDialog extends JDialog implements MouseListener{
private static final long serialVersionUID = 1L;
private static Frame frame;
private JLabel lblNum , lblUserName;
private JComboBox jcomboNum;
private JTextField txtUserName;
private JButton btnSave , btnClear;
private JPanel panel , btnPanel;
public ComplaintsDialog() {
super(frame , true);
setTitle("변경 등록");
setSize(500,270);
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
setResizable(false); // 창의 크기를 자유로이 변화 시킬수 있음.
setLocationRelativeTo(null); // parent의 중앙에 위치 함.
panel = new JPanel(new BorderLayout());
panel.setLayout(new GridBagLayout());
panel.setBorder(new EmptyBorder(new Insets(5,5,5,5)));
getContentPane().add(BorderLayout.CENTER, panel);
GridBagConstraints gridconstrain = new GridBagConstraints();
gridconstrain.insets= new Insets(2,2,2,2);
gridconstrain.anchor = GridBagConstraints.WEST;
lblNum = new JLabel("등록 번호 : ");
lblNum.setBorder(new EmptyBorder(new Insets(0,0,0,10)));
panel.add(lblNum , gridconstrain);
jcomboNum = new JComboBox();
comboBoxNumber(); // 번호를 표시할 콤보박스입니다.
jcomboNum.setPreferredSize(new Dimension(300, 25));
jcomboNum.setMinimumSize(new Dimension(300,25));
gridconstrain.gridx = 1;
panel.add(jcomboNum, gridconstrain);
//==================================================================
lblUserName = new JLabel("변경 할 내용 : ");
gridconstrain.gridwidth = 1;
gridconstrain.gridx = 0;
gridconstrain.gridy = 1;
gridconstrain.weightx = 0.0;
panel.add(lblUserName , gridconstrain);
//-------------------------------------------------------------------
txtUserName = new JTextField();
txtUserName.setPreferredSize(new Dimension(250,25));
gridconstrain.gridx = 1;
gridconstrain.weightx = 0.0;
gridconstrain.gridwidth = 3;
gridconstrain.fill = GridBagConstraints.HORIZONTAL;
panel.add(txtUserName , gridconstrain);
//--------------------------------------------------------------------
btnPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 8, 35));
btnSave = new JButton("저 장");
btnSave.setPreferredSize(new Dimension(100,35));
btnPanel.add(btnSave , gridconstrain);
//--------------------------------------------------------------------
btnClear = new JButton("취 소");
btnClear.setPreferredSize(new Dimension(100,35));
btnPanel.add(btnClear , gridconstrain);
gridconstrain.gridx = 1;
gridconstrain.gridy = 7;
gridconstrain.gridwidth = 4;
panel.add(btnPanel , gridconstrain);
//--------------------------------------------------------------------
btnSave.addMouseListener(this);
btnClear.addMouseListener(this);
setVisible(true);
}
public static void main(String args[]) {
try {
new ComplaintsDialog();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void comboBoxNumber() {
StoryDAO sdao = new StoryDAO();
List<ComplaintsInfo> comInfo = sdao.selectAll();
Iterator<ComplaintsInfo> it = comInfo.iterator();
jcomboNum.addItem(" ");
while(it.hasNext()) {
ComplaintsInfo com = it.next();
String sNo = com.getstrNo();
String sName = com.getCompanyName();
jcomboNum.addItem(sNo + " - " + sName);
}
}
private void infoClear() {
ComplaintsInfo info = new ComplaintsInfo();
info.setstrNo("");
info.setstrUserName("");
info.setstrDate("");
}
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
if(e.getSource() == btnSave){
ComplaintsInfo info = new ComplaintsInfo();
StoryDAO sdao = new StoryDAO();
if(jcomboNum.getSelectedItem() != null && txtUserName.getText() != null && txtUserName.getText().length() != 0) {
info.setstrNo(jcomboNum.getSelectedItem().toString());
info.setstrUserName(txtUserName.getText());
boolean ok = sdao.DialogSave(info);
if (ok) {
JOptionPane.showMessageDialog(this, "저장 하였습니다." ,"저장" ,JOptionPane.INFORMATION_MESSAGE);
jcomboNum.setSelectedIndex(0);
txtUserName.setText("");
infoClear();
} else {
JOptionPane.showMessageDialog(this, "저장 실패" ,"저장" ,JOptionPane.ERROR_MESSAGE);
}
} else {
JOptionPane.showMessageDialog(this, "저장 실패" ,"수정" ,JOptionPane.ERROR_MESSAGE);
}
} else if (e.getSource() == btnClear) {
infoClear();
dispose();
}
}
@Override
public void mousePressed(MouseEvent e) {}
@Override
public void mouseReleased(MouseEvent e) {}
@Override
public void mouseEntered(MouseEvent e) {}
@Override
public void mouseExited(MouseEvent e) {}
}
'[PL] > JAVA' 카테고리의 다른 글
[ 펌 ] 이클립스 (0) | 2014.09.24 |
---|---|
puzzle 게임 (0) | 2014.09.18 |
[ Opnecv ] javacv 버그 관련 (0) | 2014.06.02 |
[ Swing ] MDI 샘플예제 (0) | 2014.05.30 |
WindowBuild Pro 관련 (0) | 2014.04.24 |