- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import java.awt.Image;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.GroupLayout;
- import javax.swing.GroupLayout.Alignment;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import javax.swing.LayoutStyle.ComponentPlacement;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import javax.swing.JProgressBar;
- import javax.swing.JLabel;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- public class PHOTO extends JFrame {
- private JPanel contentPane;
- /**
- * Launch the application.
- */
-
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- PHOTO frame = new PHOTO();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public PHOTO() {
- setTitle("ImageIcon\u985E\u5225");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 450, 300);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- JLabel label_image = new JLabel("");
- label_image.setBounds(0, 10, 431, 198);
- contentPane.add(label_image);
-
- JButton button = new JButton("\u7121\u5C3E\u718A");
- button.addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent e)
- {
-
- ImageIcon icon = new ImageIcon(PHOTO.class.getResource("Koala.jpg"));
-
- Image img = icon.getImage().getScaledInstance(431,198,Image.SCALE_FAST);
- ImageIcon newIcon = new ImageIcon(img);
- label_image.setIcon(newIcon);
-
- }
- });
- button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- }
- });
- button.setBounds(5, 218, 100, 39);
-
- JButton button_1 = new JButton("\u4F01\u9D5D");
- button_1.addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent e) {
- ImageIcon icon = new ImageIcon(PHOTO.class.getResource("Penguins.jpg"));
-
- Image img = icon.getImage().getScaledInstance(431,198,Image.SCALE_FAST);
- ImageIcon newIcon = new ImageIcon(img);
- label_image.setIcon(newIcon);
- }
- });
- button_1.setBounds(115, 218, 100, 39);
- button_1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- }
- });
-
- JButton button_2 = new JButton("\u6C99\u6F20");
- button_2.addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent e) {
- ImageIcon icon = new ImageIcon(PHOTO.class.getResource("Desert.jpg"));
-
- Image img = icon.getImage().getScaledInstance(431,198,Image.SCALE_FAST);
- ImageIcon newIcon = new ImageIcon(img);
- label_image.setIcon(newIcon);
- }
- });
- button_2.setBounds(225, 218, 100, 39);
- button_2.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- }
- });
-
- JButton button_3 = new JButton("\u71C8\u5854");
- button_3.addMouseListener(new MouseAdapter() {
- @Override
- public void mousePressed(MouseEvent e) {
- ImageIcon icon = new ImageIcon(PHOTO.class.getResource("Lighthouse.jpg"));
- Image img = icon.getImage().getScaledInstance(431,198,Image.SCALE_FAST);
- ImageIcon newIcon = new ImageIcon(img);
- label_image.setIcon(newIcon);
- }
- });
- button_3.setBounds(331, 218, 100, 39);
- contentPane.setLayout(null);
- contentPane.add(button);
- contentPane.add(button_1);
- contentPane.add(button_2);
- contentPane.add(button_3);
-
-
- }
- }
複製代碼 |