import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ColorChooser01 { private JFrame frame = new JFrame("色の選択"); private JPanel pane = (JPanel)frame.getContentPane(); private JButton button = new JButton("色の選択"); private Color color = Color.BLUE; private Canvas canvas = new Canvas(){ @Override public void paint(Graphics g){ g.setColor(color); g.fillRect(100, 150, 200, 100); } }; public ColorChooser01(){ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); button.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent ev){ color = JColorChooser.showDialog(button, "色を選択して下さい", Color.WHITE); canvas.repaint(); } }); pane.add(button, BorderLayout.NORTH); canvas.setBackground(Color.WHITE); canvas.setSize(400, 400); pane.add(canvas, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); } public static void main(String[] args){ G106WinLF.set(); new ColorChooser01(); } }