Search

'Calc'에 해당되는 글 2건

  1. 2013.08.16 JAVA 계산기 프로그램 부분완성
  2. 2013.08.16 JAVA 계산기 레이아웃

JAVA 계산기 프로그램 부분완성

Programming/JAVA,JSP 2013. 8. 16. 14:25 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
package com.tansanc.tistory;

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);

	}

	String operand1;
	String operator;
	private class Number implements ActionListener
	{

		public void actionPerformed(ActionEvent e)
		{
			if( e.getSource() == b1)
			{
				t1.setText(t1.getText() + "1");
			}
			else if( e.getSource() == b2)
			{
				t1.setText(t1.getText() + "2");
			}
			else if( e.getSource() == pl)
			{
				operand1 = t1.getText();
				operator = "+";
				t1.setText("");
			}
			else if( e.getSource() == cal)
			{
				if(operator == "+")
				{
					t1.setText("" + ( Integer.parseInt(operand1) + Integer.parseInt(t1.getText())) );
				}
			}
		}
	}

}

public class CardTest
{

	public static void main(String[] args)
	{

		Cal Cals = new Cal();

	}

}

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

JAVA 채팅 프로그램 소스  (0) 2013.08.23
JAVA 채팅 클라이언트  (0) 2013.08.23
JAVA 계산기 레이아웃  (0) 2013.08.16
JAVA 타자연습 프로그램  (0) 2013.08.13
JAVA Console Token 구현  (0) 2013.08.07

JAVA 계산기 레이아웃

Programming/JAVA,JSP 2013. 8. 16. 13:30 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.
package com.tansanc.tistory;

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 CardTest
{

	public static void main(String[] args)
	{

		Cal Cals = new Cal();

	}

}

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

JAVA 채팅 클라이언트  (0) 2013.08.23
JAVA 계산기 프로그램 부분완성  (0) 2013.08.16
JAVA 타자연습 프로그램  (0) 2013.08.13
JAVA Console Token 구현  (0) 2013.08.07
JAVA 제네릭을 사용한 Store Class  (0) 2013.08.07