import java.awt.*;
import java.awt.event.*;
import javax.swing.*;public class CSDNTest extends JFrame
{
public CSDNTest()
{
JPanel a = new JPanel(null);
a.setPreferredSize(new Dimension(300,300));
a.setBackground(Color.red);
a.setLayout(new BorderLayout());
a.add(new JLabel("This is Test."),BorderLayout.NORTH);
a.setOpaque(false);//设置JPanel为透明
Container contentPane = getContentPane();
contentPane.add(a,BorderLayout.NORTH);

setTitle("CSDN");
setBounds(0,0,600,600);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}); }

public static void main(String[] args)
{
JFrame frame = new CSDNTest();
frame.setVisible(true);
}
} 希望对你有所帮助!