展开全部
参考代码如下TextFieldtf=newTextField(16);
tf.setBackground(Color.LIGHT_GRAY);//文本框背景设置为亮灰32313133353236313431303231363533e4b893e5b19e31333363393066色
//tf.setBackground(newColor(244,244,244));//文本框背景设置为指定的颜色
tf.setEditable(false);//文本框设置为不可编辑
效果图
完整的代码importjava.awt.*;
importjava.awt.event.*;
publicclassFrameDemoextendsFrame{
FrameDemo(){
TextFieldtf=newTextField(16);//初始化文本框
tf.setBackground(Color.LIGHT_GRAY);//文本框背景为亮灰色
//tf.setBackground(newColor(244,244,244));//文本框为指定的颜色
tf.setEditable(false);//文本框不许编辑
Paneljp=newPanel();
jp.add(tf);
add(jp);
//窗口属性的设置
setTitle("窗口");//标题
setSize(242,170);//窗口大小
setLocationRelativeTo(null);//窗口居中
addWindowListener(newWindowAdapter(){//点击关闭窗口时,程序结束
@Override
publicvoidwindowClosing(WindowEvente){
System.exit(0);
}
});
}
publicstaticvoidmain(String[]args){
newFrameDemo().setVisible(true);//创建窗口实例,并让窗口可见
}
}