Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7642595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:13:46+00:00 2026-05-31T09:13:46+00:00

I am adding a heater JButton and a heater JSlider to each Tab that

  • 0

I am adding a heater JButton and a heater JSlider to each Tab that I am creating, the heater JButton to turn it off and on and the heater JSlider to choose the temp.

The JSlider status is preset to false, so when I click the heater JButton to turn the heater on,

I need it to set the status of the JSlider to TRUE, how can I access the heater JSlider in the HEATER BUTTON class? and if not what other way is there to do this??.

Any help is appreciated, thanks.

import java.util.ArrayList;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class MasterGUI extends JFrame implements ActionListener{

public MasterGUI(){

}

public void DisplayFrame(){
    ArrayList<Rooms> rooms;
    rooms = Building.getRoomList();

    JFrame master = new JFrame("Solar Master Control Panel"); 
    master.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = master.getContentPane();
    content.setBackground(Color.lightGray);

    JTabbedPane tabbedPane = new JTabbedPane();
    JPanel tmpPanel;

    for(int x = 0; x < rooms.size(); x++){
        tmpPanel = new JPanel();
        String roomName = rooms.get(x).getName();
        int roomId = rooms.get(x).getId();
        tabbedPane.addTab(roomName + " Room " + roomId, tmpPanel);

        for(int i = 0; i < rooms.get(x).roomLights.size(); i++){
            int lightId = rooms.get(x).roomLights.get(i).getId();
            JButton lights = new JButton("Light" + lightId);
            lights.setBackground(Color.red);
            lights.addActionListener(new LightButton(roomId, lightId));
            ((JPanel) tabbedPane.getComponentAt(x)).add(lights);
        }

        JButton heater = new JButton("Heater");
        heater.setBackground(Color.red);
        heater.addActionListener(new HeaterButton(roomId));
        JSlider heaterSlider = new JSlider(68, 73);
        heaterSlider.setPaintTicks(true);
        heaterSlider.setPaintLabels(true);
        heaterSlider.setMajorTickSpacing(1);
        heaterSlider.addChangeListener(new HeaterSlider(roomId));
        heaterSlider.setEnabled(false);
        ((JPanel) tabbedPane.getComponentAt(x)).add(heater);
        ((JPanel) tabbedPane.getComponentAt(x)).add(heaterSlider);
    }
    master.add(tabbedPane, BorderLayout.CENTER);
    master.setSize(800, 600);
    content.add(tabbedPane);
    master.setVisible(true);
}

HEATERBUTTON CLASS

 import java.util.ArrayList;
 import java.awt.*;
 import javax.swing.*;
 import java.awt.event.*;

public class HeaterButton implements ActionListener{
int roomNumber;

public HeaterButton(int room){
roomNumber = room;
}

public void actionPerformed(ActionEvent e){
ArrayList<Rooms> rooms;
rooms = Building.getRoomList();

    if(rooms.get(roomNumber - 1).roomHeater.getHeaterStatus() == true){
        rooms.get(roomNumber - 1).roomHeater.setHeaterOff();
        ((JButton)e.getSource()).setBackground(Color.red);

    }else{
        rooms.get(roomNumber - 1).roomHeater.setHeaterOn();
        ((JButton)e.getSource()).setBackground(Color.green);

    }
}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:13:48+00:00Added an answer on May 31, 2026 at 9:13 am

    Create the slider first and then pass it to the button.

    Change:

     heater.addActionListener(new HeaterButton(roomId)); 
    

    To:

     heater.addActionListener(new HeaterButton(roomId, slider)); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am just adding a account header for my website, that just displays the
My question is quite simple. I'm adding a header to a SOAP request that
In Silver light Tab control ,i have adding custom tab header (name along with
Is there any way of adding a route mapping in Global.asax so that routes
I am creating a button pro-grammatically in my TableView Header cell and adding TouchUpInside
I can't view header in JTable while adding it into a JFrame.. String[] col={Name,ID,Marks};
Adding an element to the head of an alist (Associative list) is simple enough:
Adding source files more than one directory away (e.g. ../../source.cpp or ../../../somewhere_else/source.cpp, vs. just
Adding more than one child to a WPF StatusBar results in poor layout with
Adding Exceptional Handling is a good practise, but I have a doubt, In our

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.