package com.mstanford; import java.awt.FlowLayout; import javax.swing.*; import javax.swing.table.DefaultTableModel; public class MainFrame extends JFrame { public JButton btn1,btn2,btn3,btn4,btn5; public MainFrame() { this.setTitle("这是一个swing窗体"); this.setBounds(200, 100, 800, 500); this.setVisible(true); this.setResizable(false); // 实例化标签 JLabel lblPwd = new JLabel(); // 增加图片 ImageIcon imgIcon = new ImageIcon("E:/images/imagen8.jpg"); JLabel lblImg = new JLabel(imgIcon); this.getContentPane().add(lblImg); // 创建表格 // String columnNames[]={"会员管理","姓名","电话","城市"}; // DefaultTableModel model=new DefaultTableModel(columnNames,0); // JTable Tb = new JTable(model); //流动布局 this.setLayout(new FlowLayout(FlowLayout.LEFT)); // 实例化按钮 JButton btn1 = new JButton("按钮1"); JButton btn2 = new JButton("按钮2"); JButton btn3 = new JButton("按钮3"); JButton btn4 = new JButton("按钮4"); JButton btn5 = new JButton("按钮5"); // 添加面板 this.getContentPane().add(btn1); this.getContentPane().add(btn2); this.getContentPane().add(btn3); this.getContentPane().add(btn4); this.getContentPane().add(btn5); } public static void main(String[] args) { new MainFrame(); } }
怎样将图片设置为背景并且全覆盖窗体,还有按钮是怎样定位啊!请大神们指导
奔跑的虫子
相关分类