import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class MyDialog extends JDialog{
private JTextField tf1=new JTextField(10);
private JTextField tf2=new JTextField(10);
private JButton jb1=new JButton ("Add");
public MyDialog(JFrame frame, String title) {
super(frame, true);
setLayout(new FlowLayout());
add(tf1);
add(tf2);
add(jb1);
setSize(500,500);
jb1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
setVisible(false);
}
});
}
public int getInput() {}
else if(tf1.getText().length()==0 || tf2.getText().length()==0) return 0;
else {
int num1 = Integer.valueOf(tf1.getText());
int num2 = Integer.valueOf(tf2.getText());
return num1+num2;
}
}
}
public class Main extends JFrame{
private MyDialog dialog;
public Main() {
Container c = getContentPane();
setDefaultCloseOperation(EXIT_ON_CLOSE);
JButton jb4=new JButton("calculate");
JLabel la=new JLabel("계산 결과 출력");
la.setOpaque(true); // 배경 불투명도 설정
la.setBackground(Color.GREEN);
dialog=new MyDialog(this, "diAlOG");
jb4.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
dialog.setVisible(true);
la.setText(Integer.toString(dialog.getInput()));
}
});
c.setLayout(new FlowLayout());
c.add(jb4);
c.add(la);
setSize(700,700);
setVisible(true);
}
public static void main(String[] args) {
new Main();
}
}