Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package newpackage;
- import java.awt.Color; // อิมพอต ให้สามารถ ใส่สี bg ได้
- //import javax.swing.Icon;
- import javax.swing.ImageIcon; // สร้าง เพื่อให้ใส่ภาพ icon ได้
- public class Toggle extends javax.swing.JFrame {
- public Toggle() {
- initComponents();
- }
- private void Toggle1ActionPerformed(java.awt.event.ActionEvent evt) {
- if(Toggle1.isSelected()){ // ให้มันอ่านค่าว่า ถ้าถูกผิด
- Toggle1.setText(" Mute !! "); // เมื่อเพิ่ม set text จะทำ กดครั้งที่ 1 เป็น Mute
- Toggle1.setBackground(Color.red); // เปลี่ยนสี bg เป็นสีแดง
- ImMic.setIcon(new ImageIcon(getClass().getResource("/Images/micoff.png"))); // เพิ่มรูปภาพ getClass ใช้ข้ามคลาส แล้วไปดูที่อยู่ใน
- }else{ // ถ้า
- Toggle1.setText(" Open !! ");
- Toggle1.setBackground(Color.green); // คลิกอีกครั้ง
- ImMic.setIcon(new ImageIcon(getClass().getResource("/Images/micon.png"))); // เหมือนเดิมครับใส่ภาพ
- }
- }
- private void ImMicAncestorAdded(javax.swing.event.AncestorEvent evt) {
- }
- private void Toggle2ActionPerformed(java.awt.event.ActionEvent evt) {
- if(Toggle2.isSelected()){
- Toggle2.setText(" Mute !! ");
- Toggle2.setBackground(Color.red);
- ImVolume.setIcon(new ImageIcon(getClass().getResource("/Images/volumemute.png")));
- }else{
- Toggle2.setText(" Open !! ");
- Toggle2.setBackground(Color.green);
- ImVolume.setIcon(new ImageIcon(getClass().getResource("/Images/volumeon.png")));
- }
- }
- public static void main(String args[]) {
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new Toggle().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JLabel ImMic;
- private javax.swing.JLabel ImVolume;
- private javax.swing.JLabel LabelTextMic;
- private javax.swing.JLabel LabelTextVolume;
- private javax.swing.JToggleButton Toggle1;
- private javax.swing.JToggleButton Toggle2;
- private javax.swing.JPanel jPanel1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement