[java] Calling another method java GUI

I'm trying to make a GUI, and I can accomplish it all in one method, but I would like to make the code simpler and make multiple methods. However, I can't get it to work. I am new to Java programming.

public class Main {     public static void main(String[] args) {         FirstWindow fw = new FirstWindow();          fw.setVisible(true);         fw.setSize(600,400);     } }  public class FirstWindow extends JFrame {      public FirstWindow() {         checkbox c = new checkbox();         c();     } }   public class checkbox extends JFrame {      public checkbox() {           //code     } } 

This question is related to java swing user-interface methods multiple-instances

The answer is


I'm not sure what you're trying to do, but here's something to consider: c(); won't do anything. c is an instance of the class checkbox and not a method to be called. So consider this:

public class FirstWindow extends JFrame {      public FirstWindow() {         checkbox c = new checkbox();         c.yourMethod(yourParameters); // call the method you made in checkbox     } }  public class checkbox extends JFrame {      public checkbox(yourParameters) {          // this is the constructor method used to initialize instance variables     }      public void yourMethod() // doesn't have to be void     {         // put your code here     } } 

Questions with java tag:

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log getting " (1) no such column: _id10 " error Instantiating a generic type When to create variables (memory management) java doesn't run if structure inside of onclick listener String method cannot be found in a main class method Are all Spring Framework Java Configuration injection examples buggy? Calling another method java GUI I need to know how to get my program to output the word i typed in and also the new rearranged word using a 2D array Java and unlimited decimal places? Read input from a JOptionPane.showInputDialog box Cannot retrieve string(s) from preferences (settings) strange error in my Animation Drawable Two Page Login with Spring Security 3.2.x Hadoop MapReduce: Strange Result when Storing Previous Value in Memory in a Reduce Class (Java) Got a NumberFormatException while trying to parse a text file for objects Best way for storing Java application name and version properties Call japplet from jframe FragmentActivity to Fragment Comparing two joda DateTime instances Maven dependencies are failing with a 501 error IntelliJ: Error:java: error: release version 5 not supported Has been compiled by a more recent version of the Java Runtime (class file version 57.0) Why am I getting Unknown error in line 1 of pom.xml? Gradle: Could not determine java version from '11.0.2' Error: Java: invalid target release: 11 - IntelliJ IDEA Android Gradle 5.0 Update:Cause: org.jetbrains.plugins.gradle.tooling.util Why is 2 * (i * i) faster than 2 * i * i in Java? must declare a named package eclipse because this compilation unit is associated to the named module How do I install Java on Mac OSX allowing version switching? How to install JDK 11 under Ubuntu? Java 11 package javax.xml.bind does not exist IntelliJ can't recognize JavaFX 11 with OpenJDK 11 Difference between OpenJDK and Adoptium/AdoptOpenJDK OpenJDK8 for windows How to allow all Network connection types HTTP and HTTPS in Android (9) Pie? Find the smallest positive integer that does not occur in a given sequence Error: JavaFX runtime components are missing, and are required to run this application with JDK 11 How to uninstall Eclipse? Failed to resolve: com.google.firebase:firebase-core:16.0.1 How to resolve Unable to load authentication plugin 'caching_sha2_password' issue

Questions with swing tag:

Calling another method java GUI Read input from a JOptionPane.showInputDialog box Call japplet from jframe Java JTable getting the data of the selected row What does .pack() do? How to add row of data to Jtable from values received from jtextfield and comboboxes How can I check that JButton is pressed? If the isEnable() is not work? Load arrayList data into JTable How to draw a circle with given X and Y coordinates as the middle spot of the circle? Simplest way to set image as JPanel background JFrame background image JFrame: How to disable window resizing? Adding image to JFrame Adding items to a JComboBox How to make a JFrame button open another JFrame class in Netbeans? Set Icon Image in Java Java - Check if JTextField is empty or not Swing vs JavaFx for desktop applications Resize a picture to fit a JLabel Save file/open file dialog box, using Swing & Netbeans GUI editor How to layout multiple panels on a jFrame? (java) How does paintComponent work? Execute an action when an item on the combobox is selected How to set the height and the width of a textfield in Java? DTO and DAO concepts and MVC getting integer values from textfield Allowing the "Enter" key to press the submit button, as opposed to only using MouseClick How to add text to JFrame? add controls vertically instead of horizontally using flow layout JFrame.dispose() vs System.exit() JPanel vs JFrame in Java JOptionPane - input dialog box program Get combobox value in Java swing Triangle Draw Method Display calendar to pick a date in java JFrame in full screen Java Restricting JTextField input to Integers Open a link in browser with java button? Most simple code to populate JTable from ResultSet Adding JPanel to JFrame Java :Add scroll into text area JPanel setBackground(Color.BLACK) does nothing Limiting the number of characters in a JTextField JTable - Selected Row click event JCheckbox - ActionListener and ItemListener? "Could not find the main class" error when running jar exported by Eclipse Drawing in Java using Canvas Java swing application, close one window and open another when button is clicked The Use of Multiple JFrames: Good or Bad Practice? How to position the form in the center screen?

Questions with user-interface tag:

Calling another method java GUI How do I center text vertically and horizontally in Flutter? Is it possible to put a ConstraintLayout inside a ScrollView? How to change color of the back arrow in the new material theme? How to create RecyclerView with multiple view type? Android RecyclerView addition & removal of items tkinter: how to use after method Presenting a UIAlertController properly on an iPad using iOS 8 Android ViewPager with bottom dots How do I get the height and width of the Android Navigation Bar programmatically? How to set default text for a Tkinter Entry widget Change color of Button when Mouse is over UINavigationBar custom back button without title Left align and right align within div in Bootstrap How to view table contents in Mysql Workbench GUI? Swipe to Delete and the "More" button (like in Mail app on iOS 7) iOS 7's blurred overlay effect using CSS? How do I fix this "TypeError: 'str' object is not callable" error? Swing vs JavaFx for desktop applications How to Lock Android App's Orientation to Portrait in Phones and Landscape in Tablets? Save file/open file dialog box, using Swing & Netbeans GUI editor Android - Back button in the title bar DTO and DAO concepts and MVC Platform.runLater and Task in JavaFX close fxml window by code, javafx Adding new line of data to TextBox What is Linux’s native GUI API? Formatting MM/DD/YYYY dates in textbox in VBA Navigation Drawer (Google+ vs. YouTube) Align HTML input fields by : How to add an image in Tkinter? The Use of Multiple JFrames: Good or Bad Practice? How to make a gui in python How to close a GUI when I push a JButton? How to get the fragment instance from the FragmentActivity? the getSource() and getActionCommand() How to set specific window (frame) size in java swing? jQuery animate scroll How do I put an image into my picturebox using ImageLocation? How can I add a hint text to WPF textbox? Java GUI frameworks. What to choose? Swing, SWT, AWT, SwingX, JGoodies, JavaFX, Apache Pivot? How do I put the image on the right side of the text in a UIButton? How do you add UI inside cells in a google spreadsheet using app script? How to Disable GUI Button in Java Sequel Pro Alternative for Windows How to center the text in a JLabel? Create GUI using Eclipse (Java) How do I run Selenium in Xvfb? Resizing image in Java How can I do GUI programming in C?

Questions with methods tag:

String method cannot be found in a main class method Calling another method java GUI ReactJS - Call One Component Method From Another Component multiple conditions for JavaScript .includes() method java, get set methods includes() not working in all browsers Python safe method to get value of nested dictionary Calling one method from another within same class in Python TypeError: method() takes 1 positional argument but 2 were given Android ListView with onClick items Error: Main method not found in class Calculate, please define the main method as: public static void main(String[] args) Purpose of a constructor in Java? Methods vs Constructors in Java class method generates "TypeError: ... got multiple values for keyword argument ..." Java: Sending Multiple Parameters to Method How to make method call another one in classes? Write a mode method in Java to find the most frequently occurring element in an array PHP call Class method / function What does .class mean in Java? C# cannot convert method to non delegate type Non-Static method cannot be referenced from a static context with methods and variables Can overridden methods differ in return type? How to log as much information as possible for a Java Exception? How to return a boolean method in java? Method to get all files within folder and subfolders that will return a list Python calling method in class Can there exist two main methods in a Java program? Compare two objects with .equals() and == operator method in class cannot be applied to given types Converting Integers to Roman Numerals - Java 'Class' does not contain a definition for 'Method' How to call a parent method from child class in javascript? Return a string method in C# HTTP Status 405 - Request method 'POST' not supported (Spring MVC) Passing just a type as a parameter in C# C# : Passing a Generic Object How to use a variable of one method in another method? C# referencing a variable from another method Verify a method call using Moq Why do some functions have underscores "__" before and after the function name? Python 3 string.join() equivalent? List method to delete last element in list as well as all elements calling a function from class in python - different way How can I create a Java method that accepts a variable number of arguments? Retrieving data from a POST method in ASP.NET Java Inheritance - calling superclass method Set and Get Methods in java? Abstract methods in Java Count words in a string method? How to get an object's methods?

Questions with multiple-instances tag:

Calling another method java GUI How do you join tables from two different SQL Server instances in one SQL query