U E D R , A S I H C RSS

whiteblue/간단한계산기

아직은 인터페이스만...;;

~cpp 
import java.awt.*;

import javax.swing.*;

public class MyCalculator extends JFrame {

	JButton numberButton[];
	JTextField inputField = new JTextField();

	public MyCalculator() {
		GridBagLayout gridbag = new GridBagLayout();
		GridBagConstraints c = new GridBagConstraints();
		
		this.setTitle("Calculator");

		getContentPane().setLayout(gridbag);

		c.fill = GridBagConstraints.BOTH;
		c.weightx = 1.0;
		c.weighty = 1.0;
		c.gridwidth = GridBagConstraints.REMAINDER; //end row

		gridbag.setConstraints(inputField, c);
		getContentPane().add(inputField);

		c.weightx = 1.0;
		c.gridwidth = GridBagConstraints.LAST_LINE_END;
		
		makebutton("+", gridbag, c);
		makebutton("-", gridbag, c);
		makebutton("*", gridbag, c);

		c.gridwidth = GridBagConstraints.REMAINDER; //end row
		makebutton("/", gridbag, c);

		c.gridwidth = GridBagConstraints.LAST_LINE_END;
		makebutton("1", gridbag, c);
		makebutton("2", gridbag, c);
		makebutton("3", gridbag, c);

		c.gridwidth = GridBagConstraints.REMAINDER; //end row
		makebutton("<-", gridbag, c);

		c.gridwidth = GridBagConstraints.LAST_LINE_END;
		makebutton("4", gridbag, c);
		makebutton("5", gridbag, c);
		makebutton("6", gridbag, c);

		c.gridwidth = GridBagConstraints.REMAINDER; //end row
		makebutton("C", gridbag, c);

		c.gridwidth = GridBagConstraints.LAST_LINE_END;
		makebutton("7", gridbag, c);
		makebutton("8", gridbag, c);
		makebutton("9", gridbag, c);

		c.gridwidth = GridBagConstraints.REMAINDER; //end row
		makebutton("=", gridbag, c);

		setSize(300, 200);
		setVisible(true);
	}

	private void makebutton(
		String name,
		GridBagLayout gridbag,
		GridBagConstraints c) {
		Button button = new Button(name);
		gridbag.setConstraints(button, c);
		getContentPane().add(button);
	}

	public static void main(String[] args) {
		MyCalculator calculator = new MyCalculator();
	}
}

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:31:46
Processing time 0.0094 sec