我有一个swing 应用程序,并且我编写了代码来更改JTextArea 的背景颜色。但是,它给了我例外。
这是代码:
//1.JtextArea will work after maximize.
//2.on typing text,background will slowly transform to black line by line.
import java.awt.*;
import javax.swing.*;
public class TextArea {
JTextArea area;
JFrame frame;
public static void main(String args[])
{
TextArea x = new TextArea();
x.execute();
}
void execute()
{
frame = new JFrame();
frame.setVisible(true);
frame.setSize(600,600);
frame.setTitle("Temp Area");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
area = new JTextArea();
frame.add(area,BorderLayout.CENTER);
Color c = new Color(0,0,0,100);
area.setBackground(c);
}
}