import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;
public class X extends JPanel {
private static final long serialVersionUID = 0L;
private javax.swing.Timer timer = null;
private Random rand = new Random();
public X(LayoutManager layout) {
super(layout);
}
//just is a dumb example, but you get the idea
//you may want to suspend animation when the window is iconified or deactivated
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(getBackground());
g.fillRect(0,0,getWidth(),getHeight());
if (timer == null) {
timer = new javax.swing.Timer(500, new ActionListener(){
public void actionPerformed(ActionEvent evt) {
setBackground(new Color(rand.nextInt(0x1000000)));
//repaint();
}
});
timer.start();
}
}
public static void main(String[] args) throws IOException {
Container cp = new X(new BorderLayout());
JTextArea area = new JTextArea();
area.setOpaque(false);
area.read(new FileReader("X.java"), null);
JScrollPane sp = new JScrollPane(area);
sp.setOpaque(false);
sp.getViewport().setOpaque(false);
cp.add(sp);
JPanel south = new JPanel();
south.setOpaque(false);
south.add(new JButton("ABC"));
south.add(new JButton("DEF"));
south.add(new JButton("GHI"));
cp.add(south, BorderLayout.SOUTH);
JFrame f = new JFrame("X");
f.setContentPane(cp);
f.setSize(300,200);
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}