java

java 환율변경

코딩 공부중 2020. 1. 3. 11:35
 public class MyFrame extends JFrame{

	

	private JTextField input;		//숫자를 입력하기 위한 텍스트필드

	private JButton button;			//환율변경버튼

	private JLabel output;			//출력 라벨

	//private JLabel labelwon;

 

	public MyFrame() {

		this.setSize(300,200);		//프레임 사이즈

		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		this.setTitle("환율변경");

		

		JPanel panel = new JPanel();	//프레임 창안에 내용 출력을 위한 판넬

		JPanel panel2 = new JPanel();

		JPanel panel3 = new JPanel();

		

		button = new JButton("환율변환 ↓");

		input = new JTextField(8);		//괄호 안에 숫자는 입력 창을 8칸 띄운다는 뜻

		output = new JLabel("	");

		//labelwon = new JLabel("원");

		

		button.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent e) {		//한율변경 버튼을 눌렀을때

				

					String in = input.getText();		//텍스트필드에서 입력한 값을 스트링변수 in에 저장

					int won = Integer.parseInt(in);		//스트링 변수를 int형으로 변환

					double d = (double)won / 1000;		//원화를 달러로 변환하기 위해 1000으로 나눔

					

					output.setText(d + "달러");				//변환한 값을 출력

			}

			

		});

		

		panel.add(input);

		panel2.add(button);	

		panel3.add(output);

		

		this.add(panel);

		this.setVisible(true);

	}

	

}