编程:在form窗体中,建立1个Text文本框、1个Label标签、2个命令按钮,单击不同命令

,在Label标签中分别显示“文本框的前景色为红色”和“文本框的背景色为蓝色”。

我是这样做的
建立三个TEXT文本框(因为rgb函数的参数有三个)
一个标签用来显示颜色
第一个命令按钮是确定 第二个是退出

代码如下
private sub command1_click()
r=val(text1.text)
g=val(text2.text)
b=val(text3.text)
label1.backcolor=rgb(r,g,b)
if r>255 or r<0 then
msgbox "只能输入0到255之间的数字哦",vbinformation,"小提示"
elseif g>255 or g<0 then
msgbox "只能输入0到255之间的数字哦",vbinformation,"小提示"
elseif r>255 or r<0 then
msgbox "只能输入0到255之间的数字哦",vbinformation,"小提示"

end sub
private sub command2_click()
end
end sub
把分给我 我都打字打晕了
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-11-06
问题描述的不详细 那个TEXT 用来干嘛
第2个回答  2009-11-06
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class YourQuestion{
JFrame frmMain;
JLabel lblInfo;
JTextField txtExample;
JButton btnShowBackground,btnShowForeground;
public YourQuestion(){
frmMaine=new JFrame("你的问题");
frmMain.setLayout(new FlowLayout());
txtExample("示例文本");
lblInfo=new JLabel("文本框的背景色是蓝色");
btnShowBackground.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
lblInfo.setText("文本框的背景色是蓝色");
txtExample.setBackground(Color.BLUE);
}
});
btnShowForeground.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
lblInfo.setText("文本框的前景色是红色");
txtExample.setForeground(Color.RED);
}
});
frmMain.setVisible(true);
}
public static void main(String[] args){
new YourQuestion();
}
}
第3个回答  2009-11-06
问题呢?