Sidewinder


World


FishMusic


LaughingBaby


Monday, June 30, 2008

java Button Test

자바 gui질문입니다


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

class ButtonPanel extends JPanel
implements ActionListener

//Button 생성
{ public ButtonPanel()
{ yellowButton = new JButton("Yellow");
blueButton = new JButton("Blue");
redButton = new JButton("Red");

add(yellowButton);
add(blueButton);
add(redButton);

yellowButton.addActionListener(this);
blueButton.addActionListener(this);
redButton.addActionListener(this);
}
//Event 처리
public void actionPerformed(ActionEvent evt)
{ Object source = evt.getSource();
Color color = getBackground();
if (source == yellowButton) color = Color.yellow;
else if (source == blueButton) color = Color.blue;
else if (source == redButton) color = Color.red;
setBackground(color);
repaint();
}

private JButton yellowButton;
private JButton blueButton;
private JButton redButton;
}


class ButtonFrame extends JFrame
{ public ButtonFrame()
{ setTitle("ButtonTest");
setSize(300, 200);
addWindowListener(new WindowAdapter()
{ public void windowClosing(WindowEvent e)
{ System.exit(0);
}
} );

Container contentPane = getContentPane();
contentPane.add(new ButtonPanel());
}


//} 이 부분 삭제 여기서 에러 납니다.
//public class ButtonTest
//{


public static void main(String[] args)
{ JFrame frame = new ButtonFrame();
frame.show();
}
}


//뭘 원하시는 건지 잘 모르겠습니다. 정확히 말해주시면 좋겠는데.
//쪽지 한번 주세요

No comments:

Post a Comment