Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package practice.pkg1;
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- class test extends JFrame{
- private JButton b;
- private Color color = (Color.BLACK);
- private JPanel panel;
- public test(){
- super("Choose Color");
- panel = new JPanel();
- panel.setBackground(color);
- b = new JButton("Choose a color : ");
- b.addActionListener(
- new ActionListener(){
- public void actionPerformed(ActionEvent e){
- color = JColorChooser.showDialog(null, "Pick your color",color);
- if(color == null)
- color = (Color.BLACK);
- panel.setBackground(color);
- }
- }
- );
- add(panel,BorderLayout.CENTER);
- add(b, BorderLayout.SOUTH);
- setSize(350,175);
- setVisible(true);
- }
- }
- public class Practice1{
- public static void main(String[] args) {
- test t = new test();
- t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement