java 小马_Java 窗口 小马时钟

1 packagechryssi;2

3 importjava.applet.Applet;4 importjava.applet.AudioClip;5 importjava.net.URL;6 import java.awt.*;7 importjava.awt.event.ActionEvent;8 importjava.awt.event.ActionListener;9 importjava.awt.event.MouseAdapter;10 importjava.awt.event.MouseEvent;11 importjava.awt.event.MouseMotionAdapter;12 import java.io.*;13 import java.util.*;14 importjavax.swing.ImageIcon;15 importjavax.swing.JButton;16 importjavax.swing.JFrame;17 importjavax.swing.JLabel;18

19 public class PonyClock extendsJFrame20 {21 staticString ponyString;22 static boolean ponymute=true;23 static intpframexOri,pframeyOri,pframex,pframey;24

25 public static void main(String[] args) throwsException26 {27 JFrame ponyFrame=new JFrame("PonyClock");28 JLabel ponyLabel = new JLabel("",JLabel.CENTER);29 File directory = new File("");30 ponyFrame.setIconImage(Toolkit.getDefaultToolkit().getImage(directory.getCanonicalPath()+"\\icons\\32.png"));31 ImageIcon img00=new ImageIcon(Toolkit.getDefaultToolkit().getImage(directory.getCanonicalPath()+"\\pictures\\bg.png"));32 ImageIcon img01=new ImageIcon(Toolkit.getDefaultToolkit().getImage(directory.getCanonicalPath()+"\\pictures\\kisses.gif"));33 ImageIcon img02=new ImageIcon(Toolkit.getDefaultToolkit().getImage(directory.getCanonicalPath()+"\\pictures\\03.jpg"));34 ImageIcon img03=new ImageIcon(Toolkit.getDefaultToolkit().getImage(directory.getCanonicalPath()+"\\pictures\\02.jpg"));35 AudioClip ponyam,ponypm;36 File ponyf1=new File(directory.getCanonicalPath()+"\\audio\\Octavia_in_Tropics.wav");37 URL ponyurl1=ponyf1.toURI().toURL();38 File ponyf2=new File(directory.getCanonicalPath()+"\\audio\\Two_Best_Sisters.wav");39 URL ponyurl2=ponyf2.toURI().toURL();40 JButton ponyb_front = new JButton("");41 JButton ponyb_exit = new JButton("");42 JButton ponyb_mute = new JButton("");43 JButton ponyb_min = new JButton("");44 ImageIcon ponyb_fronti = new ImageIcon(Toolkit.getDefaultToolkit().getImage(directory.getCanonicalPath()+"\\icons\\front.png"));45 ImageIcon ponyb_nfronti = new ImageIcon(Toolkit.getDefaultToolkit().getImage(directory.getCanonicalPath()+"\\icons\\nfront.png"));46 ImageIcon ponyb_exiti = new ImageIcon(Toolkit.getDefaultToolkit().getImage(directory.getCanonicalPath()+"\\icons\\exit.png"));47 ImageIcon ponyb_mutei = new ImageIcon(Toolkit.getDefaultToolkit().getImage(directory.getCanonicalPath()+"\\icons\\mute.png"));48 ImageIcon ponyb_nmutei = new ImageIcon(Toolkit.getDefaultToolkit().getImage(directory.getCanonicalPath()+"\\icons\\nmute.png"));49 ImageIcon ponyb_mini = new ImageIcon(Toolkit.getDefaultToolkit().getImage(directory.getCanonicalPath()+"\\icons\\min.png"));50

51 /*Whole*/

52 ponyFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);53 ponyFrame.setLayout(null);54 ponyFrame.setResizable(false);55 ponyFrame.setLocationRelativeTo(null);56 ponyFrame.setSize(img01.getIconWidth(),img01.getIconHeight());57 ponyFrame.setUndecorated(true);58 ponyFrame.setAlwaysOnTop(false);59 ponyFrame.setBackground(new Color(255,255,255,255));60 ponyFrame.addMouseListener(newMouseAdapter() {61 @Override62 public voidmousePressed(MouseEvent e) {63 pframexOri=e.getX();64 pframeyOri=e.getY();65 }66 });67 ponyFrame.addMouseMotionListener(newMouseMotionAdapter() {68 @Override69 public voidmouseDragged(MouseEvent e) {70 ponyFrame.setLocation(e.getXOnScreen()-pframexOri,e.getYOnScreen()-pframeyOri);71 }72 });73

74 /*BUTTON_FRONT*/

75 ponyb_front.setIcon(ponyb_nfronti);76 ponyb_front.setSize(30, 30);77 ponyb_front.setLocation(img01.getIconWidth()-125, 10);78 ponyb_front.addActionListener(newActionListener(){79 public voidactionPerformed(ActionEvent e)80 {81 if(ponyFrame.isAlwaysOnTop()==true)82 {83 ponyFrame.setAlwaysOnTop(false);84 ponyb_front.setIcon(ponyb_nfronti);85 }86 else

87 {88 ponyFrame.setAlwaysOnTop(true);89 ponyb_front.setIcon(ponyb_fronti);90 }91 }92 });93 ponyFrame.add(ponyb_front);94

95 /*BUTTON_EXIT*/

96 ponyb_exit.setIcon(ponyb_exiti);97 ponyb_exit.setSize(30, 30);98 ponyb_exit.setLocation(img01.getIconWidth()-45, 10);99 ponyb_exit.addActionListener(newActionListener(){100 public voidactionPerformed(ActionEvent e)101 {102 System.exit(0);103 }104 });105 ponyFrame.add(ponyb_exit);106

107 /*BUTTON_MUTE*/

108 ponyb_mute.setIcon(ponyb_mutei);109 ponyb_mute.setSize(30, 30);110 ponyb_mute.setLocation(img01.getIconWidth()-165, 10);111 ponyb_mute.addActionListener(newActionListener(){112 public voidactionPerformed(ActionEvent e)113 {114 if(ponymute==true)115 {116 ponymute=false;117 ponyb_mute.setIcon(ponyb_nmutei);118 }119 else

120 {121 ponymute=true;122 ponyb_mute.setIcon(ponyb_mutei);123 }124 }125 });126 ponyFrame.add(ponyb_mute);127

128 /*BUTTON_MIN*/

129 ponyb_min.setIcon(ponyb_mini);130 ponyb_min.setSize(30, 30);131 ponyb_min.setLocation(img01.getIconWidth()-85, 10);132 ponyb_min.addActionListener(newActionListener(){133 public voidactionPerformed(ActionEvent e)134 {135 ponyFrame.setState(Frame.ICONIFIED);136 }137 });138 ponyFrame.add(ponyb_min);139

140 /*TEXT*/

141 ponyFrame.add(ponyLabel);142 ponyLabel.setSize(img01.getIconWidth(),img01.getIconHeight());143 ponyLabel.setFont(new Font("",1,82));144 ponyLabel.setForeground(new Color(255,255,255,255));145

146 /*AUDIO*/

147 ponyam=Applet.newAudioClip(ponyurl1);148 ponypm=Applet.newAudioClip(ponyurl2);149

150 /*IMG00*/

151 JLabel Label00 = newJLabel(img00);152 Label00.setSize(img00.getIconWidth(),img00.getIconHeight());153 ponyFrame.add(Label00);154

155 /*IMG01*/

156 JLabel Label01 = newJLabel(img01);157 Label01.setSize(img01.getIconWidth(),img01.getIconHeight());158 ponyFrame.add(Label01);159

160 /*IMG02*/

161 JLabel Label02 = newJLabel(img02);162 Label02.setSize(0,0);163 ponyFrame.add(Label02);164

165 /*IMG03*/

166 JLabel Label03 = newJLabel(img03);167 Label03.setSize(0,0);168 ponyFrame.add(Label03);169

170 /*FINAL*/

171 ponyFrame.setVisible(true);172

173 while(true)174 {175 if(Calendar.getInstance().get(Calendar.MINUTE)==0 && Calendar.getInstance().get(Calendar.SECOND)<=8)176 {177 ponyString=Calendar.getInstance().get(Calendar.HOUR_OF_DAY)+"";178 ponyLabel.setText(ponyString);179 ponyLabel.setForeground(new Color(0,0,0,255));180 Label00.setSize(0,0);181 Label01.setSize(0,0);182 if(Calendar.getInstance().get(Calendar.HOUR_OF_DAY)>=8 && Calendar.getInstance().get(Calendar.HOUR_OF_DAY)<=19)183 {184 Label02.setSize(img02.getIconWidth(),img02.getIconHeight());185 try{186 if(ponymute==false) {ponyam.play();}187 Thread.sleep(15000);188 }catch(InterruptedException e){}189 Label02.setSize(0,0);190 }191 else

192 {193 Label03.setSize(img03.getIconWidth(),img03.getIconHeight());194 try{195 if(ponymute==false) {ponypm.play();}196 Thread.sleep(12000);197 }catch(InterruptedException e){}198 Label03.setSize(0,0);199 }200 ponyLabel.setForeground(new Color(255,255,255,255));201 Label00.setSize(img01.getIconWidth(),img01.getIconHeight());202 Label01.setSize(img01.getIconWidth(),img01.getIconHeight());203 }204 else

205 {206 ponyString=Calendar.getInstance().get(Calendar.HOUR_OF_DAY) + ":" + Calendar.getInstance().get(Calendar.MINUTE) + ":" +Calendar.getInstance().get(Calendar.SECOND);207 ponyLabel.setText(ponyString);208 try{209 Thread.sleep(1000);210 }catch(InterruptedException e){}211 }212 }213 }214

215 }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值