일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- VisualStudio 2003 .NET
- 자동화 서버
- 누난 너무 예뻐
- 자동화 서버는 개체를 작성할 수 없습니다.
- 네이버1위
- Visual Studio .NET 9.0 Express Edition
- 폰번호정리
- 폰번호추출
- 심플네이버
- 이메일수집
- esperanca
- 전화번호찾기
- 메일수집
- 용역직원
- Stand 4 U
- 김밥할머니 폭행 동영상
- http://www.microsoft.com/downloads/
- 이메일추출
- 이메일광고
- 비주얼 C++
- 절대참조
- 애러
- iostream.h
- 이메일수집기
- 태마곡
- 전번
- 김밥할머니 폭행사건
- esperanca.kr
- 제2의 동방신기
- 네이버
- Today
- Total
BLOG ESPERANCA
JAVA GUI 사칙연산 계산기 본문

import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class ButtonActionListener implements ActionListener {
private int intFlag = 0;
private String strAct = null;
private TextField display = null;
private String strOP = null;
private String strTmp = null;
public ButtonActionListener (TextField display) {
this.display = display;
}
public void actionPerformed(ActionEvent arg0) {
strAct = arg0.getActionCommand();
if (strAct.equals("/") || strAct.equals("*") || strAct.equals("-") || strAct.equals("+")){
strTmp =display.getText();
strOP = strAct;
intFlag = 1;
}
else if (strAct.equals("=")){
if (intFlag == 2){
long f = Long.parseLong(strTmp);
long e = Long.parseLong(display.getText());
long result;
if(strOP.equals("+")){
result = f + e;
display.setText(""+ result);
}
else if (strOP.equals("*")){
result = f * e;
display.setText(""+ result);
}
else if (strOP.equals("/")){
if(e ==0)
display.setText("Error:Divide by 0");
else{
result = f / e;
display.setText(""+ result);
}
}
intFlag = 0;
}
}
else if (strAct.equals("C")){
intFlag = 0;
display.setText("0");
}
else{
if(intFlag == 1){
intFlag = 2;
display.setText("0");
}
if(display.getText().equals("0")){
display.setText(strAct);
}
else{
display.setText(display.getText() + strAct);
}
}
}
}
import java.awt.Button;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.ActionListener;
public class ButtonPane extends Panel {
private TextField display = null;
private Button[] butt = null;
private final String[] buttName = { "7" , "8", "9" , "/",
"4", "5", "6", "*",
"1", "2", "3", "-",
"0", "C", "=", "+"};
public ButtonPane (TextField display){
this.display = display;
setLayout ( new GridLayout(4,4));
ActionListener act1 = new ButtonActionListener (display);
butt = new Button[buttName.length];
for(int i = 0; i < butt.length; i++){
butt[i] = new Button(buttName[i]);
butt[i].addActionListener(act1);
add (butt[i]);
}
}
}
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.*;
public class Calculator implements WindowListener {
private Frame mainFrame = null;
private TextField display = null;
private Panel displayPanel = null;
private ButtonPane buttonPane = null;
private String strTitle = null;
public Calculator (String strTitle){
this.strTitle = strTitle;
}
public void init(){
mainFrame = new Frame (strTitle);
mainFrame.setLayout(new BorderLayout());
mainFrame.setBounds(10,10, 250, 250);
mainFrame.addWindowListener(this);
display = new TextField (30);
display.setText("0");
display.setEditable(false);
displayPanel = new Panel();
displayPanel.setBounds(0, 30, 250, 40);
displayPanel.add(display);
buttonPane = new ButtonPane (display);
buttonPane.setBounds(0, 70, 250, 180);
mainFrame.add("North", displayPanel);
mainFrame.add("Center", buttonPane);
mainFrame.setVisible(true);
}
@Override
public void windowActivated(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowClosed(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowClosing(WindowEvent arg0) {
// TODO Auto-generated method stub
System.out.println("dfsdf");
mainFrame.setVisible(false);
mainFrame.dispose();
System.exit(0);
}
@Override
public void windowDeactivated(WindowEvent arg0) {
// TODO Auto-generated method stub
System.out.println("dfljsdflksdf");
}
@Override
public void windowDeiconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowIconified(WindowEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void windowOpened(WindowEvent arg0) {
// TODO Auto-generated method stub
}
public static void main (String[] args){
Calculator calculator = new Calculator ("dsfsdf");
calculator.init();
}
}