공학용 계산기입니다....
사랑은아픔
옆에 주석좀 달아주시면 감사하겠습니다.정말 부탁드리겠습니다.....인생이걸려있습니다...
import java.awt.*;import java.awt.event.*; // 이벤트 관련import javax.swing.*;import javax.swing.border.*;class CalculatorExam2 extends JFrame implements ActionL ActionListener{ BevelBorder be=new BevelBorder(BevelBorder.LOWERED); EtchedBorder eb=new EtchedBorder(EtchedBorder.RAISED); CheckboxGroup g=new CheckboxGroup(); Checkbox ch1=new Checkbox(Hex,false,g); Checkbox ch2=new Checkbox(Dec,false,g); Checkbox ch3=new Checkbox(Oct,false,g); Checkbox ch4=new Checkbox(Bin,false,g); CheckboxGroup g1=new CheckboxGroup(); Checkbox ch5=new Checkbox(Degrees,false,g1); Checkbox ch6=new Checkbox(Radians,false,g1); Checkbox ch7=new Checkbox(Grads,false,g1); Checkbox c1=new Checkbox(Inv); Checkbox c2=new Checkbox(Hyp); JTextField t1=new JTextField(); JTextField t2=new JTextField(); JTextField t3=new JTextField(); JButton b1=new JButton(Backspace); JButton b2=new JButton(CE); JButton b3=new JButton(C);
JButton be1=new JButton(Sta); JButton be2=new JButton(Ave); JButton be3=new JButton(Sum); JButton be4=new JButton(s); JButton be5=new JButton(Dat); JButton bw1=new JButton(MC); JButton bw2=new JButton(MR); JButton bw3=new JButton(MS); JButton bw4=new JButton(M+); JButton bw5=new JButton(pi);
JPanel wgrid1=new JPanel(new GridLayout(1,4)); JPanel wgrid2=new JPanel(new GridLayout(1,2)); Panel wgrid3=new Panel(new GridLayout(1,2)); Panel wgrid4=new Panel(new GridLayout(1,2)); Panel wgrid5=new Panel(new GridLayout(2,1)); Panel bwgrid1=new Panel(new GridLayout(5,1,5,5)); Panel bwgrid2=new Panel(new GridLayout(5,3,5,5)); Panel bwgrid3=new Panel(new GridLayout(5,1,10,5)); JPanel egrid1=new JPanel(new GridLayout(1,3,10,5)); Panel flow1=new Panel(new GridLayout(1,3,5,0)); Panel egrid2=new Panel(new GridLayout(2,1)); Panel egrid3=new Panel(new GridLayout(5,6,5,5));
Panel allgrid=new Panel(new GridLayout(1,2,5,5));
Panel bor1=new Panel(new BorderLayout(5,5)); Panel wbor2=new Panel(new BorderLayout(5,5)); Panel ebor3=new Panel(new BorderLayout(5,5)); Panel bor2=new Panel(new BorderLayout(5,5)); Panel ppp=new Panel(new GridLayout(2,1));
JButton bu1[] = new JButton[30]; JButton b [] = new JButton[15]; String s1[]={7,8,9,/,Mod,And,4,5,6,*,Or,Xor,1,2,3,-,Lsh,Not,0,+/-,.,+,=,Int,A,B,C,D,E,F,}; String s[]={F-E,(,),dms,Exp,In,sin,x^y,log,cos,x^3,n!,tan,x^2,1/x};
JMenu m=new JMenu(편집(E)); JMenu m1=new JMenu(보기(V)); JMenu m2=new JMenu(도움말(H)); JMenuItem copy=new JMenuItem(복사(C)); JMenuItem menu=new JMenuItem(붙여넣기(P)); JMenuItem helplist=new JMenuItem(도움말 항목(H)); JMenuItem calcul=new JMenuItem(계산기 정보(A)); JMenuItem 일반용=new JMenuItem(일반용(T)); JMenuItem 공학용=new JMenuItem(공학용(S)); JMenuItem Hex=new JMenuItem(Hex(H)); JMenuItem Decimal=new JMenuItem(Decimal(D)); JMenuItem Octal=new JMenuItem(Octal(O)); JMenuItem Binary=new JMenuItem(Binary(B)); JMenuItem Degrees=new JMenuItem(Degrees(E)); JMenuItem Radians=new JMenuItem(Radians(R)); JMenuItem Grads=new JMenuItem(Grads(G)); JMenuItem 자릿수구분=new JMenuItem(자릿수 구분 단위(I)); JMenuBar bar=new JMenuBar(); public CalculatorExam2(){ super(공학용계산기); setSize(780,300); //스크린의 사이즈를 가져오기 Toolkit tk = super.getToolkit(); Dimension d = tk.getScreenSize(); int screenWidth=(int)d.getWidth(); int screenHeight=(int)d.getHeight();
//JFrame 사이즈 가져오기ㅣ int width=super.getWidth(); int height=super.getHeight(); //JFrame 정가운 데 놓기위해 공식!! int x=(screenWidth - width)/2; int y=(screenHeight - height )/2; setLocation(x, y);
//메뉴 (편집) m.add(copy);//복사 m.add(menu);//붙여넣기 m1.add(일반용);//일반용 m1.add(공학용);//공학용 m1.add(Hex);//HEX m1.add(Decimal);//Decimal m1.add(Octal);//Octal m1.add(Binary);//Binary m1.addSeparator();//라인넣기 m1.add(Degrees); m1.add(Radians); m1.add(Grads); m1.addSeparator(); m1.add(자릿수구분);
//메뉴 (도움말) m2.add(helplist);//도움말 항목 m2.addSeparator();//라인넣기 m2.add(calcul);//계산기 정보 t3.setHorizontalAlignment(JTextField.RIGHT);//t3의 Hoirzontal을 right로 왼쪽으로 민다 egrid1.setBorder(eb);//border사용 테두리 wgrid1.setBorder(eb);//border사용 테두리 wgrid2.setBorder(eb);//border사용 테두리 t1.setBorder(be);//border사용 입체감 t2.setBorder(be);//border사용 입체감
add(t3,North);//t3을 상위로 넣는다 //1행4열의 GridLayout wgrid1.add(ch1); wgrid1.add(ch2); wgrid1.add(ch3); wgrid1.add(ch4); //wgrid1를 wgrid5에 넣는다 wgrid5.add(wgrid1);
//Inv,Hyp를 wgrid2에 넣는다 wgrid2.add(c1); wgrid2.add(c2);
ppp.add(bor2); ppp.add(egrid3);
wgrid3.add(t1); wgrid3.add(t2);
wgrid4.add(wgrid2); wgrid4.add(wgrid3); wgrid5.add(wgrid4);
wbor2.add(wgrid5,North);
allgrid.add(wbor2);
bor2.add(bwgrid2,Center);
bwgrid1.add(be1); bbwgrid1.add(be2); bwgrid1.add(be3); bwgrid1.add(be4); bwgrid1.add(be5);
bor2.add(bwgrid1,West);
bwgrid3.add(bw1); bwgrid3.add(bw2); bwgrid3.add(bw3); bwgrid3.add(bw4); bwgrid3.add(bw5);
bor2.add(bwgrid3,East);
wbor2.add(bor2,Center);
egrid1.add(ch5); egrid1.add(ch6); egrid1.add(ch7);
flow1.add(b1); flow1.add(b2); flow1.add(b3);
egrid2.add(egrid1); egrid2.add(flow1); ebor3.add(egrid2,North); ebor3.add(egrid3,Center);
allgrid.add(ebor3);
//border를 쓴 t1,t2,t3의 배경색 바꾸기 t1.setBackground(new Color(220,220,220)); t2.setBackground(new Color(220,220,220)); t3.setBackground(new Color(255,255,255)); //버튼의 글씨색 변경 b1.setForeground(Color.red); b2.setForeground(Color.red); b3.setForeground(Color.red);
//버튼 등록 및 글씨색 변경 for(int i=0;ib.length;i++){ b[i]=new JButton(s[i]); bwgrid2.add(b[i]); b[i].setForeground(Color.red); } // 버튼 등록 및 비활성화 for(int i=0;ibu1.length;i++){ bu1[i]=new JButton(s1[i]); egrid3.add(bu1[i]); } for(int i=24;ibu1.length;i++){ bu1[i].setEnabled(false); } //버튼 비활성화 be2.setEnabled(false); be3.setEnabled(false); be4.setEnabled(false); be5.setEnabled(false); //버튼들의 글씨색 변경 be1.setForeground(Color.blue); bw5.setForeground(Color.blue); bw1.setForeground(Color.red); bw2.setForeground(Color.red); bw3.setForeground(Color.red); bw4.setForeground(Color.red); bu1[0].setForeground(Color.blue); bu1[1].setForeground(Color.blue); bu1[2].setForeground(Color.blue); bu1[6].setForeground(Color.blue); bu1[7].setForeground(Color.blue); bu1[8].setForeground(Color.blue); bu1[12].setForeground(Color.blue); bu1[13].setForeground(Color.blue); bu1[14].setForeground(Color.blue); bu1[18].setForeground(Color.blue); bu1[19].setForeground(Color.blue); bu1[20].setForeground(Color.blue); bu1[3].setForeground(Color.red); bu1[4].setForeground(Color.red); bu1[5].setForeground(Color.red); bu1[9].setForeground(Color.red); bu1[10].setForeground(Color.red); bu1[11].setForeground(Color.red); bu1[15].setForeground(Color.red); bu1[16].su1[16].setForeground(Color.red); bu1[17].setForeground(Color.red); bu1[21].setForeground(Color.red); bu1[22].setForeground(Color.red); bu1[23].setForeground(Color.red); //메뉴바를 프레임에 붙인다 bar.add(m); bar.add(m1); bar.add(m2); //메뉴바 등록 setJMenuBar(bar);
add(allgrid,Center); //Frame의 배경색을 바꾼다 setBackground(new Color(240,240,240));
//ActionListener 등록~
bu1[18].addActionListener(this); bu1[12].addActionListener(this); bu1[13].addActionListener(this); bu1[14].addActionListener(this); bu1[6].addActionListener(this); bu1[7].addActionListener(this); bu1[8].addActionListener(this); bu1[0].addActionListener(this); bu1[1].addActionListener(this); bu1[2].addActionListener(this); bu1[20].addActionListener(this);//. b3.addActionListener(this);//c //JFrame 확실히 닫아주기위해서 super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //텍스트필드 조작금지 t3.setEditable(false); t1.setEditable(false); t2.setEditable(false); setVisible(true); setResizable(false); } //일반용 계산기 불러오기 public void ex(){ Calcul c = new Calcul(); }public void actionPerformed(ActionEvent e) { String ss = e.getActionCommand(); // 이벤트 발생 당시의 텍스트 필드 내용을 문자열 tt에 저장 String tt = t3.getText(); if(ss==e.getActionCommand()){ t3.setText(); } // 숫자나 dot이면 문자열 뒤에 붙인다 if ( ss == 0 || ss==1 || ss ==2 || ss == 3 || ss == 4 || ss==5 || ss ==6 || ss == 7 || ss == 8 || ss==9 || ss==.) { t3.setText( tt + ss ); }
// C이면 텍스트 필드의 내용을 지운다 if ( ss == C) { t3.setText(); }
} public static void main(String[] args) { CalculatorExam2 menu= new CalculatorExam2(); try{ UIManager.setLookAndFeel(com.sun.java.swing.plaf.windows.WindowsLookAndFeel); SwingUtilities.updateComponentTreeUI(menu); }catch(Exception e){ System.out.println(적용안됨); } }
}
-
예님
아해석이됫네요ㅎㅎ감사합니다
-
청력
예 내일 저녘까지 해드릴게요
근대 너무 쓸때없이 길게 나열하셨는대 한번에 묶어드려도 될까요? -
딸기맛사탕
친구가 도와달라고하는데 제가 능력이안되서요 ㅎㅎ
-
베레기
아 하다가 문득 생각났는대요 이거 혹시 학교과제나 학원 과제는 아니죠ㅎㅎ?
-
내꺼
지금 조금조금씩 해보고있는대 잼있내요.ㅎㅎ
-
일본드립
감사합니다 부탁드리겟습니다.정말감사합니다.
-
유진깡
수요일까지는 어려울까요???ㅎㅎ
-
늘다
최대한 빨리 부탁드려도될까요???
언제까지 가능하신지 여쭤봐도될까요??ㅎㅎ -
날놓아줘
주석이랑
제가 이걸 나중에 어떤부분이 어떤거고 뭘써서 이렇게됬다는걸
설명해야하는데 부연설명좀 부탁드리겠습니다.....
어려우시면 주석만 부탁드리겠습니다.... -
연와인
자바신님 부탁드리겠습니다....지끔까지 생각해봤는데
이해가 잘되질않네요.....
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2701285 | 아이폰이나 안드로이드 폰 인터넷으로 볼때 | 배꽃 | 2025-07-12 |
2701230 | 테마 설정하면 밑에 뜨는 글 삭제 (1) | 창의적 | 2025-07-12 |
2701177 | css적용이 안되요~ (6) | 다니엘 | 2025-07-11 |
2701151 | 사이트작업시 inputbox 가 readonly 형태표시 어떻게 하시나요? (1) | 찬내 | 2025-07-11 |
2701123 | 간단한 select 질문입니다 (3) | 천사의눈물 | 2025-07-11 |
2701061 | 비베질문.. | 똘끼 | 2025-07-10 |
2701034 | 메일폼 내 script 삽입가능한 방법 없을까요.. (2) | 마음새 | 2025-07-10 |
2701008 | 분명히 버튼을 만들었는데 액션이 안걸립니다. (3) | 재찬 | 2025-07-10 |
2700923 | 전체중앙정렬&독타입&쿼크모드 ㅜㅠ (8) | 푸른들 | 2025-07-09 |
2700893 | 질문드리겠습니다. | 도도한 | 2025-07-09 |
2700793 | 무비클립에 마우스 오버시 랜덤으로 효과음 나기는 어떻게 ;; (1) | 바닐라 | 2025-07-08 |
2700741 | 웹전송? (2) | 연와인 | 2025-07-07 |
2700686 | 카테고리 호버시 세부카테고리 보이게하는 것, css로만 가능할까요?? (3) | 다힘 | 2025-07-07 |
2700658 | 메타태그 질문드립니다..ㅠㅠ;;; | 모해 | 2025-07-07 |
2700632 | 외부에서 이미지 파일을 불러와야 합니다. 도와주세요. (4) | 에일린 | 2025-07-06 |
2700579 | (air + as3) smtp 이용해서 첨부파일 포함해서 메일 보내기 | 물보라 | 2025-07-06 |
2700524 | 클릭시 밑에 메뉴 나오게 (4) | 새솔 | 2025-07-05 |
2700505 | activex를 비쥬얼6.0으로 만들었는데요 비스타 배포시에 안되서 질문드립니다 (3) | 참이 | 2025-07-05 |
2700452 | c언어에서... 자료형 구분.... (3) | 시내 | 2025-07-05 |
2700422 | 버전에 관해 질문 | 라온제나 | 2025-07-04 |