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 6863313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:46:03+00:00 2026-05-27T02:46:03+00:00

So I have this class. We’ll call it ProcessBox. I have another class called

  • 0

So I have this class. We’ll call it ProcessBox. I have another class called Process that has a ProcessBox as a member variable. Then, in my main method I have an ArrayList of Process objects (each having their own ProcessBox). How would I go about making it so that my ProcessBox would update every x ms (where x is user specified. I already have the listener for inputting x done). Below is my ProcessBox class. This is what I wish to redraw every x ms (except a whole list of them).

import java.awt.*;

import javax.swing.*;
import javax.swing.border.LineBorder;

import java.util.*;

public class ProcessBox extends JPanel {
    GridBagLayout gbc_panel;

    public ProcessBox(Process p) {
        super(new GridBagLayout());
        gbc_panel = new GridBagLayout();
        gbc_panel.columnWidths = new int[] { 0, 0, 0 };
        gbc_panel.rowHeights = new int[] { 0, 0, 0, 0, 0, 0 };
        gbc_panel.columnWeights = new double[] { 0, 0, Double.MIN_VALUE };
        gbc_panel.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0,
                Double.MIN_VALUE };
        super.setLayout(gbc_panel);


        setPreferredSize(new Dimension(110, 110));
        setMinimumSize(new Dimension(110, 110));
        setAlignmentX(Component.LEFT_ALIGNMENT);
        setBorder(new LineBorder(new Color(0, 0, 0), 1));
        setSize(new Dimension(110, 110));

        String name = p.getName();
        int priority = p.getPriority();
        int minPriority = p.getMinPriority();
        ArrayList<Integer> times = p.getTime();
        Random r = new Random(System.currentTimeMillis());
        setBackground(new Color(r.nextInt(255 - 210) + 210,
                r.nextInt(255 - 210) + 210, r.nextInt(255 - 210) + 210));

        JLabel lblNewLabel = new JLabel("ID:");
        GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
        gbc_lblNewLabel.gridheight = 2;
        gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
        gbc_lblNewLabel.gridx = 0;
        gbc_lblNewLabel.gridy = 0;
        add(lblNewLabel, gbc_lblNewLabel);

        JLabel lblNewLabel_1 = new JLabel(name);
        GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints();
        gbc_lblNewLabel_1.gridheight = 2;
        gbc_lblNewLabel_1.insets = new Insets(0, 0, 5, 0);
        gbc_lblNewLabel_1.gridx = 1;
        gbc_lblNewLabel_1.gridy = 0;
        add(lblNewLabel_1, gbc_lblNewLabel_1);

        JLabel lblNewLabel_2 = new JLabel("Priority:");
        GridBagConstraints gbc_lblNewLabel_2 = new GridBagConstraints();
        gbc_lblNewLabel_2.insets = new Insets(0, 0, 5, 5);
        gbc_lblNewLabel_2.gridx = 0;
        gbc_lblNewLabel_2.gridy = 2;
        add(lblNewLabel_2, gbc_lblNewLabel_2);

        JLabel lblNum = new JLabel(Integer.toString(priority));
        GridBagConstraints gbc_lblNum = new GridBagConstraints();
        gbc_lblNum.insets = new Insets(0, 0, 5, 0);
        gbc_lblNum.gridx = 1;
        gbc_lblNum.gridy = 2;
        add(lblNum, gbc_lblNum);

        JLabel lblNewLabel_3 = new JLabel("Min:");
        GridBagConstraints gbc_lblNewLabel_3 = new GridBagConstraints();
        gbc_lblNewLabel_3.insets = new Insets(0, 0, 5, 5);
        gbc_lblNewLabel_3.gridx = 0;
        gbc_lblNewLabel_3.gridy = 3;
        add(lblNewLabel_3, gbc_lblNewLabel_3);

        JLabel lblMp = new JLabel(Integer.toString(minPriority));
        GridBagConstraints gbc_lblMp = new GridBagConstraints();
        gbc_lblMp.insets = new Insets(0, 0, 5, 0);
        gbc_lblMp.gridx = 1;
        gbc_lblMp.gridy = 3;
        add(lblMp, gbc_lblMp);

        JLabel lblTimeSlice = new JLabel("Slice:");
        GridBagConstraints gbc_lblTimeSlice = new GridBagConstraints();
        gbc_lblTimeSlice.insets = new Insets(0, 0, 0, 5);
        gbc_lblTimeSlice.gridx = 0;
        gbc_lblTimeSlice.gridy = 4;
        add(lblTimeSlice, gbc_lblTimeSlice);

        JLabel lblLeft = new JLabel(Integer.toString(times.get(0)));
        GridBagConstraints gbc_lblLeft = new GridBagConstraints();
        gbc_lblLeft.gridx = 1;
        gbc_lblLeft.gridy = 4;
        add(lblLeft, gbc_lblLeft);
        setVisible(true);

}

}

  • 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-27T02:46:04+00:00Added an answer on May 27, 2026 at 2:46 am

    Start with How to Use Swing Timers and look at examples, e.g. MarqueeTest or AnimationTest.

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

Sidebar

Related Questions

I have this class called Hero that has the following attributes. String is for
I have this class mapped as a entity, lets call it Person. Person has
I have this class that everytime I call the constructor should increment the id
I have this class called Table: class Table { public string Name { get
i have this class called MemoryManager, it is supposed to implement a simple smart
I have this class called SiteAsyncDownload.cs Here's the code: public class SiteAsyncDownloader { WebClient
I have this class that have a function to load other classes and create
I have this class that contains vars for db connection; Imports Microsoft.VisualBasic Imports System.Data.SqlClient
I have this class that I wanted to build using TDD, but I failed.
I have this class: public class Test { public static void main(String[] args) {

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.