JAVA笔记__窗体类/Panel类/Toolkit类
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了JAVA笔记__窗体类/Panel类/Toolkit类,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2017字,纯文字阅读大概需要3分钟。
内容图文
![JAVA笔记__窗体类/Panel类/Toolkit类](/upload/InfoBanner/zyjiaocheng/1129/b6666120630549999f556ad7a278eff2.jpg)
/** * 窗体类 */ public class Main { public static void main(String[] args) { MyFrame m1 = new MyFrame(); } } class MyFrame extends Frame{ public MyFrame(){ this.setTitle("My first software"); this.setSize(300,200); this.setBackground(Color.yellow); this.setResizable(false); //不允许调整窗体大小this.setLocation(300,300); this.setLayout(new FlowLayout()); //把窗体的默认布局设成"流水布局" //在窗体上添加按钮 Button b1 = new Button("click me.1"); this.add(b1); this.add(new Button("click me.2")); this.setVisible(true); } }
/** * Panel类(面板类),组件容器 */ public class Main { public static void main(String[] args) { MyPanel m1 = new MyPanel(); } } class MyPanel extends Frame{ public MyPanel(){ this.setTitle("My first software"); this.setSize(600,400); this.setBackground(Color.yellow); this.setResizable(false); //不允许调整窗体大小this.setLocation(300,300); this.setLayout(new FlowLayout()); //把窗体的默认布局设成"流水布局" addPanel(); this.setVisible(true); } publicvoid addPanel(){ //Panel的布局默认是"流水布局" Panel p1 = new Panel(); //创建面板对象 p1.setBackground(Color.GREEN); p1.add(new Button("click me.1")); p1.add(new Button("click me.2")); p1.add(new Button("click me.3")); this.add(p1); //把面板添加到窗体上 } }
/** * Toolkit类:用于将各种组件绑定到本地系统的工具包。 */ public class Main { public static void main(String[] args) { MyToolkit m1 = new MyToolkit(); } } class MyToolkit extends Frame{ public MyToolkit(){ this.setTitle("My first software"); this.setSize(600,400); this.setBackground(Color.yellow); Toolkit t1 = Toolkit.getDefaultToolkit(); //获取工具对象 Dimension d1 = t1.getScreenSize(); //获取当前屏幕的尺寸double w = d1.getWidth(); double h = d1.getHeight(); int x = (int)(w/2); int y = (int)(h/2); this.setLocation(x-300,y-200); //设置窗体图标 (新建一个包,把图片放进去) URL url = this.getClass().getClassLoader().getResource("pkg1/image/fish.jpg"); //写成pkg1.image.fish.jpg不可以 Image ima1 = t1.getImage(url); this.setIconImage(ima1); this.setResizable(false); //不允许调整窗体大小this.setLayout(new FlowLayout()); //把窗体的默认布局设成"流水布局"this.setVisible(true); } }
原文:http://www.cnblogs.com/fish7/p/4162170.html
内容总结
以上是互联网集市为您收集整理的JAVA笔记__窗体类/Panel类/Toolkit类全部内容,希望文章能够帮你解决JAVA笔记__窗体类/Panel类/Toolkit类所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。