- package bbs.istak.org.tw;
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import java.awt.GridBagLayout;
- import com.jgoodies.forms.layout.FormLayout;
- import com.jgoodies.forms.layout.ColumnSpec;
- import com.jgoodies.forms.layout.RowSpec;
- import javax.swing.GroupLayout;
- import javax.swing.GroupLayout.Alignment;
- import javax.swing.JTextField;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import javax.swing.JLabel;
- import javax.swing.ImageIcon;
- public class Main extends JFrame {
- private JPanel contentPane;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Main frame = new Main();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public Main() {
- setTitle("ImageIcon");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 314, 396);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
-
- JLabel lblNewLabel = new JLabel("Welcome");
- lblNewLabel.setLabelFor(this);
- lblNewLabel.setBounds(-1, 0, 296, 276);
- contentPane.add(lblNewLabel);
-
- JButton btn2 = new JButton("\u7761\u89BA");
- btn2.setIcon(new ImageIcon(Main.class.getResource("/bbs/istak/org/tw/parrot.png")));
- btn2.setBounds(142, 274, 153, 39);
- contentPane.add(btn2);
-
- JButton btn4 = new JButton("\u554F\u865F");
- btn4.setIcon(new ImageIcon("C:\\Users\\15LiveTW\\Downloads\\sleep.jfif"));
- btn4.setBounds(142, 310, 153, 40);
- contentPane.add(btn4);
-
- JButton btn3 = new JButton("\u9E1A\u9D61");
- btn3.setIcon(new ImageIcon(Main.class.getResource("/bbs/istak/org/tw/qm.jpg")));
- btn3.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- }
- });
- btn3.setBounds(0, 310, 145, 40);
- contentPane.add(btn3);
-
- JButton btn1 = new JButton("\u8C93\u54AA");
- btn1.setIcon(new ImageIcon("C:\\Users\\15LiveTW\\Downloads\\meow.jfif"));
- btn1.setBounds(-1, 274, 145, 38);
- contentPane.add(btn1);
-
- JButton icon = new JButton("\u8C93\u54AA");
- icon.addActionListener(new ActionListener() {
-
- public void actionPerformed(ActionEvent e) {
-
- if(e.getSource()==btn1)
- {
- lblNewLabel.setIcon(new ImageIcon("meow.jifi"));
- }
- if(e.getSource()==btn2)
- {
- lblNewLabel.setIcon(new ImageIcon("parrot.png"));
- }
- if(e.getSource()==btn4)
- {
- lblNewLabel.setIcon(new ImageIcon("qm.jpg"));
- }
- if(e.getSource()==btn3)
- {
- lblNewLabel.setIcon(new ImageIcon("sleep.jifi"));
- }
- }
- });
-
-
-
-
- }
- }
複製代碼 |