31. Java中定义组件TextArea ta的背景颜色为红色的命令是什么?

来源:百度知道 编辑:UC知道 时间:2024/06/07 16:51:31
(是SetBackGround(color.red) 吗)

import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Test2 extends JFrame
{
private JTextArea ta ;
private Container con;
private JPanel panel;
private JPanel panel2;
public Test2(){

setTitle("Test JTextarea");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
con = getContentPane();
ta = new JTextArea(10,20);
ta.setText("TextArea");
ta.setBackground(Color.red);
panel = new JPanel();
panel.add(ta);
panel2 = new JPanel();
con.setLayout(new BorderLayout());
con.add(panel,BorderLayout.EAST);
con.add(panel,BorderLayout.WEST);
setSize(200,400);
setVisible(true);
}
public static void main(String[] args)
{
new Test2();
}
}

我写了一个小程序测试了一下,用的方法是setBackground(Color.red).

是的吧,注意大小写,SetBackground(Color.RED)颜色小写也行,Background是一个单词,B大写……
这种问题自己看