JFrame中背景图大小随窗口大小自动改变
来源:互联网 发布:mac qq怎么发送文件 编辑:程序博客网 时间:2024/05/29 16:14
package com.ui; import java.awt.Color;import java.awt.Font;import java.awt.Graphics;import java.awt.Image; import javax.swing.ImageIcon;import javax.swing.JButton;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JTextField; public class MainTopPanel extends JPanel {private static final long serialVersionUID = -2783727170881461229L;private int width;private int height;private Image image = new ImageIcon(getClass().getClassLoader().getResource("com/resource/ZHU.jpg")).getImage();private JButton btnLogon = new JButton(" 登录 ");private JButton btnCancel = new JButton(" 取消 ");private JLabel labId = new JLabel("账号:");private JLabel labPass = new JLabel("密码:");private JTextField fieldId = new JTextField();private JPasswordField fieldPass = new JPasswordField();private int btnLogon_x = 535, btnLogon_y = 399;private int btnCancel_x = 655, btnCancel_y = 399;private int labId_x = 495, labId_y = 339;private int labPass_x = 495, labPass_y = 369;private int fieldId_x = 545, fieldId_y = 339;private int fieldPass_x = 545, fieldPass_y = 369; public MainTopPanel(int width, int height) {this.width = width;this.height = height;this.setLayout(null);this.init();} public void setScreenSize(int width, int height) { //设置窗口变化后的大小this.width = width;this.height = height;} public void setLocationComponent(int width, int height) { //计算当窗口放大或者缩小,组件自动调整位置int m = this.width - width;int n = this.height - height;this.btnLogon_x -= m;this.btnLogon_y -= n;this.btnCancel_x -= m;this.btnCancel_y -= n;this.labId_x -= m;this.labId_y -= n;this.labPass_x -= m;this.labPass_y -= n;this.fieldId_x -= m;this.fieldId_y -= n;this.fieldPass_x -= m;this.fieldPass_y -= n;btnLogon.setBounds(this.btnLogon_x, this.btnLogon_y, 102, 22);btnCancel.setBounds(this.btnCancel_x, this.btnCancel_y, 102, 22);labId.setBounds(this.labId_x, this.labId_y, 57, 17);labPass.setBounds(this.labPass_x, this.labPass_y, 57, 17);fieldId.setBounds(this.fieldId_x, this.fieldId_y, 191, 22);fieldPass.setBounds(this.fieldPass_x, this.fieldPass_y, 191, 22);} private void init() {labId.setFont(new Font("微软雅黑", Font.PLAIN, 16));labId.setForeground(new Color(255, 255, 255));labId.setBounds(495, 339, 57, 17);labPass.setFont(new Font("微软雅黑", Font.PLAIN, 16));labPass.setForeground(new Color(255, 255, 255));labPass.setBounds(495, 369, 57, 17); btnLogon.setBounds(535, 399, 102, 22);btnLogon.setBackground(new Color(57, 149, 136));btnCancel.setBackground(new Color(57, 149, 136));btnCancel.setBounds(655, 399, 102, 22); fieldId.setBounds(545, 339, 191, 22);fieldId.setBackground(new Color(57, 149, 136));fieldId.setForeground(new Color(255, 255, 255));fieldPass.setBounds(545, 369, 191, 22);fieldPass.setBackground(new Color(57, 149, 136));fieldPass.setForeground(new Color(255, 255, 255)); this.add(labId);this.add(labPass);this.add(btnLogon);this.add(btnCancel);this.add(fieldId);this.add(fieldPass);} @Overrideprotected void paintComponent(Graphics g) {super.paintComponent(g);g.drawImage(image, 0, 0, width, height ,this);} }
0 0
- JFrame中背景图大小随窗口大小自动改变
- MFC如何让背景图随窗口大小改变
- netbeans中JTable大小随窗口大小改变而改变
- C#中pictureBox控件随窗口大小而改变大小
- 控件大小随窗口大小改变
- datagridview 随窗口大小改变自动调整列宽
- html中背景图不随着鼠标的转动改变大小
- vc picture控件载入背景图,随控件大小改变
- C#窗口控件大小随窗口大小而改变
- 在DELPHI中让WindowsMediaPlayer控件随窗口改变大小。
- QT中如何使控件随窗口改变大小?
- QT中如何使控件随窗口改变大小?
- winform中禁止改变窗口大小
- 改变窗口大小问题
- 改变窗口大小位置
- 改变窗口大小
- 当前窗口改变大小
- vim 改变窗口大小
- C++箭头(->)运算符的重载
- 关于百度地图、腾讯地图、高德地图、谷歌地图、天地图的那点事儿
- MessageBox 的一些用法
- JAVA年度安全 第七周 内容安全策略
- 手机找回
- JFrame中背景图大小随窗口大小自动改变
- C&C++混合编程
- 用Bing API接口实现同IP域名查询(Python版)
- OCP-1Z0-051 补充题库 第4题 聚合函数的使用
- 第一题
- 行为型模式4:观察者模式(Observer Pattern)
- Math与Random类
- 关于二级访存
- 第13周 比较