디시인사이드 갤러리

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

갤러리 본문 영역

자바 그림판 소스 문제해결좀 해줘 횽들

에불레(119.149) 2009.06.17 15:50:01
조회 51 추천 0 댓글 1

자바 에플릿으로 만든 그림판인데
버튼은 제대로 나오는데 캔버스가 엉망이고 액션소스에도 문제가 있는것 같아
고수횽들 좀 도와줘 ㅜㅜ

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;

public class PaintTest extends java.applet.Applet
{
 Button buttonLine;
 Button buttonRect;
 Button buttonOval;
 Panel canvas;
 Button buttonRed;
 Button buttonBlue;
 Button buttonYellow;
 Button buttonGreen;
 Button buttonWhite;
 Button buttonBlack;

 int DRAW=0;

 Point p1,p2;   //좌료얻기위한 변수
 Graphics g;  //그리기수행하는 변수

 static Color color;

 public void init()
 {
  buttonLine = new Button("선");   //버튼생성
  add(buttonLine);
  buttonLine.setBounds(10, 10, 75, 30);   //버튼위치 지정
  

  buttonOval = new Button("원");
  add(buttonOval);
  buttonOval.setBounds(10, 50, 75, 30);

  buttonRect = new Button("사각형");
  add(buttonRect);
  buttonRect.setBounds(10, 90, 75, 30);

  buttonRed = new Button("Red");
  add(buttonRed);
  buttonRed.setBounds(10, 150, 30, 30);
  buttonRed.setBackground(Color.red);

  buttonBlue = new Button("Blue");
  add(buttonBlue);
  buttonBlue.setBounds(50, 150, 30, 30);
  buttonBlue.setBackground(Color.blue);
  
  buttonYellow = new Button("Yellow");
  add(buttonYellow);
  buttonYellow.setBounds(10, 190, 30, 30);
  buttonYellow.setBackground(Color.yellow);
  
  buttonGreen = new Button("Green");
  add(buttonGreen);
  buttonGreen.setBounds(50, 190, 30, 30);
  buttonGreen.setBackground(Color.green);
  
  buttonWhite = new Button("White");
  add(buttonWhite);
  buttonWhite.setBounds(10, 230, 30, 30);
  buttonWhite.setBackground(Color.white);
  
  buttonBlack = new Button("Black");
  add(buttonBlack);
  buttonBlack.setBounds(50, 230, 30, 30);
  buttonBlack.setBackground(Color.black);

  canvas = new Panel();
  canvas.setBounds(90,0,410,800);
  canvas.setBackground(Color.green);
  add(canvas);
 }
 
 public void drawLine(Color color)   //선그리기
  {
   g = canvas.getGraphics();
   g.setColor(color);
   g.drawLine((int)p1.getX(),(int)p1.getY(),(int)p2.getX(),(int)p2.getY());
  }
 
 public void drawRect(Color color)  //사각형그리기
  {
   g = canvas.getGraphics();
   g.setColor(color);
   g.drawRect((int)p1.getX(),(int)p1.getY(),(int)p2.getX()-(int)p1.getX(),(int)p2.getY()-(int)p1.getY());
  }
 
 public void drawOval(Color color)   //원그리기
 {
  g = canvas.getGraphics();
  g.setColor(color);
  g.drawOval((int)p1.getX(),(int)p1.getY(),(int)p2.getX()-(int)p1.getX(),(int)p2.getY()-(int)p1.getY());
 }
 
 public void mouseClicked(MouseEvent e) {} 
 public void mouseEntered(MouseEvent e) {}

 public void mouseExited(MouseEvent e) {}

 public void mousePressed(MouseEvent e)
 {
  p1=e.getPoint();
 }
 
 public void mouseReleased(MouseEvent e)
 {
  p2=e.getPoint();
  
  switch(DRAW)
    {
     case 1:drawLine(color);break;
     case 2:drawRect(color);break;
     case 3:drawOval(color);break;
    }
 }

/* public void actionPerformed(ActionEvent e)  //ActionListener 구현
 {
  if (e.getActionCommand().equals("선")) //선 버튼일 경우
  {
   DRAW=1;
  } else if (e.getActionCommand().equals("사각형")) //사각형 버튼일 경우
  {
   DRAW=2;
  } else if (e.getActionCommand().equals("원")) //원 버튼일 경우
  {
   DRAW=3;
     }

  if(e.getActionCommand().equals("Red"))
  {
   color = Color.red;
  } else if(e.getActionCommand().equals("Blue"))
  {
   color = Color.blue;
     } else if(e.getActionCommand().equals("Yellow"))
  {
   color = Color.yellow;
  } else if(e.getActionCommand().equals("Green"))
  {
   color = Color.green;
  } else if(e.getActionCommand().equals("White"))
  {
   color = Color.white;
  } else if(e.getActionCommand().equals("Black"))
  {
   color = Color.black;
  }
 }*/
}

추천 비추천

0

고정닉 0

0

댓글 영역

전체 댓글 0
등록순정렬 기준선택
본문 보기

하단 갤러리 리스트 영역

왼쪽 컨텐츠 영역

갤러리 리스트 영역

갤러리 리스트
번호 제목 글쓴이 작성일 조회 추천
설문 경제관념 부족해서 돈 막 쓸 것 같은 스타는? 운영자 24/05/13 - -
140925 손가인 갈수록 요염해지는 듯 [2] 이모군(110.8) 09.07.26 131 0
140924 void형 변수가 없다면, void동생 변수는 있나여? [11] 씬입사원1.7갤로그로 이동합니다. 09.07.26 135 0
140920 이 겔에선 누가 제일 잘나가냐? 씬입사원1.7갤로그로 이동합니다. 09.07.26 56 0
140918 프겔에서 누가 제일 잘나가냐? 유리한갤로그로 이동합니다. 09.07.26 63 0
140917 디씨 게시판 바뀌고 느려진거 같지 않음? [2] 두루미(218.238) 09.07.26 59 0
140916 프겔에서 누가 제일 잘나가냐? [7] ∫ 2t dt=t²+c갤로그로 이동합니다. 09.07.26 144 0
140914 형들 듀얼모니터 이상쓰면서 컴터 하루 12시간이상쓰는형들있나여?? [9] 탱킹갤로그로 이동합니다. 09.07.26 131 0
140912 님들하 ARM Eval보드는 Keil이 좋음or Stellaris가좋음? 우엠다(99.236) 09.07.26 33 0
140908 이거 좀 늅늅한 질문인데 자바스크립트(222.111) 09.07.26 54 0
140906 원 치킨 투 치킨 [3] DMW(123.111) 09.07.26 106 0
140905 템플릿 좆까 [3] Alkyl갤로그로 이동합니다. 09.07.26 119 0
140904 그러면 dat 파일을 exe 변환할수있는 방법 없나요 [4] aaasd(125.187) 09.07.26 97 0
140903 ㅠㅠ 아나 형들 도와줘 asrock 메인보드쓰는데 모르고 인텔용칩셋설치했 [1] 2(58.224) 09.07.26 64 0
140902 저기... dat 파일 exe 못바꾸나여? [2] aaasd(125.187) 09.07.26 91 0
140901 복권이라는게 말이야, 안될놈은 안되는거야. [1] 유리한갤로그로 이동합니다. 09.07.26 91 0
140900 무슨 세금이 이렇게 많은지... [7] 2년차(118.103) 09.07.26 183 0
140899 우분투 시냅틱 패키지 관리자 편하네요 [3] NaCl갤로그로 이동합니다. 09.07.26 124 0
140896 생각해봤는데 이렇게 하면 될 것 같아요. [5] ㅇㅇ(121.129) 09.07.26 113 0
140895 신입으로 들어가면 어느정도 수준 기대해? [4] 두루미(218.238) 09.07.26 268 0
140894 지금 리눅스 [3] NaCl갤로그로 이동합니다. 09.07.26 128 0
140892 호머나 보자능 [3] algorithm갤로그로 이동합니다. 09.07.26 99 0
140890 자전거 안장도둑 [1] 이모군(110.8) 09.07.26 154 0
140889 스택을 이용한 트리의 후위 순회??? [8] dipie갤로그로 이동합니다. 09.07.26 143 0
140888 친구녀석따라 요가 갔다 왔다느ㅇ [3] algorithm갤로그로 이동합니다. 09.07.26 126 0
140887 다들 제시카의 깜찍함은 보고 디씨질하나염? [4] Vita500갤로그로 이동합니다. 09.07.26 167 0
140886 아 공부하기도 좆나 힘드네. [2] ㅇㅇ(121.129) 09.07.26 102 0
140884 프갤에 로또하는 횽들 있나? [4] Q Lazzarus갤로그로 이동합니다. 09.07.26 97 0
140883 예전 군대서 쓰던 bcwipe 프로그램으로 지우면 복구 안됨? [10] 두루미(218.238) 09.07.26 621 0
140882 강제원격조정당했다;; [3] 웃대에서왔어요갤로그로 이동합니다. 09.07.26 195 0
140881 프로그래밍을 합시다 프로그래밍은 나에 원수 [1] 병신로봇갤로그로 이동합니다. 09.07.26 107 0
140880 이 짤의 출처 영화를 보고왔다는 ㅋㅋ [1] ㅇㅇ(112.149) 09.07.26 206 0
140877 디씨질을 접기로 했음. [3] JuEUS-U갤로그로 이동합니다. 09.07.26 161 0
140875 베두는 봅니다 [1] Vita500갤로그로 이동합니다. 09.07.26 138 0
140870 다들주무실려나..온김에 글싸고가야짐.. [5] 초밥술사갤로그로 이동합니다. 09.07.26 149 0
140869 아오 테트리스 ㅡㅡ [2] ㄱㄱ(121.138) 09.07.26 127 0
140868 휴지통이 이상합니다..도와주세요 [2] ㅁㅁ(121.124) 09.07.26 127 0
140867 프겔에서 누가 제일 잘 나가냐? [70] 베두갤로그로 이동합니다. 09.07.26 476 0
140862 적분 소환 [6] Alkyl갤로그로 이동합니다. 09.07.26 93 0
140859 스크립트언어의 한계가 뭐야? [2] 히밤리눅스갤로그로 이동합니다. 09.07.26 127 0
140858 OS과목 배울때 무슨언어로 배워? [6] (116.127) 09.07.26 201 0
140857 컴퓨터 사는데 좀 조언해주실분없나요 [8] street T(59.13) 09.07.26 156 0
140856 공비훃의 팩떡밥 [9] NaCl갤로그로 이동합니다. 09.07.26 155 0
140853 일본에서는 Cell 연구가 상당히 진행된 듯 [3] 분당살람갤로그로 이동합니다. 09.07.26 180 0
140852 어떤게 속도가 더 빠를까 [12] NaCl갤로그로 이동합니다. 09.07.26 194 0
140851 역시 동영상으로 공부를 해야하는걸까.. [7] 적이되고싶은가갤로그로 이동합니다. 09.07.25 128 0
140850 The Art of Multiprocessor Programming을 [3] Alkyl갤로그로 이동합니다. 09.07.25 101 0
140848 학교에서 전자공학과라고 하면 우~와~ 이런 반응인데.. [2] 삼학년갤로그로 이동합니다. 09.07.25 189 0
140847 주먹고기가 맛있구나. ㅇㅇ [3] Rei@디씨갤로그로 이동합니다. 09.07.25 121 0
140846 obsidium 1.3.0.4 언팩좀 [1] ㅈㄷㄹ(61.109) 09.07.25 129 0
140844 다차원배열 포인터연산 이제 별거 아냐 [1] 강c(118.218) 09.07.25 69 0
갤러리 내부 검색
제목+내용게시물 정렬 옵션

오른쪽 컨텐츠 영역

실시간 베스트

1/8

뉴스

디시미디어

디시이슈

1/2