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

  • SEARCH
  • Home
  • 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 6996413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:09:11+00:00 2026-05-27T20:09:11+00:00

Oke so i updated the Question whit the full class included the problem is

  • 0

Oke so i updated the Question whit the full class included the problem is that
even to the function incrementVariables(); is working it is not coloring the consumed amount of total of JProgressBar. JProgressBar will display the correct consumed amount but wont color the JProgressBar.

However is i add the following to the method initUI() { cap_bar.setMaximum(5000); cap_bar.setValue(1000) } then the JProgressBar gets its values set and its colored.

Why isnt JProgressBar getting colored when .setValue() is called in incrementVariables().

ALSO SECOND QUESTION:

From what you can see my Class is a mess i have more Classes that handle additional methods anyhow what is the professional way to approach GUI development i am guessing its not the way i am doing it. I have created my GUI in a separate Class and made all components callable by public variables so i can manipulate them outside that class.

package ept.controller;

import ept.view.EPTMain;
import ept.model.EPTEvent_Model;
import ept.model.EPTLocal_Model;
import ept.model.EPTModule_Model;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.DefaultListModel;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JProgressBar;


public class EPTIndex_Controler {

    public EPTIndex_Controler() {
        initUI();
    }

    //Globals
    protected String selectedTower = null;
    protected Integer selectedModules = 0;

    public void setSelectedTower(String tower){
        this.selectedTower = tower;
    }

    public String getSelectedTower(){
        return this.selectedTower;
    }

    public void setSelectedModules(Integer i){
        this.selectedModules += i;
    }

    public void decrementSelectedModule(Integer i){
        this.selectedModules -= 1;
    }

    public Integer getSelectedModules(){
        return this.selectedModules;
    }

    private void initUI(){
        EPTMain runnable = new EPTMain();

        JLabel towerName = runnable.tower_name;
        JComboBox towerSelect = runnable.tower_selection;

        JLabel shield_ = runnable.shield_amount;
        JLabel armor_  = runnable.armor_amount;
        JLabel em_     = runnable.em_amount;
        JLabel th_     = runnable.th_amount;
        JLabel kn_     = runnable.kn_amount;
        JLabel ex_     = runnable.ex_amount;

        JProgressBar cpu_bar = runnable.cpu_bar;
        JProgressBar cap_bar = runnable.capacitor_bar;

        JList mod_browse = runnable.module_browser;
        JList mod_select = runnable.selected_modules;
        Font decode = new Font("monospaced", Font.PLAIN, 12);
        mod_select.setFont(decode);
        //mod_browse.setFont(decode);

        setTowerName(towerName, towerSelect, shield_, armor_, em_, th_, kn_, ex_, cap_bar, cpu_bar);
        removeTower(towerName, shield_, armor_, em_, th_, kn_, ex_, cap_bar, cpu_bar);

        addModule(mod_browse, mod_select, shield_, armor_, em_, th_, kn_, ex_, cap_bar, cpu_bar);
        removeModule(mod_select, shield_, armor_, em_, th_, kn_, ex_, cap_bar, cpu_bar);

        runnable.setExtendedState(EPTMain.MAXIMIZED_BOTH);
        runnable.setVisible(true);
    }



    protected DefaultListModel struct = new DefaultListModel();

    private void removeModule(final JList select, final JLabel shield_, final JLabel armor_, final JLabel em_, final JLabel th_,
            final JLabel kn_, final JLabel ex_, final JProgressBar cap_bar, final JProgressBar cpu_bar){
        select.addMouseListener(new MouseListener(){
            @Override
            public void mouseClicked(MouseEvent e) {
                String removable = select.getSelectedValue().toString();
                if(e.getClickCount() == 2 && removable.equals("No modules have been selected") == false){
                    String cap = select.getSelectedValue().toString().substring(61, 70).trim();
                    String cpu = select.getSelectedValue().toString().substring(75).trim();
                    Integer D_CAP = Integer.valueOf(cap).intValue();
                    Integer D_CPU = Integer.valueOf(cpu).intValue();
                    decConsumedCap(D_CAP);
                    decConsumedCpu(D_CPU);
                    struct.removeElement(select.getSelectedValue());
                    incrementVariables(shield_, armor_, em_, th_, kn_, ex_, cap_bar, cpu_bar);
                    select.setModel(struct);
                    decrementSelectedModule(1);
                }
            }
            @Override
            public void mousePressed(MouseEvent e) {}
            @Override
            public void mouseReleased(MouseEvent e) {}
            @Override
            public void mouseEntered(MouseEvent e) {}
            @Override
            public void mouseExited(MouseEvent e) {}
        });
    }

    private void addModule(final JList browse, final JList select, final JLabel shield_, final JLabel armor_, final JLabel em_, final JLabel th_,
            final JLabel kn_, final JLabel ex_, final JProgressBar cap_bar, final JProgressBar cpu_bar){
        browse.addMouseListener(new MouseListener(){
            @Override
            public void mouseClicked(MouseEvent e) {
                String addable = browse.getSelectedValue().toString();
                if(e.getClickCount() == 2 && getSelectedTower() != null && addable.charAt(0) == ' '){
                    String data[] = new EPTModule_Model().moduleData(addable.trim());
                    String module = data[0];
                    Integer capacitor = Integer.valueOf(data[1]).intValue(); setConsumedCap(capacitor);
                    Integer cpu = Integer.valueOf(data[2]).intValue(); setConsumedCpu(cpu);
                    String module_cap = data[1];
                    String module_cpu = data[2];
                    struct.addElement(String.format("> %-47s Capacitor: %-8s CPU: %s", module, module_cap, module_cpu));
                    select.setModel(struct);
                    setSelectedModules(1);
                    incrementVariables(shield_, armor_, em_, th_, kn_, ex_, cap_bar, cpu_bar);
                } else if (e.getClickCount() == 2 && getSelectedTower() == null){
                    new EPTEvent_Model().eventNoTowerSelected();
                }
            }
            @Override
            public void mousePressed(MouseEvent e) {}
            @Override
            public void mouseReleased(MouseEvent e) {}
            @Override
            public void mouseEntered(MouseEvent e) {}
            @Override
            public void mouseExited(MouseEvent e) {}
        });
    }

    private void removeTower(final JLabel type, final JLabel shield_, final JLabel armor_, final JLabel em_, final JLabel th_,
            final JLabel kn_, final JLabel ex_, final JProgressBar cap_bar, final JProgressBar cpu_bar){
        type.addMouseListener(new MouseListener(){
            @Override
            public void mouseClicked(MouseEvent e) {
                if(getSelectedModules() == 0){
                    type.setText("No Control Tower Selected");
                    setSelectedTower(null);
                    resetVariables(shield_, armor_, em_, th_, kn_, ex_, cap_bar, cpu_bar);
                } else {
                    new EPTEvent_Model().eventModuleSelected();
                }
            }
            @Override
            public void mousePressed(MouseEvent e) {}
            @Override
            public void mouseReleased(MouseEvent e) {}
            @Override
            public void mouseEntered(MouseEvent e) {}
            @Override
            public void mouseExited(MouseEvent e) {}    
        });
    }

    private void setTowerName(final JLabel type, final JComboBox type2, final JLabel shield_, final JLabel armor_, final JLabel em_, final JLabel th_,
            final JLabel kn_, final JLabel ex_, final JProgressBar cap_bar, final JProgressBar cpu_bar){
        type2.addActionListener(new ActionListener(){
            @Override
            public void actionPerformed(ActionEvent e) {
                if(getSelectedTower() != null){
                    new EPTEvent_Model().eventTowerSelected();
                } else {
                    setSelectedTower(type2.getSelectedItem().toString());
                    new EPTDispatch_Controler(type, type2.getSelectedItem().toString());
                    updateVariables(shield_, armor_, em_, th_, kn_, ex_, cap_bar, cpu_bar);

                }
            }
        });
    }

    //Referenced Globals
    protected int cap = 0;
    protected int consumed_cap = 0;
    protected int cpu = 0;
    protected int consumed_cpu = 0;

    public void setCap(int cap){
        this.cap = cap;
    }

    public int getCap(){
        return this.cap;
    }

    public void setCpu(int cpu){
        this.cpu = cpu;
    }

    public int getCpu(){
        return this.cpu;
    }

    public void resetConsumed(){
        this.consumed_cap = 0;
        this.consumed_cpu = 0;
    }

    public void setConsumedCap(int consumed_cap){
        this.consumed_cap += consumed_cap;
    }

    public void decConsumedCap(int consumed_cap){
        this.consumed_cap -= consumed_cap;
    }

    public int getConsumedCap(){
        return this.consumed_cap;
    }

    public void setConsumedCpu(int consumed_cpu){
        this.consumed_cpu += consumed_cpu;
    }

    public void decConsumedCpu(int consumed_cpu){
        this.consumed_cpu -= consumed_cpu;
    }

    public int getConsumedCpu(){
        return this.consumed_cpu;
    }

    //Referenced Globals
    protected int shield = 0;
    protected int armor = 0;
    protected double em = 00.00;
    protected double th = 00.00;
    protected double kn = 00.00;
    protected double ex = 00.00;

    public void setEm(double em){
        this.em = em;
    }

    public double getEm(){
        return this.em;
    }

    public void setTh(double th){
        this.th = th;
    }

    public double getTh(){
        return this.th;
    }

    public void setKn(double kn){
        this.kn = kn;
    }

    public double getKn(){
        return this.kn;
    }

    public void setEx(double ex){
        this.ex = ex;
    }

    public double getEx(){
        return this.ex;
    }

    public void setShield(int shield){
        this.shield = shield;
    }

    public int getShield(){
        return this.shield;
    }

    public void setArmor(int armor){
        this.armor = armor;
    }

    public int getArmor(){
        return this.armor;
    }

    private void setCL(JProgressBar t, int i){
        t.setValue(i);
    }

    private void incrementVariables(final JLabel shield_, final JLabel armor_, final JLabel em_, final JLabel th_,
            final JLabel kn_, final JLabel ex_, final JProgressBar cap_bar, final JProgressBar cpu_bar){

        cap_bar.setMaximum(getCap());
        cap_bar.setValue(getConsumedCap());
        cap_bar.setString(getConsumedCap() + " / " + getCap());
        cap_bar.setStringPainted(true);



        cpu_bar.setMaximum(getCpu());
        cpu_bar.setString(getConsumedCpu() + " / " + getCpu());
        cpu_bar.setStringPainted(true);
        cap_bar.setValue(getConsumedCpu());

        String shieldA = String.valueOf(getShield()).toString();
        shield_.setText(shieldA);

        String armorA = String.valueOf(getArmor()).toString();
        armor_.setText(armorA);

        double e = getEm();
        String emT = String.valueOf(e);
        em_.setText(emT);

        double t = getTh();
        String thT = String.valueOf(t);
        th_.setText(thT);

        double k = getKn();
        String knT = String.valueOf(k);
        kn_.setText(knT);

        double x = getEx();
        String exT = String.valueOf(x);
        ex_.setText(exT);

    }

    private void updateVariables(final JLabel shield_, final JLabel armor_, final JLabel em_, final JLabel th_,
            final JLabel kn_, final JLabel ex_, final JProgressBar cap_bar, final JProgressBar cpu_bar){

        String data[] = new EPTLocal_Model().serializeData(getSelectedTower());

        Integer capA = Integer.valueOf(data[1]).intValue();
        setCap(capA);
        cap_bar.setMaximum(getCap());
        cap_bar.setString(getConsumedCap() + " / " + getCap());
        cap_bar.setValue(getConsumedCap());
        cap_bar.setStringPainted(true);

        Integer cpuA = Integer.valueOf(data[2]).intValue();
        setCpu(cpuA);
        cpu_bar.setMaximum(getCpu());
        cpu_bar.setString(getConsumedCpu() + " / " + getCpu());
        cpu_bar.setValue(getConsumedCpu());
        cpu_bar.setStringPainted(true);

        Integer shieldAmount = Integer.valueOf(data[3]).intValue();
        setShield(shieldAmount);
        shield_.setText(data[3]);

        Integer armorAmount = Integer.valueOf(data[4]).intValue();
        setArmor(armorAmount);
        armor_.setText(data[4]);

        Double emT = Double.valueOf(data[5]).doubleValue();
        setEm(emT);
        em_.setText(data[5]);

        Double thT = Double.valueOf(data[6]).doubleValue();
        setTh(thT);
        th_.setText(data[6]);

        Double knT = Double.valueOf(data[7]).doubleValue();
        setKn(knT);
        kn_.setText(data[7]);

        Double exT = Double.valueOf(data[8]).doubleValue();
        setEx(exT);
        ex_.setText(data[8]);

    }

    private void resetVariables(final JLabel shield_, final JLabel armor_, final JLabel em_, final JLabel th_,
            final JLabel kn_, final JLabel ex_, final JProgressBar cap_bar, final JProgressBar cpu_bar){

        resetConsumed();

        setCap(0);
        cap_bar.setMaximum(getCap());
        cap_bar.setString(getConsumedCap() + " / " + getCap());
        cap_bar.setStringPainted(true);

        setCpu(0);
        cpu_bar.setMaximum(getCpu());
        cpu_bar.setString(getConsumedCpu() + " / " + getCpu());
        cpu_bar.setStringPainted(true);

        setShield(0);
        shield_.setText("0");

        setArmor(0);
        armor_.setText("0");

        setEm(00.00);
        em_.setText("00.00");

        setTh(00.00);
        th_.setText("00.00");

        setKn(00.00);
        kn_.setText("00.00");

        setEx(00.00);
        ex_.setText("00.00");

    }

}
  • 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-27T20:09:12+00:00Added an answer on May 27, 2026 at 8:09 pm

    Swing GUI is single threaded and has one general rule about all events must be done on EDT,

    1) long answer is clearly described more in the Concurrency in Swing and JProgressBar,

    2) short answer you have to invoke in/decreasing value for JProgressBar from SwingWorker or Runnable#Thread, but then is required wraping output to the GUI into invokeLater()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Oke my website works with Facebook Api, it will import all the friends (userId,
After 2+ hours of looking WHY my bloody process would not exit when I
I'm using the PHP native mail() function to send HTML emails and have a
I created a (very simple) class wich gets a string value from an intent.
I have a problem in revealing the actual results of the radio buttons. I
I can't imagine that there doesn't exist an efficient, lightweight, secure authentication and authorization
I have searched a lot about UTF8 decoding, but not found the answer yet.
Have have a question about FLV files, do FLV files stream when you post
I have a jQuery code: $('.team-leader-id').delegate('button', 'click', function() { var parent_object = $(this); var
I have got the resize thing working but when i use the pie chart

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.