在一个frame设置四个组件
2015-10-27 12:33
218 查看
import javax.swing.*; import java.awt.*; public class Panel extends JPanel{ public void paintComponent(Graphics g){ g.fillRect(0, 0, this.getWidth(), this.getHeight()); int red = (int)(Math.random() * 255); int green = (int)(Math.random() * 255); int blue = (int)(Math.random() * 255); Color myColor = new Color(red,green,blue); g.setColor(myColor); g.fillOval(70,70, 100, 100); } }
View class Panel
在Panel(继承自JPanel)类中方法paintComponent()
fillRect(0,0,this.width,this.height)表示在该panel的(x,y)坐标为起始,this.width和this.height也表示该面板的宽高
需要作出改变的组件,放做全局
在go中有代码:
button1.addActionListener(new ColorActionListener());
button2.addActionListener(new LabelActionListener());
在外部类对象中新建的内部类对象会与该外部类对象产生联结,内部类对象可直接调用外部类对象的实例变量,也因此,需要改变的组件做实例变量也是为了给内部对象使用
BoarderLayout.CENTER 这个中间是相对于其他组件而言的,当其左边的组件变小时,他可能会变大
相关文章推荐
- 在PYTHON中,用cx_Oracle连接ORACLE数据库简单示例
- iOS 获取 APP 的 Launch Image
- QT5入门之15 - qr函数
- opencv读入图像和avi
- JavaScript 通过HTML的FileReader把图片转成base64
- 九度OJ 1209:最小邮票数 (遍历)
- 经常使用的网站汇总
- 九度OJ 1209:最小邮票数 (遍历)
- 第一篇
- Android怎么让软键盘显示和消失
- Operating System: Three Easy Pieces --- LDE (Note)
- 九度OJ 1208:10进制 VS 2进制 (进制转换)
- 九度OJ 1208:10进制 VS 2进制 (进制转换)
- gdb qemu调试linux kernel并修改远程连接的bug
- Windows无法启动OracleOraDb10g_home1TNSListener维修,1错误067
- Objective-C中的getter与setter
- Lua中的基本函数库
- [LeetCode] Search in Rotated Sorted Array II [36]
- 图解linux启动过程
- iOS-极光推送开发小结