inkedmn
07-06-2002, 05:00 PM
it's pretty basic, just opens a dialog with one button that opens a color chooser which allows you to change the button's color...
w00t!
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class GuiAttempt extends JPanel{
private JButton button1 = new JButton("Colors");
public GuiAttempt(){
buildUI();
buildListeners();
}
private void buildUI() {
this.setLayout(new GridLayout(1,1));
add(button1);
}
private void buildListeners() {
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
doStuff();
}
});
}
private void doStuff() {
Color pickColor = button1.getBackground();
pickColor = JColorChooser.showDialog(this,"Pick a color", pickColor);
button1.setBackground(pickColor);
}
public static void main(String [] args) {
int myHeight = 150;
int myWidth = 150;
JFrame theFrame = new JFrame("Color Chooser");
GuiAttempt thePanel = new GuiAttempt();
Container contentPane = theFrame.getContentPane();
contentPane.add(thePanel);
theFrame.setSize(150, 150);
Toolkit toolkit = theFrame.getToolkit();
Dimension screenSize = toolkit.getScreenSize();
Dimension frameSize = theFrame.getSize();
int newX = (int)((screenSize.width / 2) - (frameSize.width / 2));
int newY = (int)((screenSize.height / 2) - (frameSize.height / 2));
theFrame.setLocation(newX, newY);
theFrame.setVisible(true);
theFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
w00t!
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class GuiAttempt extends JPanel{
private JButton button1 = new JButton("Colors");
public GuiAttempt(){
buildUI();
buildListeners();
}
private void buildUI() {
this.setLayout(new GridLayout(1,1));
add(button1);
}
private void buildListeners() {
button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
doStuff();
}
});
}
private void doStuff() {
Color pickColor = button1.getBackground();
pickColor = JColorChooser.showDialog(this,"Pick a color", pickColor);
button1.setBackground(pickColor);
}
public static void main(String [] args) {
int myHeight = 150;
int myWidth = 150;
JFrame theFrame = new JFrame("Color Chooser");
GuiAttempt thePanel = new GuiAttempt();
Container contentPane = theFrame.getContentPane();
contentPane.add(thePanel);
theFrame.setSize(150, 150);
Toolkit toolkit = theFrame.getToolkit();
Dimension screenSize = toolkit.getScreenSize();
Dimension frameSize = theFrame.getSize();
int newX = (int)((screenSize.width / 2) - (frameSize.width / 2));
int newY = (int)((screenSize.height / 2) - (frameSize.height / 2));
theFrame.setLocation(newX, newY);
theFrame.setVisible(true);
theFrame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}