请加我QQ:53112850,我加过你了,不过你当时没在线
/*
* ColorDemo.java
*
* Created on 2006年10月29日, 上午9:16
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
/**
*
* @author lbf
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ColorDemo extends JFrame implements ActionListener{
private JButton ok,exit;
private JLabel demo;
/** Creates a new instance of ColorDemo */
public ColorDemo() {
super("颜色选取DEMO");
initWindow();
}
private void initWindow(){
ok=new JButton("选择");
exit=new JButton("退出");
demo=new JLabel("这是样版字!!!",JLabel.CENTER);
demo.setFont(new Font("黑体",Font.BOLD,20));
JPanel jpButton=new JPanel();
this.getContentPane().add(jpButton,BorderLayout.SOUTH);
this.getContentPane().add(demo,BorderLayout.CENTER);
jpButton.add(ok);
jpButton.add(exit);
ok.addActionListener(this);
exit.addActionListener(this);
this.setSize(300,300);
this.setLocationRelativeTo(null);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent ae){
if(ae.getSource()==ok){
Color c=JColorChooser.showDialog(this,"请选择颜色",Color.BLUE);
if(c==null){
JOptionPane.showMessageDialog(this,"您没有选取颜色!");
}else{
demo.setForeground(c);
}
}else if(ae.getSource()==exit){
System.exit(0);
}
}
public static void main(String args[]){
new ColorDemo();
}
}
你看一下吧
简单的颜色选取器
体会一下什么叫模态,你在关掉颜色选择框之前,能按到主面板么,当然按不到,这就是模态.
[此贴子已经被作者于2006-10-29 9:32:58编辑过]