Swing001
2019. 7. 25. 10:55
Study/Java Basic
package kr.ac.jj;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class Swing_001 extends JFrame implements ActionListener{
JLabel lb;
JLabel lbValue;
JTextField txtName;
JTextField txtNum;
JTextField txtValue;
JButton btn;
public Swing_001() {
// TODO Auto-generated constructor stub
this.setSize(1080, 720);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setLayout(null);
lb = new JLabel("이름 : ");
lb.setBounds(10, 10, 150, 50);
lb.setBackground(Color.BLUE);
lb.setFont(new Font("굴림", Font.BOLD,20));
lb.setHorizontalAlignment(JLabel.CENTER);
this.add(lb);
txtName = new JTextField();
txtName.setBounds(160, 10, 300, 50);
txtName.setFont(new Font("굴림",Font.BOLD,20));
this.add(txtName);
lb = new JLabel("번호 : ");
lb.setBounds(10, 110, 150, 50);
lb.setBackground(Color.BLUE);
lb.setFont(new Font("굴림", Font.BOLD,20));
lb.setHorizontalAlignment(JLabel.CENTER);
this.add(lb);
txtNum = new JTextField();
txtNum.setBounds(160, 110, 300, 50);
txtNum.setFont(new Font("굴림",Font.BOLD,20));
txtNum.setHorizontalAlignment(JLabel.CENTER);
this.add(txtNum);
txtValue = new JTextField();
txtValue.setBounds(160, 210, 300, 50);
txtValue.setFont(new Font("굴림",Font.BOLD,20));
txtValue.setHorizontalAlignment(JLabel.CENTER);
this.add(txtValue);
lb = new JLabel("결과 : ");
lb.setBounds(10, 210, 150, 50);
lb.setBackground(Color.BLUE);
lb.setFont(new Font("굴림", Font.BOLD,20));
lb.setHorizontalAlignment(JLabel.CENTER);
this.add(lb);
btn = new JButton("실행");
btn.setBounds(50, 360, 400, 150);
btn.setFont(new Font("굴림", Font.BOLD,20));
btn.addActionListener(this);
this.add(btn);
this.setVisible(true);
}
public static void main(String[] e) {
// TODO Auto-generated method stub
new Swing_001();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
switch(e.getActionCommand()) {
case "실행":
txtValue.setText(
txtName.getText()+txtNum.getText()
);
break;
}
}
}