• 0

[JAVA] Auxiliary Class Help


Question

Can someone please explain as easily as possible how to create a java program that handles all the user input in one program and then uses an auxiliary class (a seperate java file) to perform the calculations. I have trouble understanding how the entered data is passed to the auxiliary class file for processing.

So for example, this program could prompt for 3 numbers to be entered using JOptionPane.showInputDialog's and these numbers are then fed to the auxiliary class file which adds these numbers together and passes the total back to the main program which then uses a JOptionPane.showMessageDialog to display the total.

I'm really not that good with java so the simpler its explained the better, thx :D

Link to comment
https://www.neowin.net/forum/topic/456134-java-auxiliary-class-help/
Share on other sites

8 answers to this question

Recommended Posts

  • 0

A class is your blue print (not really but close enough).....

When you run an application you create "Instances of the Class" so in memory you might have 5 people instances with different names ... ie

Person.java

public class Person {
  private String name;

  public Person(String name) {
	this.name=name;
  }
  public String getName(){
	 return name;
  }
}

main code

public static void main (String[] arg) {
  //create instances of person class
   Person p1 = new Person("John");
   Person p2 = new Person("Luke");
   Person p3 = new Person("Mary");

}  

now we will add another class file

Bus.java

public class Bus {
  private String busName;
  private ArrayList peopleOnTheBus = new ArrayList();  

  public Bus(String name) {
	this.busName=name;
  }

  public String getName() {
	return this.busName;=name;
  }

  public void addPerson(Person p) {
  peopleOnTheBus.add(p);
  }
}

so now bringing all instances of classes together and interacting

public static void main (String[] arg) {
  //create instances of person class
   Person p1 = new Person("John");
   Person p2 = new Person("Luke");
   Person p3 = new Person("Mary");

   Bus b1 = new Bus("A");
   Bus b2 = new Bus("B");

   b1.add(p1);
   b1.add(p3);

   b2.add(p2);
}  

  • 0

well ok... i think i got bits of that but any chance of more basic and easier to understand examples?

sure i could google around and find a tutorial somewhere but im looking for an explanation thats super easy to understand, perhaps the actual parts where the auxiliary class links to the main program could be highlighted?

  • 0

Main.java

public class Main {
   public static void main (String[] args) {

	 Auxiliary aux = new Auxiliary();
	 GUI g = new GUI(aux);
	 g.setVisible(true);
   }
} 

GUI.java

public class GUI {

  public GUI(ActionListener al) {
	 button.setActionCommand("START");
	 button.addListener(al); // the button registers the ActionListener to be notified of changes/button presses
	 .... 
  }


  .. gui stuff
}

Auxiliary.java - ActionListener is an interface that defines how you listen to button events etc

public class Auxiliary implements ActionListener{

  public void ActionPerformed(ActionEvent e) {
	... do some action based on what was pressed/action performed - method is called when button is pressed

	if (e.getActionCommand().equals("START"))
		System.out.println("Startgame"); 
  }
}

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • YouTube is bring its age detection tech to the U.S. to identify minors by Usama Jawad YouTube hosts a wide range of video content on its platform, some of which may not be suitable to minors. For some of that audience, Google recommends the YouTube Kids app which offers child-friendly content with parental controls. However, some minors still circumvent measures put in place by the platform or their parents, so now, YouTube wants to put a stop to that. YouTube has revealed plans to bring its age detection technology to the United States. This is a machine learning algorithm which will infer a user's age based on various signals and traits such as the type of content they watch, the categories of their search queries, and the age of their account, among other things. If an account is identified as belonging to a teen, YouTube will immediately stop personalized advertising for that account, turn on digital well-being tools, and stop the person from viewing repetitive content. If this is a true positive detection, the user will just have to bear with the aforementioned consequences. However, in the case of a false positive, the affected person will be required to share their government-issued ID or credit card information. Google will start rolling out this technology to a limited subset of customers in the U.S. in the coming weeks and then monitor its results. This is not its first rodeo in this field as it has already deployed and tested the model in other countries. Still, the company will closely monitor the outcome of the age detection tech and its accuracy. YouTube has emphasized that it is committing to serving child-friendly content to minors and protect them from age-inappropriate material. It's unclear how accurate its age detection technology is, but we'll likely find out in the next few weeks. If this trial is successful, Google will probably roll it out to a larger audience in the U.S. and might expand to other countries too.
    • God of Way Ragnarok on PS5 Pro.
    • EMDB 5.38 by Razvan Serea EMDB is an application to keep track of your movie and TV Series collection. Both physical discs and media files are fully supported. With an automatic import from the database of IMDB, export to csv, text or HTML, thumbnail cover preview, a loan tracker, advances search and filter functions and multi-language user interface. EMDB doesn't need a .NET framework or any other external libraries and is therefore fully portable. And best of all... it's free!. EMDB 5.38 changelog: User interface: fix initial sort order was not always correct." Batch Update: fix updating TV Series from TheMovieDb cleared the title." Database: fixed possible invalid aspect ratio or codec could crash sorting." Search: added search on UPC / EAN." HTML Export: fixed favorites." Media files: delete / move thumbnails and subtitles too along with the media file." Image Import: added option to set resolution of saved images (when you use a zoomed bookshelf or display html on a 4K screen)." Batch update: movies in Collections were not always updated." Batch update: added an option to remove drive labels from media paths as they are not supported anymore and will break playing." HTML Export: fixed crash during export." Translations: updated the Arabic, Czech, French, German, Hebrew, Portuguese, Slovenian and Dutch translations." Download: EMDB 5.38 | 6.2 MB (Freeware) Link: EMDB Home Page | Screenshot Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • AMD brings datacenter-level AI to Windows PCs, runs Meta's 109B Llama lodel locally by Pradeep Viswanathan Earlier this year, during CES 2025, AMD announced the world's first AI PC processor that can run Meta's Llama 70B model locally. Today, AMD announced that the Ryzen AI MAX+ 395 processor, when paired with 128 GB of RAM on Windows, can now run Meta’s Llama 4 Scout 109B (17B active) with full vision and MCP support. This capability is enabled for the AMD Ryzen AI Max+ 395 processor with the new AMD Software: Adrenalin Edition 25.8.1 WHQL driver update. AMD claims that this processor can not only run Meta’s Llama 4 Scout but also supports a context length of 256,000 (Flash Attention ON, KV Cache Q8), which is useful for agentic workflows. AMD claims that the Llama 4 Scout 109B model was previously only possible on datacenter-grade hardware but is now available in thin and light PCs, thanks to its Variable Graphics Memory feature. Variable Graphics Memory is AMD's BIOS-level feature, introduced with the latest Ryzen AI 300 series processors, that enables users to reallocate a percentage of the system RAM to the integrated graphics. This unified memory architecture allows users to allocate unused system RAM as dedicated graphics memory. The AMD Ryzen AI Max+ processor is now available as an option for the following Windows PCs: ASUS ROG Flow Z13 Corsair AI Workstation 300 Framework Desktop HP ZBook Ultra G1a HP Z2 Mini G1a By enabling massive AI models to run locally, AMD is paving the way for more responsive, private, and capable AI applications on Windows PCs. As an Amazon Associate we earn from qualifying purchases.
    • You ARE old. Its not just a feeling.
  • Recent Achievements

    • Week One Done
      andeyhawk65 earned a badge
      Week One Done
    • First Post
      Jake2530 earned a badge
      First Post
    • Explorer
      Deranox went up a rank
      Explorer
    • Week One Done
      John Volks earned a badge
      Week One Done
    • One Month Later
      enric earned a badge
      One Month Later
  • Popular Contributors

    1. 1
      +primortal
      675
    2. 2
      ATLien_0
      253
    3. 3
      Xenon
      177
    4. 4
      neufuse
      136
    5. 5
      +FloatingFatMan
      99
  • Tell a friend

    Love Neowin? Tell a friend!