- 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 static ImageIcon icon;
- private static ImageIcon iconsm;
- private static JLabel lblNewLabel;
- private static ImageIcon ICON1;
- /**
- * 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() {
- ICON1 = new ImageIcon(Main.class.getResource("icon4.png"));
- Image img1 = ICON1.getImage().getScaledInstance(376,208,Image.SCALE_FAST);
-
- setIconImage(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);
-
- lblNewLabel = new JLabel();
- lblNewLabel.setBounds(10, 10, 376, 208);
- contentPane.add(lblNewLabel);
-
- JButton btnNewButton = new JButton();
- btnNewButton.setIcon(ciconsm("image3.jpg"));
- btnNewButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- cicon("image3.jpg");
- }
- });
- btnNewButton.setBounds(10, 229, 87, 30);
- contentPane.add(btnNewButton);
-
- JButton btnNewButton_1 = new JButton();
- btnNewButton_1.setIcon(ciconsm("image0.jpg"));
- btnNewButton_1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- cicon("image0.jpg");
- }
- });
- btnNewButton_1.setBounds(107, 229, 87, 30);
- contentPane.add(btnNewButton_1);
-
- JButton btnNewButton_2 = new JButton();
- btnNewButton_2.setIcon(ciconsm("image2.jpg"));
- btnNewButton_2.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- cicon("image2.jpg");
- }
- });
- btnNewButton_2.setBounds(201, 229, 87, 30);
- contentPane.add(btnNewButton_2);
-
- JButton btnNewButton_3 = new JButton();
- btnNewButton_3.setIcon(ciconsm("image1.jpg"));
- btnNewButton_3.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- cicon("image1.jpg");
- }
- });
- btnNewButton_3.setBounds(298, 229, 87, 30);
- contentPane.add(btnNewButton_3);
-
-
- }
- public static void cicon (String str){
- icon = new ImageIcon(Main.class.getResource(str));
- Image img = icon.getImage().getScaledInstance(376,208,Image.SCALE_FAST);
- ImageIcon newicon = new ImageIcon(img);
- lblNewLabel.setIcon(newicon);
-
- }
- public static ImageIcon ciconsm (String str){
- iconsm = new ImageIcon(Main.class.getResource(str));
- Image imgsm = iconsm.getImage().getScaledInstance(47,26,Image.SCALE_FAST);
- ImageIcon newiconsm = new ImageIcon(imgsm);
- return newiconsm;
-
- }
- }
複製代碼 |