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

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

  4. import javax.swing.JFrame;
  5. import javax.swing.JPanel;
  6. import javax.swing.border.EmptyBorder;
  7. import java.awt.GridBagLayout;
  8. import com.jgoodies.forms.layout.FormLayout;
  9. import com.jgoodies.forms.layout.ColumnSpec;
  10. import com.jgoodies.forms.layout.RowSpec;
  11. import javax.swing.GroupLayout;
  12. import javax.swing.GroupLayout.Alignment;
  13. import javax.swing.JTextField;
  14. import javax.swing.JButton;
  15. import java.awt.event.ActionListener;
  16. import java.awt.event.ActionEvent;
  17. import javax.swing.JLabel;
  18. import javax.swing.ImageIcon;

  19. public class Main extends JFrame {

  20.         private JPanel contentPane;

  21.         /**
  22.          * Launch the application.
  23.          */
  24.         public static void main(String[] args) {
  25.                 EventQueue.invokeLater(new Runnable() {
  26.                         public void run() {
  27.                                 try {
  28.                                         Main frame = new Main();
  29.                                         frame.setVisible(true);
  30.                                 } catch (Exception e) {
  31.                                         e.printStackTrace();
  32.                                 }
  33.                         }
  34.                 });
  35.         }

  36.         /**
  37.          * Create the frame.
  38.          */
  39.         public Main() {
  40.                 setTitle("ImageIcon");
  41.                 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  42.                 setBounds(100, 100, 314, 396);
  43.                 contentPane = new JPanel();
  44.                 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  45.                 setContentPane(contentPane);
  46.                 contentPane.setLayout(null);
  47.                
  48.                 JLabel lblNewLabel = new JLabel("Welcome");
  49.                 lblNewLabel.setLabelFor(this);
  50.                 lblNewLabel.setBounds(-1, 0, 296, 276);
  51.                 contentPane.add(lblNewLabel);
  52.                
  53.                 JButton btn2 = new JButton("\u7761\u89BA");
  54.                 btn2.setBounds(142, 274, 153, 39);
  55.                 contentPane.add(btn2);
  56.                
  57.                 JButton btn4 = new JButton("\u554F\u865F");
  58.                 btn4.setBounds(142, 310, 153, 40);
  59.                 contentPane.add(btn4);
  60.                
  61.                 JButton btn3 = new JButton("\u9E1A\u9D61");
  62.                 btn3.setBounds(0, 310, 145, 40);
  63.                 contentPane.add(btn3);
  64.                
  65.                 JButton btn1 = new JButton("\u8C93\u54AA");
  66.                 btn1.setBounds(-1, 274, 145, 38);
  67.                 contentPane.add(btn1);
  68.                
  69.                 JButton icon = new JButton("\u8C93\u54AA");
  70.                 icon.addActionListener(new ActionListener() {       
  71.                        
  72.                         public void actionPerformed(ActionEvent e) {
  73.                        
  74.                                 if(e.getSource()==btn1)                
  75.                                 {
  76.                                         lblNewLabel.setIcon(new ImageIcon("meow.jifi"));
  77.                         }
  78.                                 if(e.getSource()==btn2)
  79.                         {
  80.                                         lblNewLabel.setIcon(new ImageIcon("parrot.png"));
  81.                         }
  82.                                 if(e.getSource()==btn4)
  83.                                 {
  84.                                         lblNewLabel.setIcon(new ImageIcon("qm.jpg"));
  85.                                 }
  86.                                 if(e.getSource()==btn3)
  87.                                 {
  88.                                         lblNewLabel.setIcon(new ImageIcon("sleep.jifi"));
  89.                                 }

  90.                         }
  91.                 });

  92.                
  93.        
  94.                
  95.                        
  96.         }
  97. }
複製代碼

TOP

返回列表