![]() |
#2
Iamnemo2017-10-23 20:56
|

[code]
import java.awt.*;
import javax.swing.*;
public class AbsolutePosition extends JFrame{
public AbsolutePosition(){
setTitle("本窗口使用绝对布局");
setLayout(null);
setBounds(200,200,500,350);
Container c = getContentPane();
setBackground(Color.BLUE);
JButton b1 = new JButton("按钮1");
JButton b2 = new JButton("按钮2");
b1.setBounds(10, 30, 80, 30);
b2.setBounds(60, 70, 100, 20);
c.add(b1);
c.add(b2);
setBackground(Color.black);
setVisible(true);
//设置窗体关闭方式
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args){
new AbsolutePosition();
}
}
[/code]import java.awt.*;
import javax.swing.*;
public class AbsolutePosition extends JFrame{
public AbsolutePosition(){
setTitle("本窗口使用绝对布局");
setLayout(null);
setBounds(200,200,500,350);
Container c = getContentPane();
setBackground(Color.BLUE);
JButton b1 = new JButton("按钮1");
JButton b2 = new JButton("按钮2");
b1.setBounds(10, 30, 80, 30);
b2.setBounds(60, 70, 100, 20);
c.add(b1);
c.add(b2);
setBackground(Color.black);
setVisible(true);
//设置窗体关闭方式
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args){
new AbsolutePosition();
}
}
运行之后setBackground();这行代码没作用啊,怎么回事