디시인사이드 갤러리

갤러리 이슈박스, 최근방문 갤러리

갤러리 본문 영역

프갤러님드라 자바 이부분 막히는데 쪼끔만바죵

으으(220.149) 2010.11.26 10:52:33
조회 124 추천 0 댓글 10

29045835_1290512966.jpg 
저기 빨간부분을 추가해야되는데..

import java.awt.*; // AWT(Abstract Window Toolkit)을 사용하기 위하여 임포트한다
import javax.swing.*; // 그래픽구현시 swing을 사용하기 위하여 임포트한다
import java.awt.event.*; // 이벤트 객체를 사용하기 위하여 임포트한다
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
 

// 기본적으로 JFrame을 상속받으며, WindowListener와 ActionListener를

// implement함으로써 이벤트 객체를 활용한다

public class adx extends JFrame implements WindowListener,ActionListener{
// private TextField tf = null;
 private Panel tp = null;
 private Button bp = null;
 private JRadioButton Hex,Dec,Oct,Bin = null;
 Checkbox cb1,cb2;
 private Dimension dimen,dimen1;
 private int xpos, ypos, tot;

Button n7,n8,n9,n4,n5,n6,n1,n2,n3,n0,x1,x2,y1,y2,y3,y4,a1,a2,a3,a4,b1,b2,b3,b4,b5,w1,w2,w3,w4,w5,w6; // 계산기에 쓰일 각각의 버튼을 생성한다

Panel p1,p2; // 두개의 패널을 생성한다

TextField tf; // 계산기의 계산과정과 결과값을 처리할 텍스트필드를 생성한다

String str; //문자열을 입력받을 변수선언

long num,result; // 결과값을 저장할 변수선언

boolean ok,plus,minus,gob,nanut; // 이벤트를 수행할 boolean변수 선언

Container con; // 위에서 생성한 두개의 패널을 붙인 컨테이너선언

FlowLayout layout; // 정렬방식인 FlowLayout의 객체를 선언한다

 

public adx() // Design클래스의 생성자

{

super("계산기");

}
---------------------------------------요기서부터-----------------------------------------------------------
public void init() {
 setSize(254, 336);
 JPanel p = new JPanel();
 p.setLayout(null);
 
 dimen = Toolkit.getDefaultToolkit().getScreenSize();
 dimen1= this.getSize();
 xpos= (int)(dimen.getWidth()/2 - dimen1.getWidth()/2);
 ypos = (int)(dimen.getHeight()/2 - dimen1.getHeight()/2);
 this.setLocation(xpos, ypos);
 this.setVisible(true);

 tf = new TextField(25);
 tf.setEditable(false);

 tp = new Panel();
 tp.add(tf);
 tp.setVisible(true);

 bp = new ButtonPanel(tf);
 bp.setVisible(true);

 p.add(tf); p.add(bp);
 tf.setBounds(40,10,170,30);
 bp.setBounds(0,150,250,160);
 setVisible(true);

 cb1 = new Checkbox("Inv");
 cb2 = new Checkbox("Hyp");
 p.add(cb1);  p.add(cb2);
 cb1.setBounds(25,100,50,20);
 cb2.setBounds(75,100,50,20);

 Hex = new JRadioButton("Hex");
 Dec = new JRadioButton("Dec");
 Oct = new JRadioButton("Oct");
 Bin = new JRadioButton("Bin");
 p.add(Hex); p.add(Dec); p.add(Oct); p.add(Bin);
 Hex.setBounds(20,60,50,20);
 Dec.setBounds(70,60,50,20);
 Oct.setBounds(120,60,50,20);
 Bin.setBounds(170,60,50,20);

 add(p);
}
 ---------------------------------------이까지 퍼왓는데 코드가 안먹히네 머가문제일까 ㅠㅠ 안떠화면에---------------------------

public static void main(String args[]){

adx de = new adx(); // Design클래스의 객체 de를 생성한다

de.go(); // Design클래스의 객체 de의 멤버함수 go()를 실행한다

}

 

public void go(){

 

con = getContentPane();

con.setLayout(new BorderLayout());

// 컨테이너를 생성함과 동시에 컨테이너의 배경색을 노란색으로 하며

// 기본적인 정렬은 BorderLayout으로 한다

 

tf = new TextField("0",24); // 계산과정과 결과값을 나타낼 텍스트필드를 생성하며, 기본값은 0으로한다

 

layout = new FlowLayout(); //FlowLayout으로 초기화

p1 = new Panel(); // 첫번째 패널을 생성한다

p1.setLayout(layout); // 첫번째패널의 정렬방식은 위에서 선언한 FlowLayout으로 한다

 

p2 = new Panel(); // 두번째 패널을 생성한다다

p2.setLayout (new GridLayout(5,6,5,5));

// 두번째 패널의 정렬방식은 GridLayout이며, 4행4열로 정렬하며, 수평, 수직간격은 각각 5로 한다

 

p1.add(tf); // 위에서 생성한 텍스트박스의 객체를 패널1에 붙인다

layout.setAlignment(FlowLayout.CENTER); // FlowLayout.CENTER으로 배치

 

con.add(p1,BorderLayout.CENTER); // 패널1을 화면의 중앙에 오도록하여 컨테이너에 붙인다

con.add(p2,BorderLayout.SOUTH); // 패널2를 화면의 아랫쪽에 오도록하여 컨테이너에 붙인다

 

//////////////////////각각의 버튼을 설정///////////////////////////////////
w1 = new Button("");
w2 = new Button("");
w3 = new Button("");
w4 = new Button("Backspace");
w5 = new Button("CE");
x1 = new Button("C");
a1 = new Button("MC");
n7 = new Button("7");
n8 = new Button("8");
n9 = new Button("9");
y1 = new Button("/");
b1 = new Button("sqrt");
a2 = new Button("MR");
n4 = new Button("4");
n5 = new Button("5");
n6 = new Button("6");
y2 = new Button("*");
b2 = new Button("%");
a3 = new Button("MS");
n1 = new Button("1");
n2 = new Button("2");
n3 = new Button("3");
y3 = new Button("-");
b3 = new Button("1/x");
a4 = new Button("M+");
n0 = new Button("0");
x2 = new Button("+/-");
y4 = new Button(".");
b5 = new Button("+");
b4 = new Button("=");

///////////////////////////////////////////////////////////////////////////

 

//////////////////// 위에서 생성한 버튼을 패널2에다가 붙인다/////////////////////////
p2.add(w1);
p2.add(w2);
p2.add(w3);
p2.add(w4);
p2.add(w5);
p2.add(x1);
p2.add(a1);
p2.add(n7);
p2.add(n8);
p2.add(n9);
p2.add(y1);
p2.add(b1);
p2.add(a2);
p2.add(n4);
p2.add(n5);
p2.add(n6);
p2.add(y2);
p2.add(b2);
p2.add(a3);
p2.add(n1);
p2.add(n2);
p2.add(n3);
p2.add(y3);
p2.add(b3);
p2.add(a4);
p2.add(n0);
p2.add(x2);
p2.add(y4);
p2.add(b5);
p2.add(b4);

///////////////////////////////////////////////////////////////////////////

 

///////////////////// 각각의 버튼에 대한 색을 지정해준다///////////////////////////
w1.setForeground(Color.BLUE);
w2.setForeground(Color.BLUE);
w3.setForeground(Color.BLUE);
w4.setForeground(Color.RED);
w5.setForeground(Color.RED);
x1.setForeground(Color.RED);
a1.setForeground(Color.RED);
n7.setForeground(Color.BLUE);
n8.setForeground(Color.BLUE);
n9.setForeground(Color.BLUE);
y1.setForeground(Color.RED);
b1.setForeground(Color.BLUE);
a2.setForeground(Color.RED);
n4.setForeground(Color.BLUE);
n5.setForeground(Color.BLUE);
n6.setForeground(Color.BLUE);
y2.setForeground(Color.RED);
b2.setForeground(Color.BLUE);
a3.setForeground(Color.RED);
n1.setForeground(Color.BLUE);
n2.setForeground(Color.BLUE);
n3.setForeground(Color.BLUE);
y3.setForeground(Color.RED);
b3.setForeground(Color.BLUE);
a4.setForeground(Color.RED);
n0.setForeground(Color.BLUE);
x2.setForeground(Color.BLUE);
y4.setForeground(Color.BLUE);
b5.setForeground(Color.RED);
b4.setForeground(Color.RED);

 

//////////////////////////////////////////////////////////////////////////

 

/////////////////////// 윈도우리스너설정/////////////////////////////////////

addWindowListener(this);

n1.addActionListener(this);

n2.addActionListener(this);

n3.addActionListener(this);

n4.addActionListener(this);

n5.addActionListener(this);

n6.addActionListener(this);

n7.addActionListener(this);

n8.addActionListener(this);

n9.addActionListener(this);

n0.addActionListener(this);

b4.addActionListener(this);

b5.addActionListener(this);

y1.addActionListener(this);

y2.addActionListener(this);

y3.addActionListener(this);

b2.addActionListener(this);

x1.addActionListener(this);
/////////////////////////////////////////////////////////////////////////

 

///////////////////// 액션리스너설정////////////////////////////////////////

y4.addActionListener( new ButtonPlus() );

y3.addActionListener( new ButtonMinus() );

y2.addActionListener( new ButtonGob() );

y1.addActionListener( new ButtonNanut()) ;

////////////////////////////////////////////////////////////////////////

 

setSize(400,260);

setVisible(true);

}

 

// 플러스버튼이 눌러졌을 경우 puls = true

class ButtonPlus implements ActionListener {

public void actionPerformed(ActionEvent ae){

plus=true;

}

}

//마이너스버튼이 눌러졌을 경우 minus = true

class ButtonMinus implements ActionListener {

public void actionPerformed(ActionEvent ae){

minus=true;

}

}

//곱셈버튼이 눌러졌을 경우 gob = true

class ButtonGob implements ActionListener {

public void actionPerformed(ActionEvent ae){

gob=true;

}

}

//나눗셈버튼이 눌러졌을 경우 nanut = true

class ButtonNanut implements ActionListener {

public void actionPerformed(ActionEvent ae){

nanut=true;

}

}

 

 

public void actionPerformed(ActionEvent e){

String mmn = e.getActionCommand(); // 입력되어지는 값들을 문자열변수 mmn에 저장한다

if(mmn.equals("1")||mmn.equals("2")||mmn.equals("3")||mmn.equals("4")||mmn.equals("5")||mmn.equals("6")||mmn.equals("7")||mmn.equals("8")||mmn.equals("9")||mmn.equals("0")){

// 입력된 값이 숫자인지 확인하여 숫자일 경우 입력이 끝날때까지 입력받아서 str변수에 저장한다

if(str != null){str = str + mmn; }

 

else

{

str = mmn;

}

 

tf.setText(str); // 텍스트필드에 입력되는 값을 str에 저장한다

num = Long.parseLong(str); // str에 저장된 입력값을 정수값으로 변환하여 num값에 입력한다

 

}

 

//////////////////////////// 사칙연산을 수행하는 알고리즘////////////////////...

else if(mmn.equals("+")||mmn.equals("-")||mmn.equals("*")||mmn.equals("/")||mmn.equals("=")){

// 입력되는 값이 숫자가 아닌 사칙연산일 경우에는 입력된 값에 대하여 아래와 같이 사칙연산을 수행하여

// result값에 저장한다

if(result == 0){result=num;}

 

if(ok==true){

 

if(mmn.equals("+")){result = result + num;}

 

else if(mmn.equals("-")){result = result - num;}

 

else if(mmn.equals("*")){result = result * num;}

 

else if(mmn.equals("/")){result = result / num;}

 

else if(plus==true&&mmn.equals("=")){result = result + num;plus=false;}

 

else if(minus==true&&mmn.equals("=")){result = result - num;minus=false;}

 

else if(gob==true&&mmn.equals("=")){result = result * num;gob=false;}

 

else if(nanut==true&&mmn.equals("=")){result = result / num;nanut=false;}

 

str =""; str = new Long(result).toString();tf.setText(str);num=0;

}

 

ok=true;str="";

}

//////////////////////////////////////////////////////////////////////

 

 

else if(mmn.equals("C")){num=0;result=0;ok=false;str="";tf.setText(str);}}

// C버튼이 눌러질경우 num, result를 0으로 초기화하고 ok, str모두 처음값으로 초기화한다

 

///////////// 윈도우리스너를 implement했기때문에 선언해줘야 할부분 ///////////////////

public void windowClosing(WindowEvent e){System.exit(0);}

 

public void windowOpened(WindowEvent e) { }

 

public void windowIconified(WindowEvent e) { }

 

public void windowDeiconified(WindowEvent e) { }

 

public void windowClosed(WindowEvent e) { }

 

public void windowActivated(WindowEvent e) { }

 

public void windowDeactivated(WindowEvent e) { }

////////////////////////////////////////////////////////////////////////////////

}

 

추천 비추천

0

고정닉 0

0

댓글 영역

전체 댓글 0
본문 보기

하단 갤러리 리스트 영역

왼쪽 컨텐츠 영역

갤러리 리스트 영역

갤러리 리스트
번호 제목 글쓴이 작성일 조회 추천
설문 끝까지 다 본 걸 후회하게 만든 용두사미 드라마는? 운영자 25/07/07 - -
AD 휴대폰 바꿀까? 특가 구매 찬스! 운영자 25/07/02 - -
349727 ㅇㅇ형님 감사히 먹겠습니다. ㅇㅇ(211.234) 13.03.16 27 0
349724 ㅇㅇ님 피자 잘먹을게요 ㅠㅠ 인간(110.35) 13.03.16 34 0
349723 ㅇㅇ 형님 잘먹겟습니다 백이(182.214) 13.03.16 33 0
349722 성님 잘먹겠습니다 ㅇㅇ(61.98) 13.03.16 23 0
349719 ㅇㅇ 횽 잘먹겠습니다 DART(116.41) 13.03.16 43 0
349718 감사합니다 잘먹겠습니다 [1] 야간편돌이(175.116) 13.03.16 60 0
349715 @@@@@@@ 20130316 프갤 피자대첩 공휴일로 지정합니다 @@@@@@@@@@ [1] dd(1.214) 13.03.16 58 0
349714 급한일 있어서 먼저 나간다 피자는 잘받았어. 내일 11시꺼로 예약함 규식이(218.153) 13.03.16 33 0
349713 ㅇㅇ성님 싱글제한 깨달라는 꾸준놈좀 도와주세요 [1] @앱벌이갤로그로 이동합니다. 13.03.16 65 0
349712 ★★★★★★★ 앞으로 프갤에 글올릴때 이 짤방으로 올리세요 ★★★★★★★ dd(1.214) 13.03.16 58 1
349711 싱글게임의 제한을 깨뜨려 주실 분 구합니다 징기스칸4갤로그로 이동합니다. 13.03.16 27 0
349710 프갤은 대 ㅇㅇ시대를 맞이한다 백이(182.214) 13.03.16 36 0
349708 싱글게임의 제한을 깨뜨려 주실 분 구합니다. [2] 징기스칸4갤로그로 이동합니다. 13.03.16 69 0
349704 메일로 쿠폰 왔다 @앱벌이갤로그로 이동합니다. 13.03.16 33 0
349703 설마가 아니구... [9] ㅇㅇ(119.203) 13.03.16 119 0
349702 ★☆ㅇㅇ성님 차냥☆★★☆ㅇㅇ성님 차냥☆★★☆ㅇㅇ성님 차냥☆★★☆ㅇㅇ성님 차냥☆★★☆ㅇㅇ성님 차냥☆★★☆ㅇㅇ성님 차냥☆★★☆ㅇㅇ성님 차냥☆★★☆ㅇㅇ성님 차냥☆★★☆ㅇㅇ성님 차냥☆★★☆ㅇㅇ성님 차냥☆★★☆ㅇㅇ성님 차냥☆★ [1] dd(1.214) 13.03.16 36 1
349701 ㅇㅇ형 잘먹겠습니다♡ ㅁㄴㅇ(1.245) 13.03.16 25 0
349700 쿠폰 입력하는 방법좀 알려줘 ㅠㅠ 어디서 뭘 해야하는지 ㅠㅠ 규식이(218.153) 13.03.16 26 0
349699 이메일로 피자옴 [2] 백이(182.214) 13.03.16 48 0
349698 왔구나 왔어~~~ ㅁㄴㅇ(1.245) 13.03.16 30 0
349697 피자 이메일로 다시 보냈냐 ? 규식이(218.153) 13.03.16 31 0
349696 대충 이순서 맞지? [3] ㅇㅇ(61.98) 13.03.16 86 0
349695 그나저나 airwig 버로우탄거냐? [1] dd(1.214) 13.03.16 87 0
349694 ㅇㅇ 형이 다시 하나하나 보내 [4] ㅇㅇ(121.163) 13.03.16 91 0
349693 ㅋㅋㅋㅋ아 생각해보니 죤트웃기넼ㅋㅋㅋ [5] dd(1.214) 13.03.16 109 0
349691 두명한테 한개씩 보냈는데 버튼이 사라짐 ㅋㅋ [3] ㅇㅇ(119.203) 13.03.16 93 0
349690 성님 선착순 20명 들었는데 왜 안주세요 @앱벌이갤로그로 이동합니다. 13.03.16 35 0
349689 책상에 폰놓고 다시 공부팜ㅋㅋ [1] 야간편돌이(175.116) 13.03.16 50 0
349687 19개 받은 분 젤 아래 번호 가지시고 메일로 불러주세요 [8] ㅇㅇ(119.203) 13.03.16 133 0
349686 airwig 성님은 어디가심??? [3] ㅇㅇ(223.33) 13.03.16 111 0
349684 내가 피자 20판 받았는데 [3] ㅇㅇ(121.163) 13.03.16 81 0
349683 근데 이거 번호 갖고 있다고 되는게 아닐껄? [2] ㅇㅇ(119.203) 13.03.16 89 0
349682 피자 19판 코드번호 쏜다 ㄱㄱㄱㄱ [6] dd(1.214) 13.03.16 158 0
349681 내가 이래서 웹이 싫어 [10] ㅇㅇ(119.203) 13.03.16 178 0
349679 실시간프갤현상황 [1] 근성가이(211.237) 13.03.16 97 0
349678 어 나한테는 18개 날라옴 루비•‿•갤로그로 이동합니다. 13.03.16 91 0
349676 아싸피자! sh(24.244) 13.03.16 59 0
349675 지금 일어났는데 방법 없나요 [3] 에어로홍갤로그로 이동합니다. 13.03.16 56 0
349674 나한테 정확히 19판 왔는데 ? ㅇㅇ(121.163) 13.03.16 80 0
349673 ㅇㅇ형 피자 쿠폰 19개 보낼게요 그럼 되져 [10] dd(1.214) 13.03.16 141 0
349672 근성가이야 너가 이번사건 잘 요약 정리해봐라 [1] 규식이(218.153) 13.03.16 48 0
349671 지금 20판 받았다는 사람이 두명이야 [2] ㅇㅇ(61.98) 13.03.16 113 0
349670 아 이거 어떻게 할거야 나혼자 20판 다 못먹어.. [1] ㅇㅇ(121.163) 13.03.16 87 0
349669 피자 20판왔닼ㅋㅋㅋㅋ 으앜ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ [10] dd(1.214) 13.03.16 4554 8
349668 야 쿠폰으로 먹는 방법도 좀 알려줘봐라 규식이(218.153) 13.03.16 45 0
349667 VC한글 [2] 백이(182.214) 13.03.16 55 0
349665 ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ [18] dd(1.214) 13.03.16 175 0
349664 열심히하면 [1] ㅇㅇ(61.98) 13.03.16 59 0
349663 엌ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ 도미노피자 왤케많이옴ㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋㅋ [14] dd(1.214) 13.03.16 184 0
349662 피자왔다! [2] (168.126) 13.03.16 76 0
뉴스 고건한, 박지훈·배인혁과 한둥지…YY엔터테인먼트와 전속계약 디시트렌드 07.05
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

뉴스

디시미디어

디시이슈

1/2