-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path67_JColorChooser
More file actions
52 lines (41 loc) · 1.26 KB
/
67_JColorChooser
File metadata and controls
52 lines (41 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<Man.java>
// JColorChooser = A GUI mechanism that let's a user choose a color
public class Main {
public static void main(String[] args) {
new MyFram();
}
}
<MyFram.java>
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
public class MyFram extends JFrame implements ActionListener {
JButton button;
JLabel label;
MyFram(){
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new FlowLayout());
button = new JButton("Pick a color");
button.addActionListener(this);
label = new JLabel();
label.setBackground(Color.white);
label.setText("This is some text:D");
label.setFont(new Font("MV Boli",Font.PLAIN,100))
label.setOpaque(true);
this.add(button);
this.add(label);
this.pack();
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource()==button){
JColorChooser colorChooser = new JColorChooser();
Color color = JColorChooser.showDialog(null, "Pick a color...I guess", color.black);
//label.setForeground(color);
//label.setBackgound(color);
}
}
}