Advertisement
Guest User

Untitled

a guest
Apr 30th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.74 KB | None | 0 0
  1.  
  2. package newpackage;
  3. import java.awt.Color;       // อิมพอต ให้สามารถ ใส่สี bg ได้
  4. //import javax.swing.Icon;
  5. import javax.swing.ImageIcon; // สร้าง เพื่อให้ใส่ภาพ icon ได้
  6.  
  7.  
  8.  
  9.  
  10.  
  11. public class Toggle extends javax.swing.JFrame {
  12.  
  13.     public Toggle() {
  14.         initComponents();
  15.     }
  16.     private void Toggle1ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  17.         if(Toggle1.isSelected()){ // ให้มันอ่านค่าว่า ถ้าถูกผิด
  18.         Toggle1.setText(" Mute !! "); // เมื่อเพิ่ม set text จะทำ กดครั้งที่ 1 เป็น Mute
  19.         Toggle1.setBackground(Color.red); // เปลี่ยนสี bg เป็นสีแดง
  20.         ImMic.setIcon(new ImageIcon(getClass().getResource("/Images/micoff.png"))); // เพิ่มรูปภาพ  getClass ใช้ข้ามคลาส แล้วไปดูที่อยู่ใน
  21.      
  22.        
  23.         }else{ // ถ้า
  24.         Toggle1.setText(" Open !! ");
  25.         Toggle1.setBackground(Color.green); // คลิกอีกครั้ง
  26.         ImMic.setIcon(new ImageIcon(getClass().getResource("/Images/micon.png"))); // เหมือนเดิมครับใส่ภาพ
  27.        }
  28.  
  29.     }                                      
  30.  
  31.     private void ImMicAncestorAdded(javax.swing.event.AncestorEvent evt) {                                    
  32.        
  33.     }                                  
  34.  
  35.     private void Toggle2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
  36.         if(Toggle2.isSelected()){
  37.         Toggle2.setText(" Mute !! ");
  38.         Toggle2.setBackground(Color.red);
  39.         ImVolume.setIcon(new ImageIcon(getClass().getResource("/Images/volumemute.png")));
  40.        
  41.     }else{
  42.         Toggle2.setText(" Open !! ");
  43.         Toggle2.setBackground(Color.green);
  44.         ImVolume.setIcon(new ImageIcon(getClass().getResource("/Images/volumeon.png")));
  45.        }
  46.  
  47.     }                                      
  48.  
  49.    
  50.     public static void main(String args[]) {
  51.  java.awt.EventQueue.invokeLater(new Runnable() {
  52.             public void run() {
  53.                 new Toggle().setVisible(true);
  54.             }
  55.         });
  56.     }
  57.  
  58.     // Variables declaration - do not modify                    
  59.     private javax.swing.JLabel ImMic;
  60.     private javax.swing.JLabel ImVolume;
  61.     private javax.swing.JLabel LabelTextMic;
  62.     private javax.swing.JLabel LabelTextVolume;
  63.     private javax.swing.JToggleButton Toggle1;
  64.     private javax.swing.JToggleButton Toggle2;
  65.     private javax.swing.JPanel jPanel1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement