图形用户界面(三)

1.面板也是一种容器,不是一个单独的窗口,它只是包含在窗口中的一个区域,必须将面板添加到窗体中。
2. 文本框
public class PanelDemo extends JFrame{
private JPanel panel;
private JButton button;
private void init(){
button=new JButton(“按钮”);
panel=new JPanel();//流式布局 居中对齐
panel.add(button);
panel.setBackground(Color.blue);
this.add(panel);
this.setResizable(false);
this.setTitle(“QQ登录”);
this.setSize(255,125);
this.setLocation(400,300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public PanelDemo(){
init();}
}

public class Test{
public static void main(String[] args){
new PanelDemo();}}

3.屏幕中间位置
Dimension dim=getToolkit().getScreenSize();
int w=dim.width/2;
int h=dim.height/2;
this.setSize(255,125);
this.setLocation(w-255/2,h-125/2);
4.滚动条
public class PanelDemo extends JFrame{
private JPanel panel;
private JButton button;
private JTextArea area;
private JScrollPane scrollPane;
private void init(){
//显示文本,行数,列数
area=new JTextArea(“多行文本框”,5,20);
scrollPane=newJScrollPane(area);
this.setLayout(new FlowLayout());
this.add(scrollPane);
this.setTitle(“QQ登录”);
this.setSize(255,125);
this.setLocation(400,300);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public PanelDemo(){
init();}
}

public class Test{
public static void main(String[] args){
new PanelDemo();}}

5.多选框
public class PanelDemo extends JFrame{
private JPanel panel;
private JButton button;
private JTextArea area;
private JScrollPane scrollPane;
private JCheckBox box1,box2;
private void init(){
box1=new JCheckBox(“运动”);
box2=new JCheckBox(“读书”);
//多选按钮是否被选中
box1.isSelected();
//显示文本,行数,列数
area=new JTextArea(“多行文本框”,5,20)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值