4 Replies - 529 Views - Last Post: 17 December 2013 - 09:56 PM Rate Topic: -----

#1 streek405  Icon User is offline

  • D.I.C Addict

Reputation: 12
  • View blog
  • Posts: 610
  • Joined: 10-March 13

Methods for GUI's

Posted 17 December 2013 - 02:24 PM

Ok, its been a longggg time since I worked with GUI's. On top of that, I never really learned them properly.

Right now I am trying to make a program that will teach the user some Calculus and Algebra stuff. The thing is -- is that I am not really sure if I have the right mind set for GUI's with other methods and objects. Do I only deal with the GUI stuff in my test program or in ALL of the methods/objects?

Also, a side question, do I have to create all of my classes in a separate file if they are dealing with GUI stuff? What I mean by this is that I am getting an error stating "modifier private not allowed here" if the class is private (line 20) and "class WHATEVER is public, should be declared in a file named CalculusTutorial.java" if I make the class public (line 11).

Sorry for the sub question.

/*
This program will teach the user some of the basics, but
foundational materials of Calculus and Algebra.
*/

import java.awt.FlowLayout;//the lay out of the GUI
import javax.swing.JFrame;//features of the GUI
import javax.swing.JOptionPane;


public class CalculusTutorial extends JFrame{	
	
	//method for basic derivatives
		//special case for 'e'
		
	
	//method for basic integrals
} 

private class AlgebraTutorial extends JFrame{
	
	//non variable multiplication/division
	
	//then with variables
	
	//test if they know powers

}

public class TestMathTutorial{
	public static void main(String[] args){
	
	
	
	//create the objects
	CalculusTutorial calc = new CalculusTutorial();
	AlgebraTutorial algebra = new AlgebraTutorial();
	
	//ask the user which topic they will like to learn
	
	//ask which subtopic they would like to learn
	
	//create the placement and stuff for the object
	
	}
}

This post has been edited by streek405: 17 December 2013 - 02:31 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Methods for GUI's

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2205
  • View blog
  • Posts: 5,239
  • Joined: 10-September 10

Re: Methods for GUI's

Posted 17 December 2013 - 02:35 PM

Quote

Do I only deal with the GUI stuff in my test program or in ALL of the methods/objects?

What do you mean by "deal with?"

There can only be one top-level public class in a file. If there is a main() method in the file, it should be in the top-level public class. Declare other top-level classes in the same file without access modifiers.
Was This Post Helpful? 1
  • +
  • -

#3 streek405  Icon User is offline

  • D.I.C Addict

Reputation: 12
  • View blog
  • Posts: 610
  • Joined: 10-March 13

Re: Methods for GUI's

Posted 17 December 2013 - 02:47 PM

View PostGregBrannon, on 17 December 2013 - 02:35 PM, said:

What do you mean by "deal with?"

I mean if I should include all of the GUI stuff, such as the title bar, buttons, message/input boxes, etc, in the test program only and then call the objects OR should each method/class have their own dialog/input boxes?

Also, how can I check what the user entered in for the input dialog boxes? For example for something like this:
String introQuestion = JOptionPane.showInputDialog("Hello. What topic would you like to learn: Algebra or Calculus? Please enter your choice below:");

how do I know what they entered in? Can I do an IF/ELSE the normal way to check what they entered or will this not work? For example
if(introQuestion == "calculus"){//do this}

*Edit* Or would I do something like this:
if(introQuestion.getSource() == "calculus"{//do this}
?

Quote

There can only be one top-level public class in a file. If there is a main() method in the file, it should be in the top-level public class. Declare other top-level classes in the same file without access modifiers.

Ok thanks.

This post has been edited by streek405: 17 December 2013 - 02:58 PM

Was This Post Helpful? 0
  • +
  • -

#4 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2205
  • View blog
  • Posts: 5,239
  • Joined: 10-September 10

Re: Methods for GUI's

Posted 17 December 2013 - 03:03 PM

Still a bit confused, but I'll generalize: The test class should contain a main() method, that main() method should contain the minimum number of lines required to start the GUI on the EDT and that's all.

There are multiple types of JOptionPane dialogs that can be customized to meet your needs. I think you'll find answers to your "how do I <blank>" questions by reading the dialogs tutorial and/or the JOptionPane API page.

You may remember that you don't use the equality operator, '==', to compare Stirngs. Instead, you use the equals() method.
Was This Post Helpful? 1
  • +
  • -

#5 streek405  Icon User is offline

  • D.I.C Addict

Reputation: 12
  • View blog
  • Posts: 610
  • Joined: 10-March 13

Re: Methods for GUI's

Posted 17 December 2013 - 09:56 PM

View PostGregBrannon, on 17 December 2013 - 03:03 PM, said:



Ok thanks. And you're right, I havent compared strings for quite some time now.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1