수다닷컴

  • 해외여행
    • 괌
    • 태국
    • 유럽
    • 일본
    • 필리핀
    • 미국
    • 중국
    • 기타여행
    • 싱가폴
  • 건강
    • 다이어트
    • 당뇨
    • 헬스
    • 건강음식
    • 건강기타
  • 컴퓨터
    • 프로그램 개발일반
    • C언어
    • 비주얼베이직
  • 결혼생활
    • 출산/육아
    • 결혼준비
    • 엄마이야기방
  • 일상생활
    • 면접
    • 취업
    • 진로선택
  • 교육
    • 교육일반
    • 아이교육
    • 토익
    • 해외연수
    • 영어
  • 취미생활
    • 음악
    • 자전거
    • 수영
    • 바이크
    • 축구
  • 기타
    • 강아지
    • 제주도여행
    • 국내여행
    • 기타일상
    • 애플
    • 휴대폰관련
  • 프로그램 개발일반
  • C언어
  • 비주얼베이직

계산기 만들기 질문입니다.

지지않는

2023.04.01

숫자 버튼을 눌렀을때 이벤트가 발생하지 않습니다.왜 그런건지..ㅠ0ㅠ

고수님들의 답변 부탁드립니다!!!
import java.awt.*;
import java.awt.event.*;
public class EngCalculatorUI extends Frame implements ItemListener,ActionListener{
MenuBar mBar;
Menu editMenu,viewMenu;
Menu helpMenu;
GridBagConstraints gbc;
TextField resultScreen;
Button btnBackSpace,btnCE,btnC;
CheckboxGroup cbg1;
Checkbox cbHex,cbDec,cbOct,cbBin;
CheckboxGroup cbg2;
Checkbox cbDegrees,cbRadians,cbGrads;
Checkbox cbInv,cbHyp;
Button btnSta,btnFE,btnOpen,btnClose,btnMC,btnAve;
Button btndms,btnExp,btnln,btnMR,btnSum,btnsin,btnxbyy;
Button btnlog,btnMS,btns,btncos,btnxby3,btnfac,btnMPlus;
Button btnDat,btntan,btnxby2,btnDevideX,btnpi;
Button btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8,btn9,btn0;
Button btnPorM,btnPoint,btndevide,btnMod,btnAnd,btnMulti;
Button btnOr,btnXor,btnMinus,btnLsh,btnNot,btnPlus,btnResult;
Button btnInt,btnAA,btnBB,btnCC,btnDD,btnEE,btnFF;
Dialog dlgInfo;
Label ver_Info,name_Info,ID_Info,result;
String str;

public static void main(String[] args) {
EngCalculatorUI ecalcUI = new EngCalculatorUI();
}
public EngCalculatorUI() {

//배경 색상 정의
final Color ECACL_BG_COLOR = new Color(222,222,222);

// 메뉴바 생성
editMenu = new Menu(편집);
editMenu.add(복사);
editMenu.add(붙여넣기);

viewMenu = new Menu(보기);

mBar = new MenuBar();
mBar.add(editMenu);
mBar.add(viewMenu);

helpMenu = new Menu(도움말);
helpMenu.add(도움말 항목);
helpMenu.addSeparator();
MenuItem cal_Info = new MenuItem(계산기 정보);
helpMenu.add(cal_Info);
cal_Info.addActionListener(this); mBar.setHelpMenu(helpMenu);
setMenuBar(mBar);

//panel 생성

//결과표시 panel
Panel resultPanel = new Panel();

//보기 선택 panel
Panel viewSelectionPanel = new Panel();

//기능 panel
Panel buttonsPanel = new Panel();

//보디 패널 생성
Panel bodyPanel = new Panel();
bodyPanel.setBackground(ECACL_BG_COLOR);
add(bodyPanel);

//보디 패널에 Layout 관리자로 GridBagLayout 설정
GridBagLayout gbl = new GridBagLayout();
bodyPanel.setLayout(gbl);

Insets i = new Insets(0, 0, 0, 0);
//각 패널에 GridBagConstraints 설정
GridBagConstraints gbc;
gbc = new GridBagConstraints
(0,0,1,1,1.0,1.0,GridBagConstraints.WEST,GridBagConstraints.BOTH,i,0,0);
gbl.setConstraints(resultPanel, gbc);
gbc = new GridBagConstraints
(0,3,1,1,1.0,1.0,GridBagConstraints.WEST,GridBagConstraints.BOTH,i,0,0);
gbl.setConstraints(viewSelectionPanel, gbc);
gbc = new GridBagConstraints
(0,6,1,1,1.0,8.0,GridBagConstraints.WEST,GridBagConstraints.BOTH,i,0,0);
gbl.setConstraints(buttonsPanel, gbc);

//서브 패널 생성
Panel subPanel1 = new Panel();
Panel subPanel2 = new Panel();
Panel subPanel3 = new Panel();
Panel subPanel4 = new Panel();
Panel buttonsPanel1 = new Panel();
buttonsPanel1.setBackground(ECACL_BG_COLOR);
GridBagLayout bgbl = new GridBagLayout();
buttonsPanel.setLayout(bgbl);
Insets bi = new Insets(0, 0, 0, 0);

// 각 서브 패널에 GridBagConstraints 설정
GridBagConstraints bgbc;
bgbc = new GridBagConstraints(0,0,1,1,0.5,1.0,
GridBagConstraints.WEST, GridBagConstraints.BOTH, bi,0,0);
bgbl.setConstraints(subPanel1, bgbc);
bgbc = new GridBagConstraints(1,0,1,1,0.5,1.0,
GridBagConstraints.WEST,GridBagConstraints.BOTH,bi,0,0);
bgbl.setConstraints(subPanel2, bgbc);
bgbc = new GridBagConstraints(0,1,1,1,0.5,5.0,
GridBagConstraints.WEST,GridBagConstraints.BOTH,bi,0,0);
bgbl.setConstraints(subPanel3, bgbc);
bgbc = new GridBagConstraints(1,1,1,1,0.5,5.0,
GridBagConstraints.WEST,GridBagConstraints.BOTH, bi,0,0);
bgbl.setConstraints(subPanel4, bgbc);
buttonsPanel.add(subPanel1); buttonsPanel.add(subPanel2);
buttonsPanel.add(subPanel3); buttonsPanel.add(subPanel4);

//보디 패널에 각 패널 추가
bodyPanel.add(resultPanel);
bodyPanel.add(viewSelectionPanel);
bodyPanel.add(buttonsPanel);
add(bodyPanel);

resultScreen = new TextField(0.,49);
resultScreen.setEditable(false);
resultScreen.setBackground(new Color(255,255,255));
//resultScreen.setHorizontalAlignment(JTextField.RIGHT);
resultPanel.add(resultScreen);

//viewSelectionPanel 설정
viewSelectionPanel.setLayout(new GridLayout(1,2));

//checkbox
cbg1 = new CheckboxGroup();

cbHex = new Checkbox(Hex,cbg1,false);
cbDec = new Checkbox(Dec,cbg1,truebg1,true);
cbOct = new Checkbox(Oct,cbg1,false);
cbBin = new Checkbox(Bin,cbg1,false);

viewSelectionPanel.add(cbHex);viewSelectionPanel.add(cbDec);
viewSelectionPanel.add(cbOct);viewSelectionPanel.add(cbBin);

cbg2 = new CheckboxGroup();

cbDegrees = new Checkbox(Degress,cbg2,true);
cbRadians = new Checkbox(Radians,cbg2,false);
cbGrads = new Checkbox(Grads,cbg2,false);

viewSelectionPanel.add(cbDegrees);viewSelectionPanel.add(cbRadians);
viewSelectionPanel.add(cbGrads);

//checkbox

cbInv = new Checkbox(Inv );
cbInv.setState(false);
cbInv.addItemListener(this);

cbHyp = new Checkbox(Hyp );
cbHyp.setState(false);
cbHyp.addItemListener(this);

subPanel1.add(cbInv);subPanel1.add(cbHyp);
subPanel1.setLayout(new FlowLayout(0));// button in subPanel2btnBackSpace = new Button(BackSpace);
btnBackSpace.setForeground(Color.red);
subPanel2.add(btnBackSpace);

btnCE = new Button( CE );
btnCE.setForeground(Color.red);
subPanel2.add(btnCE);

btnC = new Button( C );
btnC.setForeground(Color.red);
subPanel2.add(btnC);
subPanel2.setLayout(new FlowLayout(2));

//button in subPanel3

subPanel3.setLayout(new GridLayout(5,5));

btnSta = new Button(Sta);
btnSta.setForeground(Color.blue);
btnFE = new Button(F-E);
btnFE.setForeground(Color.PINK);
btnOpen = new Button(();
btnOpen.setForeground(Color.PINK);
btnClose = new Button());
btnClose.setForeground(Color.PINK);
btnMC = new Button(MC);
btnMC.setForeground(Color.red);
btnAve = new Button(Ave);
btnAve.setEnabled(false);
btndms = new Button(dms);
btndms.setForeground(Color.PINK);
btnExp = new Button(Exp);
btnExp.setForeground(Color.PINK);
btnln = new Button(ln);
btnln.setForeground(Color.PINK);
btnMR = new Button(MR);
btnMR.setForeground(Color.red);
btnSum = new Button(Sum);
btnSum.setEnabled(false);
btnsin = new Button(sin);
btnsin.setForeground(Color.PINK);
btnxbyy = new Button(x^y);
btnxbyy.setForeground(Color.PINK);
btnlog = new Button(log);
btnlog.setForeground(Color.PINK);
btnMS = new Button(MS);
btnMS.setForeground(Color.red);
btns = new Button(s);
btns.setEnabled(false);
btncos = new Button(cos);
btncos.setForeground(Color.PINK);
btnxby3 = new Button(x^3);
btnxby3.setForeground(Color.PINK);
btnfac = new Button(n!);
btnfac.setForeground(Color.PINK);
btnMPlus = new Button(M+);
btnMPlus.setForeground(Color.red);
btnDat = new Button(Dat);
btnDat.setEnabled(false);
btntan = new Button(tan);
btntan.setForeground(Color.PINK);
btnxby2 = new Button(x^2);
btnxby2.setForeground(Color.PINK);
btnDevideX = new Button(1/x);
btnDevideX.setForeground(Color.PINK);
btnpi = new Button(pi);
btnpi.setForeground(Color.blue);

subPanel3.add(btnSta);subPanel3.add(btnFE);subPanel3.add(btnOpen);
subPanel3.add(btnClose);subPanel3.add(btnMC);subPanel3.add(btnAve);
subPanel3.add(btndms);subPanel3.add(btnExp);subPanel3.add(btnln);
subPanel3.add(btnMR);subPanel3.add(btnSum);subPanel3.add(btnsin);
subPanel3.add(btnxbyy);subPanel3.add(btnlog);subPanel3.add(btnMS);
subPanel3.add(btns);subPanel3.add(btncos);subPanel3.add(btnxby3);
subPanel3.add(btnfac);subPanel3.add(btnMPlus);subPanel3.add(btnDat);
subPanel3.add(btntan);subPanel3.add(btnxby2);subPanel3.add(btnDevideX);
subPanel3.add(btnpi);

// button
subPanel4.setLayout(new GridLayout(5,6));
Button btn1 = new Button(1);
btn1.setForeground(Color.blue);
Button btn2 = new Button(2);
btn2.setForeground(Color.blue);
Button btn3 = new Button(3);
btn3.setForeground(Color.blue);
Button btn4 = new Button(4);
btn4.setForeground(Color.blue);
Button btn5 = new Button(5);
btn5.setForeground(Color.blue);
Button btn6 = new Button(6);
btn6.setForeground(Color.blue);
Button btn7 = new Button(7);
btn7.setForeground(Color.blue);
Button btn8 = new Button(8);
btn8.setForeground(Color.blue);
Button btn9 = new Button(9);
btn9.setForeground(Color.blue);
Button btn0 = new Button(0);
btn0.setForeground(Color.blue);

//숫자 입력
btn1.addActionListener(this);
btn2.addActionListener(this);
btn3.addActionListener(this);
btn4.addActionListener(this);
btn5.addActionListener(this);
btn6.addActionListener(this);
btn7.addActionListener(this);
btn8.addActionListener(this);
btn9.addActionListener(this);
btn0.addActionListener(this);

Button btnPorM = new Button(+/-);
btnPorM.setForeground(Color.blue);
Button btnPoint = new Button(.);
btnPoint.setForeground(Color.blue);

Button btndevide = new Button(/);
btndevide.setForeground(Color.red);
Button btnMod = new Button(Mod);
btnMod.setForeground(Color.red);
Button btnAnd = new Button(And);
btnAnd.setForeground(Color.red);
Button btnMulti = new Button(*);
btnMulti.setForeground(Color.red);
Button btnOr = new Button(Or);
btnOr.setForeground(Color.red);
Button btnXor = new Button(Xor);
btnXor.setForeground(Color.red);
Button btnMinus = new Button(Minus);
btnMinus.setForeground(Color.red);
Button btnLsh = new Button(Lsh);
btnLsh.setForeground(Color.red);
Button btnNot = new Button(Not);
btnNot.setForeground(Color.red);
Button btnPlus = new Button(+);
btnPlus.setForeground(Color.red);
Button btnResult = new Button(=utton(=);
btnResult.setForeground(Color.red);
Button btnInt = new Button(Int);
btnInt.setForeground(Color.red);
Button btnAA = new Button(A);
btnAA.setEnabled(false);
Button btnBB = new Button(B);
btnBB.setEnabled(false);
Button btnCC = new Button(C);
btnCC.setEnabled(false);
Button btnDD = new Button(D);
btnDD.setEnabled(false);
Button btnEE = new Button(E);
btnEE.setEnabled(false);
Button btnFF = new Button(F);
btnFF.setEnabled(false);

subPanel4.add(btn7);subPanel4.add(btn8);subPanel4.add(btn9);
subPanel4.add(btndevide);subPanel4.add(btnMod);subPanel4.add(btnAnd);
subPanel4.add(btn4);subPanel4.add(btn5);subPanel4.add(btn6);
subPanel4.add(btnMulti);subPanel4.add(btnOr);subPanel4.add(btnXor);
subPanel4.add(btn1);subPanel4.add(btn2);subPanel4.add(btn3);
subPanel4.add(btnMinus);subPanel4.add(btnLsh);subPanel4.add(btnNot);
subPanel4.add(btn0);subPanel4.add(btnPorM);subPanel4.add(btnPoint);
subPanel4.add(btnPlus);subPanel4.add(btnResult);subPanel4.add(btnInt);
subPanel4.add(btnAA);subPanel4.add(btnBB);subPanel4.add(btnCC);
subPanel4.add(btnDD);subPanel4.add(btnEE);subPanel4.add(btnFF);

//계산기 정보 보기

dlgInfo = new Dialog(this);
dlgInfo.setResizable(false);
ver_Info = new Label(계산기 버젼 : 1.0);
name_Info = new Label(만 든 이 : 이 준);
ID_Info = new Label(학번 : 012481);
Button btnok = new Button(확 인);
btnok.addActionListener(this);
dlgInfo.add(ver_Info);
dlgInfo.add(name_Info);
dlgInfo.add(ID_Info);
dlgInfo.add(btnok);
dlgInfo.setTitle(계산기 정보);
dlgInfo.setBounds(150,150,220,150);
dlgInfo.setLayout(new GridLayout(4,1));

// 프레임 초기화
addWindowListener(new WinCloser());
setTitle(계산기 S012481);
setBounds(100, 100, 560, 300);
setVisible(true);

}

public void actionPerformed(ActionEvent ae){
Object obj = new Object();
obj = ae.getSource();

if(obj == btn1 || obj == btn2 || obj == btn3 || obj == btn4 ||
obj == btn5 || obj == btn6 || obj == btn7 || obj == btn8 ||
obj == btn9 || obj == btn0)
{
str = 1;
printNum(str);
}

if(ae.getActionCommand().equals(계산기 정보))
dlgInfo.setVisible(true);
if(ae.getActionCommand().equals(확 인))
dlgInfo.setVisible(false);
}
private void printNum(String n) {
//String str = resultScreen.getText();
resultScreen.setText(n);
}}

신청하기





COMMENT

댓글을 입력해주세요. 비속어와 욕설은 삼가해주세요.

번호 제 목 글쓴이 날짜
2699380 메뉴가 계단식으로 나타나요.. ㅠ.ㅠ (5) 스릉흔다 2025-06-25
2699354 영문 웹폰트 관련 질문입니다!!! (1) 치킨마루 2025-06-25
2699329 윈도우 미디어 플레이어 URL 질문!!! (1) 제철 2025-06-25
2699296 동영상 배경 질문드려요!!!!!!!!!!!!!! 핫파랑 2025-06-24
2699214 position:fixed 에 대한 질문입니다.. (7) 사이 2025-06-24
2699183 제이쿼리 이미지 슬라이드 위치값 수정 초엘 2025-06-23
2699153 테마[ADORABLE]에서 페이지생성시 하위페이지는 2개밖에 안되나요? 흰여울 2025-06-23
2699129 네이버 블로그 또는 사이트의 글을 불러오기 갤원 2025-06-23
2699070 탭메뉴처럼 셀렉트 박스를 이용해서 내용을 출력할 수 있는 방법이 있을까요. (3) 큰꽃늘 2025-06-22
2699016 인터넷이 안되는 환경에서 validator설치방법 (3) 은송이 2025-06-22
2698988 대체 C++ 6.0 exe 아이콘은 어떻게 넣는건가요? 외국녀 2025-06-22
2698960 음성파일을 embed로 작업했는데..웹 표준코딩으로 변경하려면 어떻게 해야하나요? (1) 잎새 2025-06-21
2698932 메뉴목록 풍선창 만들기 html (2) 하늘이 2025-06-21
2698901 http://www.zeitgeistbot.com/ 이 사이트처럼 움직이는 효과를 무엇이라고 하나요? 누림 2025-06-21
2698876 table width값 크로스브라우징에 대한 문의 (2) 볼수록매력 2025-06-21
2698849 c언어 질문. (3) 아름나 2025-06-20
2698823 setInterval 이벤트 제거 하려면... 가온길 2025-06-20
2698796 이 오류를 이해를 못하겠어요 Addicted 2025-06-20
2698712 IF 문 이 계속 오류가 나요 (2) 옆집오빠야 2025-06-19
2698687 이미지를 클릭하면 그 이미지를 다운받게해주는 방법 질문요 ^^ (미해결) (5) 해지개 2025-06-19
<<  이전  1 2 3 4 5 6 7 8 9 10  다음  >>

수다닷컴 | 여러분과 함께하는 수다토크 커뮤니티 수다닷컴에 오신것을 환영합니다.
사업자등록번호 : 117-07-92748 상호 : 진달래여행사 대표자 : 명현재 서울시 강서구 방화동 890번지 푸르지오 107동 306호
copyright 2011 게시글 삭제 및 기타 문의 : clairacademy@naver.com