import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class ColorChoice extends JFrame {
Container contentPane;
JLabel lbl = new JLabel("Color");
ColorChoice() {
setTitle("선택");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
contentPane = getContentPane();
lbl.setHorizontalAlignment(SwingConstants.CENTER);
lbl.setFont(new Font("fontname", Font.ITALIC, 30));
contentPane.add(lbl, BorderLayout.CENTER);
createMenu();
setSize(300,300);
setVisible(true);
}
void createMenu() {
JMenuBar manue = new JMenuBar();
JMenuItem colorMenuItem = new JMenuItem("Color");
JMenu fMnu = new JMenu("change");
colorMenuItem.addActionListener(new MenuActionListener());
fMnu.add(colorMenuItem);
manue.add(fMnu);
this.setJMenuBar(manue);
}
class MenuActionListener implements ActionListener {
JColorChooser choice = new JColorChooser();
public void actionPerformed(ActionEvent e) {
String cmd = e.getActionCommand();
if(cmd.equals("Color")) {
Color selctColor = choice.showDialog(null,"Color",Color.YELLOW);
if(selctColor != null)
lbl.setForeground(selctColor);
}
}
}
public static void main(String [] args) {
new ColorChoice();
}
}
간단하게 만든 색선택해서 바까주는 프로그램 입니다.~~
댓글