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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:04:09+00:00 2026-06-06T00:04:09+00:00

I’m trying to program my first GUI-class in Java, using the Window Builder. Ok,

  • 0

I’m trying to program my first GUI-class in Java, using the Window Builder. Ok, the GUI is ready but has no functions yet (it contains 10 checkboxes (yes, they are all neccessary) and 2 buttons and a JTextField, so nothing special). So I just drag’n’dropped the checkboxes and button into the window, I haven’t coded anything yet.

I have two classes:
GUI.java -> only for the layout
Main.java -> should get ‘inputs’ from GUI.java

Now the user should check or uncheck the checkboxes and then finally press a button.

But how do I ‘read out’ if a checkbox is checked or not – I have two classes?

I have to add that I’m a beginner to Java and especially to GUI-programming, but I just want to learn it. I would be happy to receive some help but NOT the complete code.

  • 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-06-06T00:04:10+00:00Added an answer on June 6, 2026 at 12:04 am

    I know you said you didn’t want the full, code but this isn’t really it, just a very basic working demo of what you want to do

    enter image description here

    Gui.java

    import java.awt.event.ActionListener;
    import javax.swing.JButton;
    import javax.swing.JCheckBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    
    public class Gui {
    JFrame frame;
    JButton button;
    JCheckBox checkBox;
    JLabel label;
    
    public Gui() {
        frame = new JFrame("demo");
        button = new JButton("is it checked?");
        checkBox = new JCheckBox();
        label = new JLabel("no");
        JPanel panel = new JPanel();
        panel.add(checkBox);
        panel.add(button);
        panel.add(label);
        frame.add(panel);
        frame.pack();
        //frame.setSize(200, 60);
        frame.setResizable(false);
        frame.setLocation(400, 400);
        frame.setVisible(true);
    }
    
    // method to add an action listener to the gui's
    // private button
    public void setButtonActionListener(ActionListener al) {
        button.addActionListener(al);
    }
    
    // gui method to check if box is checked
    public boolean isBoxChecked() {
        return checkBox.isSelected();
    }
    
    // method to set lable
    public void setText(String text) {
        label.setText(text);
    }
    
    }
    

    Main.java

    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    
    
    public class Main {
    
    public static void main(String[] args) {
    
        // create an instance of your gui class
        final Gui gui = new Gui();
    
        // add the action listener to the button
                // notice how we reference the gui here by running the methods in the
                // gui class
                // this action listener could be created in the gui
                // class but in general you don't want to do that because actions will 
                // involve multiple classes
        gui.setButtonActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                gui.setText((gui.isBoxChecked() ? "yes" : "no"));
            }
        });
    }
    

    }

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.