java关机工具之页面布局参考代码

最终效果图:

<img src="https://img-blog.csdn.net/20140920140741474?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc3lzdHFs/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />


源代码
package com.tim.timer;
import java.awt.*;
import java.awt.event.*; //事件类
import javax.swing.*; //包含JFrame

public class CloseComputer extends JFrame implements ActionListener{
	//创建成员变量
	//创建实现BorderLayout布局的面板对象panel_main
	private JPanel panel_main=new JPanel(new BorderLayout(5,10));
	//创建实现FlowLayout布局的面板对象panel_subnorth
	private JPanel panel_subnorth=new JPanel(new FlowLayout(3));
	//创建实现FlowLayout布局的面板对象panel_subcenter
	private JPanel panel_subcenter=new JPanel(new FlowLayout(1,5,3));
	//创建了3个按钮对象countdown、time和cancel
	private JButton countdown = new JButton("倒计时关机");
	private JButton time = new JButton("定时关机");
	private JButton cancel = new JButton("取消关机");
	//创建标签对象tag
	private JLabel tag;
	//创建字符串对象key
	String key;
	//构造函数
	public CloseComputer()
	{
		//添加对象panel_main到主窗口里
		this.getContentPane().add(panel_main);
		//添加对象panel_subnorth到对象pane_main窗口里
		panel_main.add(panel_subnorth,BorderLayout.NORTH);
		//添加对象panel_subnorth到对象pane_main窗口里
		panel_main.add(panel_subcenter,BorderLayout.CENTER);
		//添加标签对象tag到对象panel_subnorth里
		panel_subnorth.add(tag=new JLabel("请选择关机方式:"));
		//添加3个按钮到对象panel_subcenter里
		panel_subcenter.add(countdown);
		panel_subcenter.add(time);
		panel_subcenter.add(cancel);
		//为3个按钮注册事件监听器
		countdown.addActionListener(this);;
		time.addActionListener(this);
		cancel.addActionListener(this);
		
	}
	
	public static void main(String[] args) throws Exception
	{
		CloseComputer frame=new CloseComputer();//创建CloseComputer对象
		//设置窗口关闭功能
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.pack();
		frame.setSize(320,120);
		frame.setTitle("关机工具");
		frame.setLocation(350,350);
		//设置显示
		frame.setVisible(true);
		frame.setResizable(false);
	}
	
	public void actionPerformed(ActionEvent eAction)
	{
		
	}
	
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值