package jingling;
import java.awt.BorderLayout;
public class l extends JFrame {
private JPanel contentPane;
int width=200;
int height=200;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
for(int i=0;i<=9;i++){
Random random = new Random();//默认构造方法
///Random random = new Random(1000);//指定种子数字
//(02) 通过Random对象获取随机数。Random支持的随机值类型包括:boolean, byte, int, long, float, double。
//比如,获取[0, 100)之间的int整数。方法如下:
//Random ra = new Random(768);//默认构造方法
Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
int w = screensize.width;
int h = screensize.height;
int x = random.nextInt(w);
int y = random.nextInt(h);
l frame = new l(x,y);
frame.setVisible(true);
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public l(int x,int y) {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//int io=0;
final double d = Math.random();
final int ic = (int)(d*100);
setBounds(x, y, width, height);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
ImageIcon image = new ImageIcon("C:/Users/cc/Desktop/2.jpg");
image.setImage(image.getImage().getScaledInstance(width,height,Image.SCALE_DEFAULT));
JLabel label = new JLabel(image);
label.setSize(width,height);
contentPane.add(label);
setUndecorated(true);//去掉边框
setAlwaysOnTop(true);//窗口置顶
}
}
java swing制作弹图片窗口 铺满屏幕
最新推荐文章于 2022-02-04 13:06:53 发布