原代码如下: import java.awt.*; import javax.swing.*;
public class MainFrame { public static void main(String[] args) { MFrame newFrame = new MFrame(); newFrame.setDefaultCloseOperation(newFrame.EXIT_ON_CLOSE); newFrame.show(); newFrame.setVisible(true); } }
class MFrame extends JFrame { private JPanel Content; public MFrame() { Content = (JPanel)getContentPane(); setTitle("财务之星"); setBounds(100,100,300,200); //setResizable(false); //add(new PicPanel()); Content.setOpaque(false); //设内容窗格为透明。。 Content.setLayout(new FlowLayout()); Content.add(new LoginPanel()); Content.add(new JButton("确认")); //Content.add(new PicPanel()); this.getLayeredPane().setLayout(null); this.getLayeredPane().add(new PicPanel(),new Integer(Integer.MIN_VALUE)); } }
class PicPanel extends JPanel { public PicPanel() { //把图片显示在标签里。。。 JLabel picLabel = new JLabel(); picLabel.setIcon(new ImageIcon("banner.gif")); picLabel.setBounds(0,0,300,200); setOpaque(false); add(picLabel); } }
class LoginPanel extends JPanel { public LoginPanel() { JLabel loginLabel = new JLabel(); loginLabel.setText("用户名:"); //loginLabel.setBounds(0,0,300,200); add(loginLabel); } }