- package bbs.istak.org.tw;
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import java.awt.Image;
- import javax.swing.ImageIcon;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JButton;
- import javax.swing.JLabel;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- public class Test extends JFrame {
- private JPanel contentPane;
- private ImageIcon icon0;
- private ImageIcon icon1;
- private ImageIcon icon2;
- private ImageIcon icon3;
-
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Test frame = new Test();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public Test() {
- icon3 = new ImageIcon(Main.class.getResource("image3.jpg"));
- Image img3 = icon3.getImage().getScaledInstance(376,208,Image.SCALE_FAST);
- ImageIcon newicon3 = new ImageIcon(img3);
-
- icon0 = new ImageIcon(Main.class.getResource("image0.jpg"));
- Image img0 = icon0.getImage().getScaledInstance(376,208,Image.SCALE_FAST);
- ImageIcon newicon0 = new ImageIcon(img0);
-
- icon2 = new ImageIcon(Main.class.getResource("image2.jpg"));
- Image img2 = icon2.getImage().getScaledInstance(376,208,Image.SCALE_FAST);
- ImageIcon newicon2 = new ImageIcon(img2);
-
- icon1 = new ImageIcon(Main.class.getResource("image1.jpg"));
- Image img1 = icon1.getImage().getScaledInstance(376,208,Image.SCALE_FAST);
- ImageIcon newicon1 = new ImageIcon(img1);
-
-
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 412, 300);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
-
- JLabel lblNewLabel = new JLabel(newicon3);
- lblNewLabel.setBounds(10, 10, 376, 208);
- contentPane.add(lblNewLabel);
-
- JButton btnNewButton = new JButton("\u8001\u76AE");
- btnNewButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- lblNewLabel.setIcon(newicon3);
- }
- });
- btnNewButton.setBounds(10, 229, 87, 23);
- contentPane.add(btnNewButton);
-
- JButton btnNewButton_1 = new JButton("\u96F7\u8332");
- btnNewButton_1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- lblNewLabel.setIcon(newicon0);
- }
- });
- btnNewButton_1.setBounds(107, 229, 87, 23);
- contentPane.add(btnNewButton_1);
-
- JButton btnNewButton_2 = new JButton("\u8D85\u7D1A\u9A0E\u58EB");
- btnNewButton_2.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- lblNewLabel.setIcon(newicon2);
- }
- });
- btnNewButton_2.setBounds(201, 229, 87, 23);
- contentPane.add(btnNewButton_2);
-
- JButton btnNewButton_3 = new JButton("\u5716\u502B");
- btnNewButton_3.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- lblNewLabel.setIcon(newicon1);
- }
- });
- btnNewButton_3.setBounds(298, 229, 87, 23);
- contentPane.add(btnNewButton_3);
-
- }
- }
複製代碼 |