/*
* NewJFrame.java
*
* Created on 2007年10月27日, 下午5:23
*/
package javaapplication1;
import java.awt.Robot;
import java.awt.*;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.UIManager;
import javax.swing.*;
import java.awt.image.*;
/**
*
* @author mm
*/
public class NewJFrame extends javax.swing.JFrame {
/** Creates new form NewJFrame */
public NewJFrame() {//構造方法
//this.setUndecorated(true);//去掉JFrame的标题栏
try {
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");//UI设置
//UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());//windows樣式
}catch (Exception ex) {
javax.swing.JOptionPane.showMessageDialog(this,"發生UI加載錯誤,您可能無法看到程式預想的UI效果,錯誤信息如下:/n"+ex.toString());
}
initComponents();
this.setLocation(100,100);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" 生成的代码 ">
private void initComponents() {
jlb = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
addComponentListener(new java.awt.event.ComponentAdapter() {
public void componentMoved(java.awt.event.ComponentEvent evt) {
formComponentMoved(evt);
}
public void componentResized(java.awt.event.ComponentEvent evt) {
formComponentResized(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jlb, javax.swing.GroupLayout.DEFAULT_SIZE, 706, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jlb, javax.swing.GroupLayout.DEFAULT_SIZE, 643, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
private void formComponentResized(java.awt.event.ComponentEvent evt) {
// TODO 将在此处添加您的处理代码:
this.selectBgimg();
}
private void formComponentMoved(java.awt.event.ComponentEvent evt) {
// TODO 将在此处添加您的处理代码:
selectBgimg();
}
private void selectBgimg(){//截屏代码
try {
//Point p=this.getLocation();//移動方式,用p
//this.setLocation(-2000,-2000);//移動方式
this.setVisible(false);//隱藏方式,用this
Robot rbt = new Robot();
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension dim = tk.getScreenSize();
java.awt.Image background = rbt.createScreenCapture(new Rectangle((int)this.getX(),(int)this.getY(), this.getWidth(),this.getHeight()));
background = rbt.createScreenCapture(new Rectangle((int)this.getX(),(int)this.getY(), this.getWidth(),this.getHeight()));
background = rbt.createScreenCapture(new Rectangle((int)this.getX(),(int)this.getY(), this.getWidth(),this.getHeight()));
background = rbt.createScreenCapture(new Rectangle((int)this.getX(),(int)this.getY(), this.getWidth(),this.getHeight()));
ImageIcon bg=new ImageIcon(background);
jlb.setIcon(bg);
this.setVisible(true);//隱藏方式
//this.setLocation(p);//移動方式
} catch (Exception ex) {
javax.swing.JOptionPane.showMessageDialog(this,"發生錯誤,錯誤信息如下:/n"+ex.toString());
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
// 变量声明 - 不进行修改
private javax.swing.JLabel jlb;
// 变量声明结束
}