返回列表 發帖
  1. package bbs.istak.org.tw;

  2. import java.awt.BorderLayout;
  3. import java.awt.EventQueue;
  4. import java.awt.Image;

  5. import javax.swing.ImageIcon;
  6. import javax.swing.JFrame;
  7. import javax.swing.JPanel;
  8. import javax.swing.border.EmptyBorder;
  9. import javax.swing.JButton;
  10. import javax.swing.JLabel;
  11. import java.awt.event.ActionListener;
  12. import java.awt.event.ActionEvent;

  13. public class Test extends JFrame {

  14.         private JPanel contentPane;
  15.         private ImageIcon icon0;
  16.         private ImageIcon icon1;
  17.         private ImageIcon icon2;
  18.     private ImageIcon icon3;
  19.        
  20.         /**
  21.          * Launch the application.
  22.          */
  23.         public static void main(String[] args) {
  24.                 EventQueue.invokeLater(new Runnable() {
  25.                         public void run() {
  26.                                 try {
  27.                                         Test frame = new Test();
  28.                                         frame.setVisible(true);
  29.                                 } catch (Exception e) {
  30.                                         e.printStackTrace();
  31.                                 }
  32.                         }
  33.                 });
  34.         }

  35.         /**
  36.          * Create the frame.
  37.          */
  38.         public Test() {
  39.                  icon3 = new ImageIcon(Main.class.getResource("image3.jpg"));
  40.          Image img3 = icon3.getImage().getScaledInstance(376,208,Image.SCALE_FAST);
  41.          ImageIcon newicon3 = new ImageIcon(img3);
  42.                
  43.          icon0 = new ImageIcon(Main.class.getResource("image0.jpg"));
  44.          Image img0 = icon0.getImage().getScaledInstance(376,208,Image.SCALE_FAST);
  45.          ImageIcon newicon0 = new ImageIcon(img0);
  46.                
  47.          icon2 = new ImageIcon(Main.class.getResource("image2.jpg"));
  48.          Image img2 = icon2.getImage().getScaledInstance(376,208,Image.SCALE_FAST);
  49.          ImageIcon newicon2 = new ImageIcon(img2);
  50.                
  51.          icon1 = new ImageIcon(Main.class.getResource("image1.jpg"));
  52.          Image img1 = icon1.getImage().getScaledInstance(376,208,Image.SCALE_FAST);
  53.          ImageIcon newicon1 = new ImageIcon(img1);
  54.                
  55.                
  56.                 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  57.                 setBounds(100, 100, 412, 300);
  58.                 contentPane = new JPanel();
  59.                 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  60.                 setContentPane(contentPane);
  61.                 contentPane.setLayout(null);
  62.                
  63.                 JLabel lblNewLabel = new JLabel(newicon3);
  64.                 lblNewLabel.setBounds(10, 10, 376, 208);
  65.                 contentPane.add(lblNewLabel);
  66.                
  67.                 JButton btnNewButton = new JButton("\u8001\u76AE");
  68.                 btnNewButton.addActionListener(new ActionListener() {
  69.                         public void actionPerformed(ActionEvent arg0) {
  70.                                 lblNewLabel.setIcon(newicon3);
  71.                         }
  72.                 });
  73.                 btnNewButton.setBounds(10, 229, 87, 23);
  74.                 contentPane.add(btnNewButton);
  75.                
  76.                 JButton btnNewButton_1 = new JButton("\u96F7\u8332");
  77.                 btnNewButton_1.addActionListener(new ActionListener() {
  78.                         public void actionPerformed(ActionEvent e) {
  79.                                 lblNewLabel.setIcon(newicon0);
  80.                         }
  81.                 });
  82.                 btnNewButton_1.setBounds(107, 229, 87, 23);
  83.                 contentPane.add(btnNewButton_1);
  84.                
  85.                 JButton btnNewButton_2 = new JButton("\u8D85\u7D1A\u9A0E\u58EB");
  86.                 btnNewButton_2.addActionListener(new ActionListener() {
  87.                         public void actionPerformed(ActionEvent e) {
  88.                                 lblNewLabel.setIcon(newicon2);
  89.                         }
  90.                 });
  91.                 btnNewButton_2.setBounds(201, 229, 87, 23);
  92.                 contentPane.add(btnNewButton_2);
  93.                
  94.                 JButton btnNewButton_3 = new JButton("\u5716\u502B");
  95.                 btnNewButton_3.addActionListener(new ActionListener() {
  96.                         public void actionPerformed(ActionEvent e) {
  97.                                 lblNewLabel.setIcon(newicon1);
  98.                         }
  99.                 });
  100.                 btnNewButton_3.setBounds(298, 229, 87, 23);
  101.                 contentPane.add(btnNewButton_3);
  102.        
  103.         }
  104. }
複製代碼

TOP

返回列表