Java 계산기 레이아웃

Programming/JAVA,JSP 2012. 11. 17. 14:44 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;


import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.JTextField;


class Cal extends JFrame {

private JTextField t1;

private JButton b1, b2, b3, b4, b5, b6, b7, b8, b9, b0;

JButton pl, mi, mu, di, cal, c;

String x, y;


public Cal() {

setSize(285, 350);

setDefaultCloseOperation(EXIT_ON_CLOSE);

setTitle("Calculator");

JPanel p = new JPanel();

p.setLayout(null);


t1 = new JTextField(10);

p.add(t1);


b1 = new JButton("1");

p.add(b1);

b1.addActionListener(new Number());


b2 = new JButton("2");

p.add(b2);

b2.addActionListener(new Number());


b3 = new JButton("3");

p.add(b3);

b3.addActionListener(new Number());


b4 = new JButton("4");

p.add(b4);

b4.addActionListener(new Number());


b5 = new JButton("5");

p.add(b5);

b5.addActionListener(new Number());


b6 = new JButton("6");

p.add(b6);

b6.addActionListener(new Number());


b7 = new JButton("7");

p.add(b7);

b7.addActionListener(new Number());


b8 = new JButton("8");

p.add(b8);

b8.addActionListener(new Number());


b9 = new JButton("9");

p.add(b9);

b9.addActionListener(new Number());


b0 = new JButton("0");

p.add(b0);

b0.addActionListener(new Number());


pl = new JButton("+");

p.add(pl);

pl.addActionListener(new Number());


mi = new JButton("-");

p.add(mi);

mi.addActionListener(new Number());


mu = new JButton("*");

p.add(mu);

mu.addActionListener(new Number());


di = new JButton("/");

p.add(di);

di.addActionListener(new Number());


cal = new JButton("=");

p.add(cal);

cal.addActionListener(new Number());


c = new JButton("C");

p.add(c);

c.addActionListener(new Number());


t1.setBounds(10, 10, 245, 80);

b1.setBounds(10, 105, 45, 45);

b2.setBounds(60, 105, 45, 45);

b3.setBounds(110, 105, 45, 45);

b4.setBounds(10, 155, 45, 45);

b5.setBounds(60, 155, 45, 45);

b6.setBounds(110, 155, 45, 45);

b7.setBounds(10, 205, 45, 45);

b8.setBounds(60, 205, 45, 45);

b9.setBounds(110, 205, 45, 45);

b0.setBounds(60, 255, 45, 45);

pl.setBounds(160, 105, 45, 45);

mi.setBounds(160, 155, 45, 45);

mu.setBounds(160, 205, 45, 45);

di.setBounds(160, 255, 45, 45);

c.setBounds(110, 255, 45, 45);

cal.setBounds(210, 105, 45, 195);


add(p);

setVisible(true);

}


private class Number implements ActionListener {

public void actionPerformed(ActionEvent e) {

}

}

}


public class cals {

public static void main(String[] args) {

Cal Cals = new Cal();


}

}

'Programming > JAVA,JSP' 카테고리의 다른 글

JAVA 다중 계산 계산기  (0) 2012.11.17
JAVA TCP 통신 예제  (0) 2012.11.17
setLookAndFeel 예제  (0) 2012.11.04
JAVA Look and Feel 활용 사이트  (0) 2012.11.04
JAVA Applet Chatting Client  (0) 2012.07.26