您的位置:首页 > 产品设计 > UI/UE

7.2在框架中添加一个面板,背景色设为黄色,在面板中再添加两个按钮。

2017-04-07 18:55 441 查看

摩尔的Java学习笔记7.2

第七周作业:

1、在窗口(宽300,高200)中添加一个面板,面板的背景色为绿色,窗口在屏幕中央,不允许改变其大小,关闭窗口时程序结束运行;

2、在框架中添加一个面板,背景色设为黄色,在面板中再添加两个按钮。

2、在框架中添加一个面板,背景色设为黄色,在面板中再添加两个按钮。

/**
* @author 薛莲婷
* 在框架中添加一个面板,背景色设为黄色,在面板中再添加两个按钮
*/
import java.awt.*;
import javax.swing.*;

class ButtonDemo{
JFrame frame;
JButton buttonOK,buttonCancel;

ButtonDemo(){}
ButtonDemo(String title){
frame = new JFrame(title);
frame.setSize(300, 200);
frame.getContentPane().setBackground(Color.YELLOW); //设置面板背景色为黄色

frame.setLayout(new FlowLayout());                  //设置流式布局管理器
buttonOK = new JButton("OK");
buttonCancel = new JButton("Cancel");

frame.add(buttonOK);                                //添加两个按钮
frame.add(buttonCancel);

frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}
}
class Button {

public static void main(String[] args) {
new ButtonDemo("黄色背景面板,以及两个按钮");
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐