返回列表 發帖
  1. package asdf;

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

  5. import javax.swing.JFrame;
  6. import javax.swing.JPanel;
  7. import javax.swing.border.EmptyBorder;
  8. import javax.swing.GroupLayout;
  9. import javax.swing.GroupLayout.Alignment;
  10. import javax.swing.ImageIcon;
  11. import javax.swing.JLabel;
  12. import javax.swing.JButton;

  13. import java.awt.event.ActionListener;
  14. import java.awt.event.ActionEvent;

  15. public class Asdf extends JFrame {

  16.         private JPanel contentPane;
  17.     private ImageIcon icon;
  18.     private ImageIcon img_fr;
  19.         
  20.         public static void main(String[] args) {
  21.                 EventQueue.invokeLater(new Runnable() {
  22.                         public void run() {
  23.                                 try {
  24.                                             Asdf frame = new Asdf();
  25.                                         frame.setVisible(true);
  26.                                         ImageIcon icon_btn = new ImageIcon(Asdf.class.getResource("earth.png"));
  27.                                         Image img_btn = icon_btn.getImage().getScaledInstance(45, 45, java.awt.Image.SCALE_FAST);
  28.                                         frame.setIconImage(img_btn);
  29.                                 } catch (Exception e) {
  30.                                         e.printStackTrace();
  31.                                 }
  32.                         }
  33.                 });
  34.         }
  35.    
  36.         JLabel lblNewLabel;
  37.         public Asdf() {
  38.                 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  39.                 setBounds(100, 100, 444, 372);
  40.                 contentPane = new JPanel();
  41.                 contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
  42.                 setContentPane(contentPane);
  43.                 contentPane.setLayout(null);
  44.                
  45.         
  46.                
  47.                 lblNewLabel = new JLabel();
  48.                 lblNewLabel.setBounds(0, 0, 429, 293);
  49.                 contentPane.add(lblNewLabel);
  50.                
  51.                 Changeicon("Koala.jpg");
  52.                
  53.                
  54.                 JButton btnNewButton = new JButton(Btnimage("Koala.jpg"));
  55.                 btnNewButton.setBounds(0, 293, 112, 41);
  56.                 contentPane.add(btnNewButton);
  57.                 btnNewButton.addActionListener(new ActionListener() {
  58.              public void actionPerformed(ActionEvent arg0) {
  59.                      Changeicon("Koala.jpg");
  60.              }
  61.                 });                     
  62.                 JButton btnNewButton_1 = new JButton(Btnimage("Chrysanthemum.jpg"));
  63.                 btnNewButton_1.setBounds(110, 293, 112, 41);
  64.                 contentPane.add(btnNewButton_1);
  65.                 btnNewButton_1.addActionListener(new ActionListener() {
  66.             public void actionPerformed(ActionEvent arg0) {
  67.                     Changeicon("Chrysanthemum.jpg");
  68.             }
  69.                 });   
  70.                
  71.                 JButton btnNewButton_2 = new JButton(Btnimage("Desert.jpg"));
  72.                 btnNewButton_2.addActionListener(new ActionListener() {
  73.                         public void actionPerformed(ActionEvent arg0) {
  74.                                 Changeicon("Desert.jpg");
  75.                         }
  76.                 });
  77.                 btnNewButton_2.setBounds(221, 293, 112, 41);
  78.                 contentPane.add(btnNewButton_2);
  79.                
  80.                 JButton btnNewButton_3 = new JButton(Btnimage("Lighthouse.jpg"));
  81.                 btnNewButton_3.addActionListener(new ActionListener() {
  82.                         public void actionPerformed(ActionEvent e) {                        
  83.                                 Changeicon("Lighthouse.jpg");
  84.                         }
  85.                 });
  86.                 btnNewButton_3.setBounds(329, 293, 100, 41);
  87.                 contentPane.add(btnNewButton_3);
  88.                         
  89.         }

  90.         public void Changeicon(String str)
  91.         {        
  92.                 icon = new ImageIcon(Asdf.class.getResource(str));
  93.                 Image img = icon.getImage().getScaledInstance(429, 293, java.awt.Image.SCALE_FAST);
  94.                 ImageIcon newicon = new ImageIcon(img);
  95.                 lblNewLabel.setIcon(newicon);        
  96.         }
  97.         public ImageIcon Btnimage(String str)
  98.         {
  99.                 ImageIcon icon_btn = new ImageIcon(Asdf.class.getResource(str));
  100.                 Image img_btn = icon_btn.getImage().getScaledInstance(45, 45, java.awt.Image.SCALE_FAST);
  101.                 ImageIcon newicon_btn = new ImageIcon(img_btn);
  102.                 return newicon_btn;
  103.         }
  104. }
複製代碼
我是眾神之王XXX  I love you
0000000000

TOP

返回列表