62,612
社区成员
发帖
与我相关
我的任务
分享
private JLabel label_held = new JLabel();
public AirMainManage() {
Thread t = new Thread();
t.start();
init();
}
public void init() {
frame.add(getPanel());
frame.setSize(1024, 768); // 设置大小
/*
* 设置局中显示 获取屏幕像素
*/
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((screen.width - frame.getWidth()) / 2,
(screen.height - frame.getHeight()) / 2);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 设置默认关闭属性
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
int value = JOptionPane.showConfirmDialog(null, "确认退出?",
"退出提示", JOptionPane.OK_CANCEL_OPTION,
JOptionPane.WARNING_MESSAGE);
if (value == JOptionPane.YES_OPTION) {
System.exit(1);
}
}
});
frame.setResizable(false);// 设置不可调整大小
frame.setVisible(true); // 设置可见性
}
public JPanel getPanel_held() {
panel_held.setLayout(null);
label_.setFont(new Font("Monotype Corsiva", Font.BOLD, 40));
label_.setForeground(Color.white);
panel_held.add(label_);
label_.setBounds(10, 50, 1018, 45);
panel_held.setBackground(new Color(194, 0, 0));
panel_held.setBounds(0, 0, 1018, 100);
panel_held.setBorder(BorderFactory.createLineBorder(Color.white, 2));
return panel_held;
}
public void run() {
while(true) {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
label_held = new JLabel(new ImageIcon(
this.getClass().getResource("/com/panSky/picture/标签.jpg")));
label_held = new JLabel(new ImageIcon(
this.getClass().getResource("/com/panSky/picture/经济舱.jpg")));
label_held = new JLabel(new ImageIcon(
this.getClass().getResource("/com/panSky/picture/特级经济舱.jpg")));
label_held = new JLabel(new ImageIcon(
this.getClass().getResource("/com/panSky/picture/豪华商务舱.jpg")));
label_held = new JLabel(new ImageIcon(
this.getClass().getResource("/com/panSky/picture/标签2.JPG")));
}
}
final ImageIcon[] icons = new ImageIcon[5];
icons[0] = new ImageIcon(
this.getClass().getResource("/com/panSky/picture/标签.jpg"));
icons[1] = new ImageIcon(
this.getClass().getResource("/com/panSky/picture/经济舱.jpg"));
icons[2] = new ImageIcon(
this.getClass().getResource("/com/panSky/picture/特级经济舱.jpg"));
icons[3] = new ImageIcon(
this.getClass().getResource("/com/panSky/picture/豪华商务舱.jpg"));
icons[4] = new ImageIcon(
this.getClass().getResource("/com/panSky/picture/标签2.JPG"));
// int delay = 1000;
// ActionListener ChangeImg = new ActionListener() {
//
// public void actionPerformed(ActionEvent arg0) {
// label_held.setIcon(icons[i]);
// }
//
// };
// new Timer(delay, ChangeImg).start();
final Random random = new Random();
new Timer(1000, new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
label_held.setIcon(icons[random.nextInt(icons.length)]);
}
}).start();
}
ImageIcon[] icons =
Random random = new Random();
new Timer(1000,new ActionListener(){
public void actionPerformed(ActionEvent e){
label.setIcon(icons[random.nextInt(icons.length)]);
}
});