我写了一个,你看看
import java.awt.*;
import javax.swing.*;class Foo extends JFrame
{
public static void main(String[] args)
{
Foo f = new Foo();
f.setSize(400, 200);
f.show();
}
public Foo()
{
Container c = getContentPane();
Canvas cn = new Canvas();
cn.setBackground(Color.red);
c.add(cn);
}
}
import java.awt.*;
import javax.swing.*;class Foo extends JFrame
{
public static void main(String[] args)
{
Foo f = new Foo();
f.setSize(400, 200);
f.show();
}
public Foo()
{
Container c = getContentPane();
Canvas cn = new Canvas();
cn.setBackground(Color.red);
c.add(cn);
}
}
c.setLayout(new BorderLayout());
试试。
Canvas cn = new Canvas();
cn.setBackground(Color.red);
c.add(cn);
import javax.swing.*;public class test extends JFrame
{
JPanel mainPane = null;
JButton btnOK = null;
test ()
{
init ();
}
private void init ()
{
addWindowListener(new WindowAdapter ()
{
public void windowClosing (WindowEvent e)
{
System.exit (0);
}
});
getPane ();
setSize (400, 350);
}
private JPanel getPane ()
{
mainPane = ((JPanel)getContentPane ());
mainPane.setBackground(Color.BLUE);
return (mainPane);
}
public static void main (String [] args)
{
new test().show ();
}
}