Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class Peach extends JFrame{
- // Variables
- private JButton b;
- private Color color = Color.WHITE;
- private JPanel panel;
- // Constructor
- public Peach(){
- super("JFrame's title");
- panel = new JPanel();
- panel.setBackground(color);
- b = new JButton("Choose a color");
- b.addActionListener(
- new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- color = JColorChooser.showDialog(null, "Pick your color", color);
- if(color == null)
- color = Color.WHITE;
- panel.setBackground(color);
- }
- }
- );
- add(panel, BorderLayout.CENTER);
- add(b, BorderLayout.SOUTH);
- setSize(425, 150);
- setVisible(true);
- }
- // Main Function
- public static void main(String[] args){
- Peach p = new Peach();
- p.setDefaultCloseOperation(EXIT_ON_CLOSE);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement