?? picture.java
字號:
/**
* <p>Title:Picture</p>
* <p>Discription:實現圖片的點擊切換</p>
* <p>Disadvantage:</p>
* @author DELL
* @version 1.0
*/
package Project1;
import java.awt.*;
import java.util.*;
import java.text.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class Picture extends JFrame{
private JButton button = new JButton();
private ImageIcon[] myPicture ={
new ImageIcon("D:\\workspace\\pictures\\0.gif"),
new ImageIcon("D:\\workspace\\pictures\\1.gif"),
new ImageIcon("D:\\workspace\\pictures\\2.gif"),
new ImageIcon("D:\\workspace\\pictures\\3.gif"),
new ImageIcon("D:\\workspace\\pictures\\4.gif"),
new ImageIcon("D:\\workspace\\pictures\\5.gif"),
new ImageIcon("D:\\workspace\\pictures\\6.gif"),
new ImageIcon("D:\\workspace\\pictures\\7.gif"),
new ImageIcon("D:\\workspace\\pictures\\8.gif"),
new ImageIcon("D:\\workspace\\pictures\\9.gif"),
};
public JButton run(){
button.setIcon(myPicture[0]);
button.addActionListener(new buttonListener());
return button;
}
class buttonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
Random r = new Random();
int i = r.nextInt(9);
button.setIcon(myPicture[i]);
}
}
public static void main(String[] args){
JFrame frame = new JFrame();
frame.setSize(500, 500);
frame.setVisible(true);
Picture p = new Picture();
p.run();
frame.getContentPane().add(p.run());
p.button.setSize(300, 233);
p.button.setVisible(true);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -