java创建一个基本窗体

import javax.swing.JFrame;

public class DFrame extends JFrame{

	/**
	 * dingshuangen
	 */
	private static final long serialVersionUID = 1L;

	//构造方法
	public DFrame()  {
	
		this.setTitle("我的第一个窗体");
		//this.setBounds(300,200,450,350);设置窗体位置大小,前两个参数为位置,后两个参数为窗体大小
		this.setLocation(300,200);//设置位置
		this.setSize(450,350);//设置大小
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//设置窗体关闭方式
		this.setVisible(true);//设置为可见
	}
	
	public static void main(String[] args) {
		new DFrame();
	}
}

  • 5
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
整理了Java GUI编程基础知识! public class AllFrame { /** * 这里的代码涉及到 GUI 编程基本面板、基本组件、事件(ActionListener、ChangeListener、MouseListener) */ public AllFrame() { // new 一个主 也可以这样写 new MainFrame(); MainFrame mf = new MainFrame(); } public static void main(String[] args) { new AllFrame(); } // 主 继承 基本格式 类 Jframe 以下弹出口均继承 Jframe class MainFrame extends Jframe implements ActionListener { JMenuBar menubar = new JMenuBar();;// 菜单条 JMenu jmenu[] = new JMenu[5];// panelMenu,usedMenu1,usedMenu2,layoutMenu,helpMenu; // 菜单项 JButton closebtn;// 关闭 // 具的选项 JMenuItem panelitem[] = new JMenuItem[4]; JMenuItem useditem1[] = new JMenuItem[6]; JMenuItem useditem2[] = new JMenuItem[6]; JMenuItem layoutitem[] = new JMenuItem[3]; JMenuItem helpitem = new JMenuItem("关于"); // 菜单中名称 String menu[] = { "面板使用", "常用组件一", "常用组件二", "布局设置", "帮助" }; String pane[] = { "普通面板", "滚动面板", "分割面板", "选项面板" }; String uesd1[] = { "标签", "按钮", "文本框", "文本域", "单选按钮" ,"微调"}; String uesd2[] = { "滑块","复选框", "下拉菜单", "列表", "表格", "树状" }; String layout[] = { "流式布局", "边界布局", "网格布局" }; // Jpanelitem,Jscrollpaneitem,Splitpaneitem,JTabbedpanelitem, // Jlabelitem,Jbuttonitem,JTextfielditem,JTextareaitem,JRadiobuttonitem, // JCheckboxitem,JCombomoxitem,Jlistitem,Jtableitem,Jtreeitem, // Flowlayoutitem,Borderlayoutitem,Girdlayoutitem, // Helpitem}; public MainFrame() { this.setTitle("JAVA图型界面学习(GUI)"); // 加载菜单条到中 this.setJMenuBar(menubar); // 重新设置大小 this.setSize(380, 290); // 简单的居中方法 在基本格式类 Jframe 中有详细的居中方法 this.setLocationRelativeTo(null); // 设置关闭口 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 调用方法 menu(); // 设置容器 Container con = this.getContentPane(); // 定义一个 标签 “JAVA图型界面学习” JLabel jl = new JLabel("JAVA图型界面学习"); // 组件 设置字大小, 其他组件用法相同 jl.setFont(new Font("隶书", Font.BOLD, 24)); // 具定位 组件名.setBounds(x, y, width, height) jl.setBounds(30, 30, 280, 50); // 把标签加到 con 容器中 con.add(jl); /
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值