Java 个性话的起始页

先写一个类public class la extends JComponent {

    private JFrame frame; 
    private Image background;

public la(JFrame frame) {
    this.frame = frame;
    updateBackground();
}
public void updateBackground( ) {
    try {
        Robot rBT = new Robot( );
        Toolkit tk = Toolkit.getDefaultToolkit( );
        Dimension dim = tk.getScreenSize( );
        background = rBT.createScreenCapture(
        new Rectangle(0,0,(int)dim.getWidth( ),
                          (int)dim.getHeight( )));
    } catch (Exception ex) {
        //p(ex.toString( )); 
// 此方法没有申明过,因为无法得知上下文。因为不影响执行效果,先注释掉它
        ex.printStackTrace( );
    }
}
public void paintComponent(Graphics g) {
    Point pos = this.getLocationOnScreen( );
    Point offset = new Point(-pos.x,-pos.y);
    g.drawImage(background,offset.x,offset.y,null);
    repaint();
}
public static void main(String[] args) {
    JFrame frame = new JFrame("Transparent Window");
    la bg = new la(frame);
    bg.setLayout(new BorderLayout( ));
    JButton button = new JButton("This is a button");   
    JLabel label = new JLabel("This is a label");
    bg.add("South",label);
    frame.setUndecorated(true);
    frame.getContentPane( ).add("Center",bg); 
    frame.setSize(500,400);
    frame.setLocation(400,400);
    frame.setVisible(true);
}
}

在其它类里调用



 public static void main(String[] args) {

JFrame frame1 = new JFrame();
  la bg = new la(frame1);
  bg.setLayout(new BorderLayout( ));
     JPanel donghua = new JPanel(){
       public void paintComponent(Graphics g) { 
           g.setColor(Color.blue);
           Image img = new ImageIcon("res/b3.png").getImage( ); 
         g.drawImage(img,0,0,null);
       }
   };
      donghua.setOpaque(false);
      bg.add(donghua);   
  frame1.getContentPane( ).add("Center",bg); 
  frame1.setSize(500,380);
  frame1.setLocation(580,240);
  frame1.setUndecorated(true);
  frame1.setVisible(true);
                 //中间代码
                 try{
Thread.sleep(1500);
frame1.setVisible(false);//启动面关闭
  }catch(Exception e){
  }
}
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值