awt 하다가 막히네요..
빛솔
빨 주 노 초 파 남 보 라고 있는거를 클릭하면 위에 있는 색깔을 바꾸려고 하는데 잘 안되네요...
색깔부분은 그림으로 표현했습니다. 네모 상자를 그리고 빨간색으로 채우고.....버튼을 클릭하면빨 이벤튼지, 주 이벤튼지, 노 이벤튼지를 판단해서 색깔을 넣을 려고 하는데
잘 모르겠네요...
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Aw implements ActionListener{
JFrame frame;
Panel buttons;
Button bbal,ju,no,cho,pa,nam,bo;
public static void main(String ar[]){
Aw a=new Aw();
a.go();
}
public void go(){
frame= new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
buttons=new Panel();
buttons.setLayout(new FlowLayout());
bbal=new Button(빨);
ju=new Button(주);
no=new Button(노);
cho=new Button(초);
pa=new Button(파);
nam=new Button(남);
bo=new Button(보);
bbal.addActionListener(this);
ju.addActionListener(this);
no.addActionListener(this);
cho.addActionListener(this);
pa.addActionListener(this);
nam.addActionListener(this);
bo.addActionListener(this);
buttons.add(bbal);
buttons.add(ju);
buttons.add(no);
buttons.add(cho);
buttons.add(pa);
buttons.add(nam);
buttons.add(bo);
Painting paint =new Painting();
frame.getContentPane().add(BorderLayout.SOUTH,buttons);
frame.getContentPane().add(BorderLayout.CENTER,paint);
frame.setSize(600,600);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent event){
if(event.getSource()==bbal){}
if(event.getSource()==ju){
}
if(event.getSource()==no){
}
if(event.getSource()==cho){ }
if(event.getSource()==pa){
}
if(event.getSource()==nam){
}
if(event.getSource()==bo){
}
}}
class Painting extends JPanel{
public void paint(Graphics g){
g.setColor(Color.red);
g.fillRect(100, 100, 50, 50);
}
}
-
낶아
paint안에 red 색있죠?
그것을 변수로 지정해서 버튼 누를때마다 값을 바꿔주고
repaint();하면 됩니다.
번호 | 제 목 | 글쓴이 | 날짜 |
---|---|---|---|
2700452 | c언어에서... 자료형 구분.... (3) | 시내 | 2025-07-05 |
2700422 | 버전에 관해 질문 | 라온제나 | 2025-07-04 |
2700393 | mysql이 갑자기!!!!!!!!!!!!!!!에러가;; (2) | 소미 | 2025-07-04 |
2700359 | 3.0 ) SimpleButton 상태 강제 변경 (3) | 희선 | 2025-07-04 |
2700304 | ie8 전용핵 문의 (3) | 여자 | 2025-07-03 |
2700281 | 이런경우 어떻게 코딩해야 표준에 따르는건가요? (6) | 늘솜 | 2025-07-03 |
2700230 | 질문이여 ! | 뿡뿡몬 | 2025-07-03 |
2700205 | 액션스크립트책 좀 추천해주세요. (10) | 화이트캣 | 2025-07-02 |
2700173 | 자바 소스인데 어떤게 에러인지..? (1) | 호빵녀 | 2025-07-02 |
2700142 | 하단이 붙어있는 가변 레이아웃구조 질문드립니다. | 이플 | 2025-07-02 |
2700089 | 이미지를 사다리꼴로 비틀게 하는 액션코드가 있나요? (4) | 여름 | 2025-07-01 |
2700033 | 배경에 그라데이션을 넣으려고 하는데요.. (4) | 화이티 | 2025-07-01 |
2700005 | [질문] TextField 객체의 실제 높이 알아오는 방법 ? | 천사의눈물 | 2025-07-01 |
2699978 | FileReferenceList를 이용하여 업로드시 자꾸 실행속도가 느리다는 팝업이... (10) | 데이비드 | 2025-06-30 |
2699944 | 자바스크립트가 많은 사이트는... (6) | 희나리 | 2025-06-30 |
2699918 | 브라우저마다 다른 input과 텍스트 정렬 (3) | 늘봄 | 2025-06-30 |
2699887 | 동적텍스트를 그래픽으로?? (2) | 족장 | 2025-06-30 |
2699862 | scope넣기 (1) | 아인 | 2025-06-29 |
2699835 | exe로 만드는 방법을....알려주세요.. (5) | 방방 | 2025-06-29 |
2699809 | 롤오버할때 백그라운드 이미지로할때 alt설명은 어떻게해야하죠?..ㅠ (4) | 반혈 | 2025-06-29 |