10 Replies - 5148 Views - Last Post: 01 January 2012 - 03:30 PM Rate Topic: -----

#1 Gaate  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 27
  • Joined: 31-December 11

GUI and .exe questions.

Posted 31 December 2011 - 01:19 PM

Just to give a little background, I am in a comp si AP class, but i skipped Comp Si regular. The AP Class goes over stuff like classes and stuff, basicaly ONLY stuff that will be on the AP test, for that reason. I know almost nothing about GUI's but do know a lot of logic coding stuff.

My question is pretty simple. I have seen a lot of tutorials on how to "Make" A gui, that is. Put up buttons and a frame. I am still pretty confused on how you make stuff do things in it. Like how hard would it be to convert a program which is written and works in the dos frame to a GUI? Is it possible to slap on a gui after you program something or do you need to have it in mind all along? Im guessing you can create another program which will use the other programs logic, but just contains a gui. But i wouldnt know where to start with that.

Also, is there a good way to convert a .java/.class file to a executable file for windows?

For what its worth this is my code as of now. (for a comp sci/science fair project)

   import java.util.Scanner;
   import static java.lang.Math.*;

   public class PhysicsCalc
   {
      static Scanner keyboard = new Scanner(System.in);
   
      public static void main (String args[])
      {
         System.out.println("Physics Projection Calculator");
         System.out.println("By Zachary Prinzbach");
         System.out.println("");
         menu();
      }
      public static void menu()
      {
         System.out.println("Please Pick one of the following calculations. Use the Number Keys to select.");
         System.out.println("(1) Calculate X-Force and Y-Force from Angle and Total Force");
         System.out.println("(2) Calculate instantanious Y velocity using Initial Y Vel. and Time");
         System.out.println("(3) Calculate the distance traveled by an object before it hits the ground");
         int choice = keyboard.nextInt();
         if(choice == 1)
            force();
         else
         {
            if(choice == 2)
            {
               iYVel();
            }
            else
            {
               if(choice == 3)
               {
                  xTravel();
               }
            }
         }   
      }
      public static void force()
      {
         System.out.println("Do you have (1) the total force and angle or (2) the X and Y Forces and angle?");
         int choice = keyboard.nextInt();
         if(choice == 1)
         {
            System.out.println("Please enter your angle");
            double angle = keyboard.nextInt();
            System.out.println("Please enter the total force");
            double totalForce = keyboard.nextDouble();
            double xForce = sin(angle) * totalForce;
            double yForce = cos(angle) * totalForce;
            System.out.println("The amount of X-Force is " + xForce + ".");
            System.out.println("The amount of Y-Force is " + yForce + ".");
            System.out.println("");
            menu();
         }
         else
         {
            System.out.println("Please enter your angle");
            double angle = keyboard.nextDouble();
            System.out.println("Please enter the X force");
            double xForce = keyboard.nextDouble();
            System.out.println("Please enter the Y Force");
            double yForce = keyboard.nextDouble();
            double totalForce = xForce / sin(angle);
            System.out.println("The Total force is " + totalForce + ".");
            System.out.println("");
            menu();
         }
      }
      public static void iYVel()
      {
         System.out.println("Please enter the Initial Y Velocity.");
         double yVelZero = keyboard.nextDouble();
         System.out.println("Please enter an amount of time in seconds.");
         double time = keyboard.nextDouble();
         double iYVel = yVelZero / 9.8;
         System.out.println("Your instantanious Y Velocity at " + time + " seconds is " + iYVel + ".");
         System.out.println("");
         menu();
      }
      public static void xTravel()
      {
         System.out.println("How high above ground is the object initially?");
         double higth = keyboard.nextDouble();
         System.out.println("Do you know the total Velocity? (1)-Yes (2)-No");
         int choice = keyboard.nextInt();
         if(choice == 1)
         {
            System.out.println("Please enter total Force.");
         	double tF = keyboard.nextDouble();
         	System.out.println("Please enter the angle of the force.");
         	double angle = keyboard.nextDouble();
            double xDistance = ((tF * cos(angle)) / 9.81) + Math.sqrt(Math.pow(tF * sin(angle),2) + (19.6 * higth));
         	System.out.println("The object travels " + xDistance + " in the x direction before it hits the ground.");
         	menu();
         }
         else
         {
            System.out.println("Please enter your angle");
            double angle = keyboard.nextDouble();
            System.out.println("Please enter the X force");
            double xForce = keyboard.nextDouble();
            System.out.println("Please enter the Y Force");
            double yForce = keyboard.nextDouble();
            double tF = xForce / sin(angle);
            System.out.println("The Total force is " + tF + ".");
            System.out.println("");
            double xDistance = ((tF * cos(angle)) / 9.81) + Math.sqrt(Math.pow(tF * sin(angle),2) + (19.6 * higth));
         	System.out.println("The object travels " + xDistance + " in the x direction before it hits the ground.");
         	menu();
         }
      }
   }



Still going to add more to it but thats it as of now.

Is This A Good Question/Topic? 0
  • +

Replies To: GUI and .exe questions.

#2 GregBrannon  Icon User is offline

  • D.I.C Lover
  • member icon

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

Re: GUI and .exe questions.

Posted 31 December 2011 - 01:43 PM

There's an intermediate step between a text-based or command line user interface and a full-blown GUI that you could use that would communicate with the user using JOptionPanes. This option would involve 'converting' your print statements and user input requests to simple graphical components. It would give your program a slightly more advanced look, would be fairly simple to learn and implement, but would be limited in how far you could go with it. Even though limited, it would handle what you've coded so far. The online tutorial is here.

Quote

Like how hard would it be to convert a program which is written and works in the dos frame to a GUI? Is it possible to slap on a gui after you program something or do you need to have it in mind all along? Im guessing you can create another program which will use the other programs logic, but just contains a gui.


If a program is written with the user interface, data, and computational parts separated, it's easier to change the user interface portion. It's harder when the user interface is mixed together with everything else, as your program is now. However, the intermediate option I suggested above simply replaces your user interactions with another that wouldn't be too hard to implement.

Quote

Also, is there a good way to convert a .java/.class file to a executable file for windows?


You can package your program in a runnable .jar file that should run on any computer with a compatible JRE. That's the concept behind Java: "Write once, run anywhere." It doesn't always work, but it's a great idea. As soon as you take a Java program and convert it to an .exe file, it will only work on a Windows machine, maybe.
Was This Post Helpful? 2
  • +
  • -

#3 htc(hot-taco-cheese)  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 17
  • View blog
  • Posts: 71
  • Joined: 04-December 10

Re: GUI and .exe questions.

Posted 31 December 2011 - 01:47 PM

It would not be too hard all. Mainly just some copy and pasting. Check out the Swing tutorials starting here- http://www.dreaminco...ng-swing-part-i
They cover Java GUIs quite well.

As for the .exe, I do not know. I just use .jars

This post has been edited by htc(hot-taco-cheese): 31 December 2011 - 01:52 PM

Was This Post Helpful? 0
  • +
  • -

#4 Gaate  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 27
  • Joined: 31-December 11

Re: GUI and .exe questions.

Posted 31 December 2011 - 01:51 PM

Thanks! That literally answered all of my questions. I appreciate the quick responses and am going to go check out that link and JOptionPanes.
Was This Post Helpful? 0
  • +
  • -

#5 Gaate  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 27
  • Joined: 31-December 11

Re: GUI and .exe questions.

Posted 31 December 2011 - 06:52 PM

Ok, I have done a LOT of work on this. Figured i would upload it. And show the code. Instead of just using JOptionPane i did the whole JFrame thing. I think it looks nice.

I also packaged it in a jar file. Here is the code, including the 3 guis i made. Not sure if there was a way i could have only made one, but this works.

   import java.util.Scanner;

import javax.swing.*;

   import static java.lang.Math.*;
   import org.jfree.chart.*;
   import org.jfree.chart.plot.PlotOrientation;
   import org.jfree.data.xy.*;

   public class PhysicsCalc
   {
      static Scanner keyboard = new Scanner(System.in);
   
      public static void main (String args[])
      {
         System.out.println("Physics Projection Calculator");
         System.out.println("By Zachary Prinzbach");
         System.out.println("");
         JOptionPane.showMessageDialog(null, "Physics Project Calculator \n By Zachary Prinzbach");
         menu();
      }
      public static void menu()
      {
    	  Gui fw = new Gui();
    	  fw.setVisible(true);	  
      }
      public static void force()
      {
         Gui2 sw = new Gui2();
         sw.setVisible(true);
      }
         
         public static void force1()
         {
            String angle1 = JOptionPane.showInputDialog("Please enter your angle");
            double angle = Double.parseDouble(angle1);
            String totalForce1 = JOptionPane.showInputDialog("Please Enter the Toral Force");
            double totalForce = Double.parseDouble(totalForce1);
            double xForce = sin(angle) * totalForce;
            double yForce = cos(angle) * totalForce;
            JOptionPane.showMessageDialog(null, "The amount of X-Force is " + xForce + ".\n" + "The amount of Y-Force is " + yForce + ".\n");
            menu();
         }
         public static void force2()
         {
            String angle1 = JOptionPane.showInputDialog("Please Enter the angle");
            double angle = Double.parseDouble(angle1);
            String xForce1 = JOptionPane.showInputDialog("Please Enter the X force");
            double xForce = Double.parseDouble(xForce1);
            String yForce1 = JOptionPane.showInputDialog("Please Enter the Y force");
            double yForce = Double.parseDouble(yForce1);
            double totalForce = xForce / sin(angle);
            JOptionPane.showMessageDialog(null, "The total force is " + totalForce + ".\n");
            menu();
         }
      
      public static void iYVel()
      {
         String yVelZero1 = JOptionPane.showInputDialog("Please enter the initial Y Velocity");
         double yVelZero = Double.parseDouble(yVelZero1);
         String time1 = JOptionPane.showInputDialog("Please enter the objects initial heighth");
         double time = Double.parseDouble(time1);
         double iYVel = yVelZero / 9.8;
         System.out.println("Your instantanious Y Velocity at " + time + " seconds is " + iYVel + ".");
         System.out.println("");
         JOptionPane.showMessageDialog(null, "Your instantanious Y Velocity at " + time + " seconds is " + iYVel + ".\n");
         menu();
      }
      public static void xTravel()
      {
          Gui3 tw = new Gui3();
          tw.setVisible(true);
      }
         public static void xTravel1()
         {
            String tF1 = JOptionPane.showInputDialog("Please enter the total force");
            double tF = Double.parseDouble(tF1);
            Gui2 sw = new Gui2();
            sw.setVisible(true);
            String a1 = JOptionPane.showInputDialog("Please enter your angle");
            double a = Double.parseDouble(a1);
            String h1 = JOptionPane.showInputDialog("Please enter the objects initial heighth");
            double h = Double.parseDouble(h1);
            double xDistance = ((tF * cos(a)) / 9.81) + Math.sqrt(Math.pow(tF * sin(a),2) + (19.6 * h));
            JOptionPane.showMessageDialog(null,"The object travels " + xDistance + " in the x direction before it hits the ground.\n" );

         	menu();
         }
         public static void xTravel2()
         {
            System.out.println("Please enter your angle");
            double angle = keyboard.nextDouble();
            System.out.println("Please enter the X force");
            double xForce = keyboard.nextDouble();
            System.out.println("Please enter the Y Force");
            double yForce = keyboard.nextDouble();
            double tF = xForce / sin(angle);
            System.out.println("The Total force is " + tF + ".");
            System.out.println("");
            System.out.println("How high above ground is the object initially?");
            double higth = keyboard.nextDouble();
			double xDistance = ((tF * cos(angle)) / 9.81) + Math.sqrt(Math.pow(tF * sin(angle),2) + (19.6 * higth));
         	System.out.println("The object travels " + xDistance + " in the x direction before it hits the ground.");
         	menu();
         }
		public static void graph()
		{
		 double[] points = new double[100];
		 double t = 1;
         String tF1 = JOptionPane.showInputDialog("Please enter the total force");
         double tF = Double.parseDouble(tF1);
		 double y = 1;
         String a1 = JOptionPane.showInputDialog("Please enter your angle");
         double a = Double.parseDouble(a1);
         String h1 = JOptionPane.showInputDialog("Please enter the objects initial heighth");
         double h = Double.parseDouble(h1);
		 System.out.println();
		 System.out.println("Co-ordinates (x,y)");
		 int count = 1;
		 while(y > 0)
		 {
		  points[count] = h + (count * tan(a)) - ((9.8 * Math.pow(count,2)) / (2 * Math.pow((tF * cos(a)),2)));
		  y = points[count];
		  if(points[count] > 0)
		  {
		  System.out.println(count + "," + points[count]);
		  count++;
		  }
		  else
		  count++;
		 }
		 System.out.println();
		 double length = count;
		 XYSeries series = new XYSeries("Position Graph (X vs. Y)");
		 count = 1;
		  while(length > 1)
		  {
			  series.add(count, points[count]);
			  count++;
			  length--;
		  }
		  XYDataset xyDataset = new XYSeriesCollection(series);
		  JFreeChart chart = ChartFactory.createXYLineChart
		  ("Position Graph", "X", "Y",
		 xyDataset, PlotOrientation.VERTICAL, true, true, false);
		  ChartFrame frame1=new ChartFrame("XYLine Chart",chart);
		  frame1.setVisible(true);
		  frame1.setSize(300,300);
		 menu();
		}
   }

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
import javax.swing.text.JTextComponent;
public class Gui extends JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public Gui() {
	super("Physics Calculator");
	setSize(600, 200);
	setDefaultCloseOperation(EXIT_ON_CLOSE);
	
	JPanel p = new JPanel();
	JPanel p2 = new JPanel();
	JPanel p3 = new JPanel(new GridBagLayout());
	
	JButton btn1 = new JButton("Calculate Forces");
	JButton btn2 = new JButton("Calculate Instantanious Y Velocity");
	JButton btn3 = new JButton("Calculate Distance Traveled at time");
	JButton btn4 = new JButton("Graph the path traveled");
	
	btn1.addActionListener(new ActionListener() {
		
		@Override
		public void actionPerformed(ActionEvent e) 
		{
			// TODO Auto-generated method stub
			PhysicsCalc.force();
			dispose();
			
		}
	});
	btn2.addActionListener(new ActionListener() {
		
		@Override
		public void actionPerformed(ActionEvent e) 
		{
			// TODO Auto-generated method stub
			PhysicsCalc.iYVel();
			dispose();
		}
	});
	btn3.addActionListener(new ActionListener() {
		
		@Override
		public void actionPerformed(ActionEvent e) 
		{
			// TODO Auto-generated method stub
			PhysicsCalc.xTravel();
			dispose();
		}
	});
	btn4.addActionListener(new ActionListener() {
		
		@Override
		public void actionPerformed(ActionEvent e) 
		{
			// TODO Auto-generated method stub
			PhysicsCalc.graph();
			dispose();
		}
	});
	
	JLabel e = new JLabel("Please Select an option");
	
	GridBagConstraints gbc = new GridBagConstraints();
	gbc.insets = new Insets(15,15,15,15);
	
	gbc.gridx = 0;
	gbc.gridy = 0;
	p3.add(btn1, gbc);
	gbc.gridx = 1;
	gbc.gridy = 0;
	p3.add(btn2, gbc);
	gbc.gridx = 0;
	gbc.gridy = 1;
	p3.add(btn3, gbc);
	gbc.gridx = 1;
	gbc.gridy = 1;
	p3.add(btn4, gbc);
	p2.add(e);
	
	add(p, BorderLayout.SOUTH);
	add(p2, BorderLayout.NORTH);
	add(p3, BorderLayout.SOUTH);
}

}


import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
import javax.swing.text.JTextComponent;
public class Gui2 extends JFrame {

/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

public Gui2() {
	super("Physics Calculator");
	setSize(600, 200);
	setDefaultCloseOperation(EXIT_ON_CLOSE);
	
	JPanel p = new JPanel();
	JPanel p2 = new JPanel();
	JPanel p3 = new JPanel(new GridBagLayout());
	
	JButton btn1 = new JButton("The Total force and angle");
	JButton btn2 = new JButton("Both X and Y forces and angle");
	
	btn1.addActionListener(new ActionListener() {
		
		@Override
		public void actionPerformed(ActionEvent e) 
		{
			// TODO Auto-generated method stub
			PhysicsCalc.force1();
			dispose();
		}
	});
	btn2.addActionListener(new ActionListener() {
		
		@Override
		public void actionPerformed(ActionEvent e) 
		{
			// TODO Auto-generated method stub
			PhysicsCalc.force2();
			dispose();
		}
	});
	
	JLabel e = new JLabel("Do you currently know...");
	
	GridBagConstraints gbc = new GridBagConstraints();
	gbc.insets = new Insets(15,15,15,15);
	
	gbc.gridx = 0;
	gbc.gridy = 0;
	p3.add(btn1, gbc);
	gbc.gridx = 1;
	gbc.gridy = 0;
	p3.add(btn2, gbc);
	p2.add(e);
	
	add(p, BorderLayout.SOUTH);
	add(p2, BorderLayout.NORTH);
	add(p3, BorderLayout.SOUTH);
}
}

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;
import javax.swing.text.JTextComponent;
public class Gui3 extends JFrame {

/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

public Gui3() {
	super("Physics Calculator");
	setSize(600, 200);
	setDefaultCloseOperation(EXIT_ON_CLOSE);
	
	JPanel p = new JPanel();
	JPanel p2 = new JPanel();
	JPanel p3 = new JPanel(new GridBagLayout());
	
	JButton btn1 = new JButton("Yes");
	JButton btn2 = new JButton("No");
	
	btn1.addActionListener(new ActionListener() {
		
		@Override
		public void actionPerformed(ActionEvent e) 
		{
			// TODO Auto-generated method stub
			PhysicsCalc.xTravel1();
			dispose();
		}
	});
	btn2.addActionListener(new ActionListener() {
		
		@Override
		public void actionPerformed(ActionEvent e) 
		{
			// TODO Auto-generated method stub
			PhysicsCalc.force2();
			dispose();
		}
	});
	
	JLabel e = new JLabel("Do you currently know the total force?");
	
	GridBagConstraints gbc = new GridBagConstraints();
	gbc.insets = new Insets(15,15,15,15);
	
	gbc.gridx = 0;
	gbc.gridy = 0;
	p3.add(btn1, gbc);
	gbc.gridx = 1;
	gbc.gridy = 0;
	p3.add(btn2, gbc);
	p2.add(e);
	
	add(p, BorderLayout.SOUTH);
	add(p2, BorderLayout.NORTH);
	add(p3, BorderLayout.SOUTH);
}
}


I have one last question. It there any way i could get all of those things to show up in one frame? Like, including the JoptionPanes. As in just putting them in a seperate pane when they are to apear.
Was This Post Helpful? 1
  • +
  • -

#6 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8343
  • View blog
  • Posts: 31,890
  • Joined: 06-March 08

Re: GUI and .exe questions.

Posted 31 December 2011 - 07:16 PM

You did a lot of job in a few hours :^:
Sure

I would put your panels in a JTabbedPane
The JOptionPane can be replaced by JTextField
Was This Post Helpful? 1
  • +
  • -

#7 Gaate  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 27
  • Joined: 31-December 11

Re: GUI and .exe questions.

Posted 31 December 2011 - 07:48 PM

View Postpbl, on 31 December 2011 - 07:16 PM, said:

You did a lot of job in a few hours :^:
Sure

I would put your panels in a JTabbedPane
The JOptionPane can be replaced by JTextField

Thanks for the advice. I will probably try and do that tomorrow. I am literally learning how to do all of this as i need to do it so i am sure i will rewrite this code a few times because i will continue to find better ways of doing things.

I cleaned up the code and made the buttons all the same size/made the labels more atractive. Basically made the program look pretty. But i dont think its worth a re post.

Another question, about the forum though, why wont it let me attach .jar files?
Was This Post Helpful? 0
  • +
  • -

#8 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8343
  • View blog
  • Posts: 31,890
  • Joined: 06-March 08

Re: GUI and .exe questions.

Posted 31 December 2011 - 08:42 PM

View PostGaate, on 31 December 2011 - 09:48 PM, said:

Another question, about the forum though, why wont it let me attach .jar files?

What do you mean ?
Was This Post Helpful? 0
  • +
  • -

#9 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2876
  • View blog
  • Posts: 11,050
  • Joined: 15-July 08

Re: GUI and .exe questions.

Posted 31 December 2011 - 08:48 PM

The security features of our site do not allow the uploading of executable files, so as to prevent malicious code from being either executed or downloaded. If you want to upload JARs, you'll have to upload them on another site and then link to them.

By the way, I'm amazed at your progress. Swing is a beastly machine; just wait till you want to do more difficult things - like changing the look and feel. Good luck!
Was This Post Helpful? 0
  • +
  • -

#10 Gaate  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 27
  • Joined: 31-December 11

Re: GUI and .exe questions.

Posted 01 January 2012 - 11:29 AM

Alright, I started fiddling with it again this morning.

I think ill make a little update log because it will make me feel cool.

-options that require a different frame/pane no longer open a new window.
-Made all the buttons same size.
-Put labels in bold.
-Did away with the excess Gui's only need 1 at this point.

Next I am going to work on doing away with the JOptionPane and trying to use the JTextField.
Any Constructive criticism would be greatly appreciated.

   import java.util.Scanner;
   import javax.swing.*;
   import static java.lang.Math.*;
   import org.jfree.chart.*;
   import org.jfree.chart.plot.PlotOrientation;
   import org.jfree.data.xy.*;

   public class PhysicsCalc
   {
      static Scanner keyboard = new Scanner(System.in);
   
      public static void main (String args[])
      {
         System.out.println("Physics Projection Calculator");
         System.out.println("By Zachary Prinzbach");
         System.out.println("");
         JOptionPane.showMessageDialog(null, "Physics Project Calculator \n By Zachary Prinzbach");
         menu();
      }
      public static void menu()
      {
         Gui fw = new Gui();
         fw.setVisible(true);	  
      }
      public static void force()
      {
         Gui2 sw = new Gui2();
         sw.setVisible(true);
      }
         
      public static void force1()
      {
         String angle1 = JOptionPane.showInputDialog("Please enter your angle");
         double angle = Double.parseDouble(angle1);
         String totalForce1 = JOptionPane.showInputDialog("Please Enter the Toral Force");
         double totalForce = Double.parseDouble(totalForce1);
         double xForce = sin(angle) * totalForce;
         double yForce = cos(angle) * totalForce;
         JOptionPane.showMessageDialog(null, "The amount of X-Force is " + xForce + ".\n" + "The amount of Y-Force is " + yForce + ".\n");
         //menu();
      }
      public static void force2()
      {
         String angle1 = JOptionPane.showInputDialog("Please Enter the angle");
         double angle = Double.parseDouble(angle1);
         String xForce1 = JOptionPane.showInputDialog("Please Enter the X force");
         double xForce = Double.parseDouble(xForce1);
         String yForce1 = JOptionPane.showInputDialog("Please Enter the Y force");
         double yForce = Double.parseDouble(yForce1);
         double totalForce = xForce / sin(angle);
         JOptionPane.showMessageDialog(null, "The total force is " + totalForce + ".\n");
         //menu();
      }
      
      public static void iYVel()
      {
         String yVelZero1 = JOptionPane.showInputDialog("Please enter the initial Y Velocity");
         double yVelZero = Double.parseDouble(yVelZero1);
         String time1 = JOptionPane.showInputDialog("Please enter the objects initial heighth");
         double time = Double.parseDouble(time1);
         double iYVel = yVelZero / 9.8;
         System.out.println("Your instantanious Y Velocity at " + time + " seconds is " + iYVel + ".");
         System.out.println("");
         JOptionPane.showMessageDialog(null, "Your instantanious Y Velocity at " + time + " seconds is " + iYVel + ".\n");
         //menu();
      }
      public static void xTravel()
      {
         Gui3 tw = new Gui3();
         tw.setVisible(true);
      }
      public static void xTravel1()
      {
         String tF1 = JOptionPane.showInputDialog("Please enter the total force");
         double tF = Double.parseDouble(tF1);
         //Gui2 sw = new Gui2();
         //sw.setVisible(true);
         String a1 = JOptionPane.showInputDialog("Please enter your angle");
         double a = Double.parseDouble(a1);
         String h1 = JOptionPane.showInputDialog("Please enter the objects initial heighth");
         double h = Double.parseDouble(h1);
         double xDistance = ((tF * cos(a)) / 9.81) + Math.sqrt(Math.pow(tF * sin(a),2) + (19.6 * h));
         JOptionPane.showMessageDialog(null,"The object travels " + xDistance + " in the x direction before it hits the ground.\n" );
         //menu();
      }
      public static void xTravel2()
      {
         System.out.println("Please enter your angle");
         double angle = keyboard.nextDouble();
         System.out.println("Please enter the X force");
         double xForce = keyboard.nextDouble();
         System.out.println("Please enter the Y Force");
         double yForce = keyboard.nextDouble();
         double tF = xForce / sin(angle);
         System.out.println("The Total force is " + tF + ".");
         System.out.println("");
         System.out.println("How high above ground is the object initially?");
         double higth = keyboard.nextDouble();
         double xDistance = ((tF * cos(angle)) / 9.81) + Math.sqrt(Math.pow(tF * sin(angle),2) + (19.6 * higth));
         System.out.println("The object travels " + xDistance + " in the x direction before it hits the ground.");
         //menu();
      }
      public static void graph()
      {
         double[] points = new double[100];
         double t = 1;
         String tF1 = JOptionPane.showInputDialog("Please enter the total force");
         double tF = Double.parseDouble(tF1);
         double y = 1;
         String a1 = JOptionPane.showInputDialog("Please enter your angle");
         double a = Double.parseDouble(a1);
         String h1 = JOptionPane.showInputDialog("Please enter the objects initial heighth");
         double h = Double.parseDouble(h1);
         System.out.println();
         System.out.println("Co-ordinates (x,y)");
         int count = 1;
         while(y > 0)
         {
            points[count] = h + (count * tan(a)) - ((9.8 * Math.pow(count,2)) / (2 * Math.pow((tF * cos(a)),2)));
            y = points[count];
            if(points[count] > 0)
            {
               System.out.println(count + "," + points[count]);
               count++;
            }
            else
               count++;
         }
         System.out.println();
         double length = count;
         XYSeries series = new XYSeries("Position Graph (X vs. Y)");
         count = 1;
         while(length > 1)
         {
            series.add(count, points[count]);
            count++;
            length--;
         }
         XYDataset xyDataset = new XYSeriesCollection(series);
         JFreeChart chart = ChartFactory.createXYLineChart
            ("Position Graph", "X", "Y",
            xyDataset, PlotOrientation.VERTICAL, true, true, false);
         ChartFrame frame1=new ChartFrame("XYLine Chart",chart);
         frame1.setVisible(true);
         frame1.setSize(300,300);
         //menu();
      }
   }



   import java.awt.*;
   import java.awt.event.ActionEvent;
   import java.awt.event.ActionListener;
   import java.awt.event.KeyEvent;
   import javax.swing.*;
import javax.swing.text.JTextComponent;
   public class Gui extends JFrame {
   /**
    * 
    */
      private static final long serialVersionUID = 1L;
//
      public Gui() {
         super("Physics Calculator");
         setSize(600, 200);
         setDefaultCloseOperation(EXIT_ON_CLOSE);
      
         JPanel p = new JPanel();
         final JPanel p2 = new JPanel();
         final JPanel p3 = new JPanel(new GridBagLayout());
         
         final JPanel p4 = new JPanel();
         final JPanel p5 = new JPanel(new GridBagLayout());
         
         final JPanel p31 = new JPanel();
         final JPanel p32 = new JPanel();
         final JPanel p33 = new JPanel(new GridBagLayout());
         
         p4.setVisible(false);
         p5.setVisible(false);
         p2.setVisible(true);
         p3.setVisible(true);
      
         JButton btn1 = new JButton("Calculate Forces");
         JButton btn2 = new JButton("Calculate Instantanious Y Velocity");
         JButton btn3 = new JButton("Calculate Distance Traveled at time");
         JButton btn4 = new JButton("Graph the path traveled");
      
         btn1.setPreferredSize(new Dimension(250, 40));
         btn2.setPreferredSize(new Dimension(250, 40));
         btn3.setPreferredSize(new Dimension(250, 40));
         btn4.setPreferredSize(new Dimension(250, 40));
         
         JButton btn5 = new JButton("The Total force and angle");
         JButton btn6 = new JButton("Both X and Y forces and angle");
      
         btn5.setPreferredSize(new Dimension(250, 40));
         btn6.setPreferredSize(new Dimension(250, 40));
         
         JButton btn31 = new JButton("Yes");
         JButton btn32 = new JButton("No");
         
         btn31.setPreferredSize(new Dimension(250, 40));
         btn32.setPreferredSize(new Dimension(250, 40));

         JLabel e = new JLabel("Please Select an option");
         java.awt.Font font = new java.awt.Font("Dialog",Font.BOLD,16);
         e.setFont(font);
         JLabel f = new JLabel("Do you currently know...");
         java.awt.Font font2 = new java.awt.Font("Dialog",Font.BOLD,16);
         f.setFont(font2);
         JLabel g = new JLabel("Do you currently know the total force?");
         java.awt.Font font3 = new java.awt.Font("Dialog",Font.BOLD,16);
         e.setFont(font3);
      
      
         GridBagConstraints gbc = new GridBagConstraints();
         gbc.insets = new Insets(15,15,15,15);
      
         gbc.gridx = 0;
         gbc.gridy = 0;
         p3.add(btn1, gbc);
         gbc.gridx = 1;
         gbc.gridy = 0;
         p3.add(btn2, gbc);
         gbc.gridx = 0;
         gbc.gridy = 1;
         p3.add(btn3, gbc);
         gbc.gridx = 1;
         gbc.gridy = 1;
         p3.add(btn4, gbc);
         p2.add(e);
         
         gbc.gridx = 0;
         gbc.gridy = 0;
         p5.add(btn5, gbc);
         gbc.gridx = 1;
         gbc.gridy = 0;
         p5.add(btn6, gbc);
         p4.add(f);
         
         gbc.gridx = 0;
         gbc.gridy = 0;
         p33.add(btn31, gbc);
         gbc.gridx = 1;
         gbc.gridy = 0;
         p33.add(btn32, gbc);
         p32.add(g);
      
         add(p, BorderLayout.SOUTH);
         add(p2, BorderLayout.NORTH);
         add(p3, BorderLayout.SOUTH);
         //add(p4, BorderLayout.NORTH);
         //add(p5, BorderLayout.SOUTH);
         
      //}
      //private JComponent makeTextPanel(String string) {
      // TODO Auto-generated method stub
       //  return null;
         
      //}
      
      btn1.addActionListener(
              new ActionListener() {
              
                 @Override
                 public void actionPerformed(ActionEvent e) 
                 {
                 // TODO Auto-generated method stub
                    //PhysicsCalc.force();
                    p2.setVisible(false);
                    p3.setVisible(false);
                    p4.setVisible(true);
                    p5.setVisible(true);
                    add(p4, BorderLayout.NORTH);
                    add(p5, BorderLayout.SOUTH);
                 }
              });
        btn2.addActionListener(
              new ActionListener() {
              
                 @Override
                 public void actionPerformed(ActionEvent e) 
                 {
                 // TODO Auto-generated method stub
                    PhysicsCalc.iYVel();
                    //dispose();
                 }
              });
        btn3.addActionListener(
              new ActionListener() {
              
                 @Override
                 public void actionPerformed(ActionEvent e) 
                 {
                 // TODO Auto-generated method stub
                    p2.setVisible(false);
                    p3.setVisible(false);
                    p31.setVisible(true);
                    p32.setVisible(true);
                    p33.setVisible(true);
                    add(p31, BorderLayout.SOUTH);
                    add(p32, BorderLayout.NORTH);
                    add(p33, BorderLayout.SOUTH);
                 }
              });
        btn4.addActionListener(
              new ActionListener() {
                 @Override
                 public void actionPerformed(ActionEvent e) 
                 {
                 // TODO Auto-generated method stub
                    PhysicsCalc.graph();
                    //dispose();
                 }
              });
        
        btn5.addActionListener(
                new ActionListener() {
                
                   @Override
                   public void actionPerformed(ActionEvent e) 
                   {
                   // TODO Auto-generated method stub
                      p2.setVisible(true);
                      p3.setVisible(true);
                      p4.setVisible(false);
                      p5.setVisible(false);
                      PhysicsCalc.force1();
                   }
                });
          btn6.addActionListener(
                new ActionListener() {
                
                   @Override
                   public void actionPerformed(ActionEvent e) 
                   {
                   // TODO Auto-generated method stub

                      p2.setVisible(true);
                      p3.setVisible(true);
                      p4.setVisible(false);
                      p5.setVisible(false);
                      PhysicsCalc.force2();
                   }
                });
          btn31.addActionListener(
                  new ActionListener() {
                  
                     @Override
                     public void actionPerformed(ActionEvent e) 
                     {
                     // TODO Auto-generated method stub
                         p31.setVisible(false);
                         p32.setVisible(false);
                         p33.setVisible(false);
                         p2.setVisible(true);
                         p3.setVisible(true);
                        PhysicsCalc.xTravel1();
                     }
                  });
            btn32.addActionListener(
                  new ActionListener() {
                  
                     @Override
                     public void actionPerformed(ActionEvent e) 
                     {
                     // TODO Auto-generated method stub
                         p31.setVisible(false);
                         p32.setVisible(false);
                         p33.setVisible(false);
                         p2.setVisible(true);
                         p3.setVisible(true);
                    	 PhysicsCalc.force2();
                     }
                  });
   }
   }



Also, I wanted to thank everyone for the support. This is a really nice forum.

I uploaded the jar file of the program. Just so people can see it in action.

Physics Calculator
Was This Post Helpful? 0
  • +
  • -

#11 Gaate  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 27
  • Joined: 31-December 11

Re: GUI and .exe questions.

Posted 01 January 2012 - 03:30 PM

Program Updated.

Jar file Here

Updates
-I have done away with Most of the JOptionPanes. The only ones left are to input Higdth and time.
Now you can Put in information at the top of the program and all of the calculations can use it.
-Calculating force with only x and y force will give the rest of the program the total force value.

Problems, if anyone sees the error to these i would be very appreciative if they posted.
-JLabels dont apear in many of the panes. And only apear in the menu pain when the program is first started. Probobly something i did wrong with the set visibility in the gui class. I will go back and look later.
-There are some times when the graph can fail, i dont know exactly why it just for some reason or another doesnt work, but sometime works fine.


To Do.
- I need to double check all of the math
-Ad a main menu button and a exit button.
-Add a initial hidgth jtextframe.

   import java.util.Scanner;
   import javax.swing.*;
   import static java.lang.Math.*;
   import org.jfree.chart.*;
   import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.*;

   public class PhysicsCalc
   {
      static Scanner keyboard = new Scanner(System.in);
      static double xVel;
      static double yVel;
      static double a;
      static double tVel;
      //= xVel / sin(a);

   
      public static void main (String args[])
      {
         System.out.println("Physics Projection Calculator");
         System.out.println("By Zachary Prinzbach");
         System.out.println("");
         JOptionPane.showMessageDialog(null, "Physics Project Calculator \n By Zachary Prinzbach");
         menu();
      }
      public static void menu()
      {
         Gui fw = new Gui();
         fw.setVisible(true);

      }
      public static void force()
      {
         Gui2 sw = new Gui2();
         sw.setVisible(true);
      }
         
      public static void force1()
      {
    	  getValues();
         xVel = sin(a) * tVel;
         yVel = cos(a) * tVel;
         yVel = Math.round(yVel*100)/100.0d;
         xVel = Math.round(xVel*100)/100.0d;
         JOptionPane.showMessageDialog(null, "The amount of X-Force is " + xVel + ".\n" + "The amount of Y-Force is " + yVel + ".\n");
         //menu();
      }
      public static void force2()
      {
    	 getValues();
         tVel = xVel / sin(a);
         tVel = Math.round(tVel*100)/100.0d;
         JOptionPane.showMessageDialog(null, "The total force is " + tVel + ".\n");
         //menu();
      }
      
      public static void iYVel()
      {
    	  getValues();
         String time1 = JOptionPane.showInputDialog("Please enter the objects initial heighth");
         double time = Double.parseDouble(time1);
         double iYVel = yVel / 9.8;
         iYVel = Math.round(iYVel*100)/100.0d;
         System.out.println("Your instantanious Y Velocity at " + time + " seconds is " + iYVel + ".");
         System.out.println("");
         JOptionPane.showMessageDialog(null, "Your instantanious Y Velocity at " + time + " seconds is " + iYVel + ".\n");
         //menu();
      }
      public static void xTravel()
      {
         Gui3 tw = new Gui3();
         tw.setVisible(true);
      }
      public static void xTravel1()
      {
    	  getValues();
         String h1 = JOptionPane.showInputDialog("Please enter the objects initial heighth");
         double h = Double.parseDouble(h1);
         double xDistance = ((tVel * cos(a)) / 9.81) + Math.sqrt(Math.pow(tVel * sin(a),2) + (19.6 * h));
         xDistance = Math.round(xDistance*100)/100.0d;
         JOptionPane.showMessageDialog(null,"The object travels " + xDistance + " in the x direction before it hits the ground.\n" );
         //menu();
      }
      public static void xTravel2()
      {
    	  getValues();
         System.out.println("Please enter your angle");
         double angle = keyboard.nextDouble();
         System.out.println("Please enter the X force");
         double xForce = keyboard.nextDouble();
         System.out.println("Please enter the Y Force");
         double yForce = keyboard.nextDouble();
         double tF = xForce / sin(angle);
         System.out.println("The Total force is " + tF + ".");
         System.out.println("");
         System.out.println("How high above ground is the object initially?");
         double higth = keyboard.nextDouble();
         double xDistance = ((tF * cos(angle)) / 9.81) + Math.sqrt(Math.pow(tF * sin(angle),2) + (19.6 * higth));
         System.out.println("The object travels " + xDistance + " in the x direction before it hits the ground.");
         //menu();
      }
      public static void graph()
      {
    	  getValues();
         double[] points = new double[9999];
         double t = 1;
         double y = 1;
         String h1 = JOptionPane.showInputDialog("Please enter the objects initial heighth");
         double h = Double.parseDouble(h1);
         System.out.println();
         System.out.println("Co-ordinates (x,y)");
         int count = 1;
         while(y > 0)
         {
            points[count] = h + (count * tan(a)) - ((9.8 * Math.pow(count,2)) / (2 * Math.pow((tVel * cos(a)),2)));
            y = points[count];
            if(points[count] > 0)
            {
               System.out.println(count + "," + points[count]);
               count++;
            }
            else
               count++;
         }
         System.out.println();
         double length = count;
         XYSeries series = new XYSeries("Position Graph (X vs. Y)");
         count = 1;
         while(length > 1)
         {
            series.add(count, points[count]);
            count++;
            length--;
         }
         XYDataset xyDataset = new XYSeriesCollection(series);
         JFreeChart chart = ChartFactory.createXYLineChart
            ("Position Graph", "X", "Y",
            xyDataset, PlotOrientation.VERTICAL, true, true, false);
         ChartFrame frame1=new ChartFrame("XYLine Chart",chart);
         frame1.setVisible(true);
         frame1.setSize(300,300);
         //menu();
      }
      public static void getValues()
      {
          a = Gui.getA();
          xVel = Gui.getXVel();
          yVel = Gui.getYVel();
          tVel = Gui.getTVel();
          System.out.println(xVel + yVel + a + tVel);
      }
      public static double getxVel()
      {
    	  return xVel;
      }
      public static double getyVel()
      {
    	  return yVel;
      }
      public static double gettVel()
      {
    	  return tVel;
      }
   }


   import java.awt.*;
   import java.awt.event.ActionEvent;
   import java.awt.event.ActionListener;
   import java.awt.event.KeyEvent;
import java.util.Scanner;

   import javax.swing.*;
import javax.swing.text.JTextComponent;
   public class Gui extends JFrame {
   /**
    * 
    */
	   
	   static Scanner keyboard = new Scanner(System.in);
	      static double xVel;
	      static double yVel;
	      static double tVel;
	      static double a;
	   
      private static final long serialVersionUID = 1L;
//
      public Gui() {
         super("Physics Calculator");
         setSize(600, 300);
         setDefaultCloseOperation(EXIT_ON_CLOSE);
      
         JPanel p = new JPanel();
         final JPanel p2 = new JPanel();
         final JPanel p3 = new JPanel(new GridBagLayout());
         
         final JPanel p4 = new JPanel();
         final JPanel p5 = new JPanel(new GridBagLayout());
         
         final JPanel p31 = new JPanel();
         final JPanel p32 = new JPanel();
         final JPanel p33 = new JPanel(new GridBagLayout());
         
         final JPanel ptf = new JPanel(new GridBagLayout());
         
         p4.setVisible(false);
         p5.setVisible(false);
         p2.setVisible(true);
         p3.setVisible(true);
         ptf.setVisible(true);
         
         final JTextField jt = new JTextField(10);
         final JTextField jt2 = new JTextField(10);
         final JTextField jt3 = new JTextField(10);
         final JTextField jt4 = new JTextField(10);
      
         JButton btn1 = new JButton("Calculate Forces");
         JButton btn2 = new JButton("Calculate Instantanious Y Velocity");
         JButton btn3 = new JButton("Calculate Distance Traveled at time");
         JButton btn4 = new JButton("Graph the path traveled");
      
         btn1.setPreferredSize(new Dimension(250, 40));
         btn2.setPreferredSize(new Dimension(250, 40));
         btn3.setPreferredSize(new Dimension(250, 40));
         btn4.setPreferredSize(new Dimension(250, 40));
         
         JButton btn5 = new JButton("The Total force and angle");
         JButton btn6 = new JButton("Both X and Y forces and angle");
      
         btn5.setPreferredSize(new Dimension(250, 40));
         btn6.setPreferredSize(new Dimension(250, 40));
         
         JButton btn31 = new JButton("Yes");
         JButton btn32 = new JButton("No");
         
         btn31.setPreferredSize(new Dimension(250, 40));
         btn32.setPreferredSize(new Dimension(250, 40));

         JLabel e = new JLabel("Please Select an option");
         java.awt.Font font = new java.awt.Font("Dialog",Font.BOLD,16);
         e.setFont(font);
         JLabel f = new JLabel("Do you currently know...");
         java.awt.Font font2 = new java.awt.Font("Dialog",Font.BOLD,16);
         f.setFont(font2);
         JLabel g = new JLabel("Do you currently know the total force?");
         java.awt.Font font3 = new java.awt.Font("Dialog",Font.BOLD,16);
         e.setFont(font3);
         
         final JLabel t = new JLabel("Angle: " + a);
         final JLabel t2 = new JLabel("X Velocity: " + xVel);
         final JLabel t3 = new JLabel("Y Velocity: " + yVel);
         final JLabel t4 = new JLabel("Total Velocity: " + tVel);
      
         GridBagConstraints gbc = new GridBagConstraints();
         gbc.insets = new Insets(15,5,15,15);
         
         GridBagConstraints gbc2 = new GridBagConstraints();
         gbc2.insets = new Insets(15,5,15,15);
      
         gbc.gridx = 0;
         gbc.gridy = 1;
         p3.add(btn1, gbc);
         gbc.gridx = 1;
         gbc.gridy = 1;
         p3.add(btn2, gbc);
         gbc.gridx = 0;
         gbc.gridy = 2;
         p3.add(btn3, gbc);
         gbc.gridx = 1;
         gbc.gridy = 2;
         p3.add(btn4, gbc);
         p2.add(e);
         
         gbc.gridx = 0;
         gbc.gridy = 1;
         p5.add(btn5, gbc);
         gbc.gridx = 1;
         gbc.gridy = 1;
         p5.add(btn6, gbc);
         p4.add(f);
         
         gbc.gridx = 0;
         gbc.gridy = 1;
         p33.add(btn31, gbc);
         gbc.gridx = 1;
         gbc.gridy = 1;
         p33.add(btn32, gbc);
         p32.add(g);
         
         gbc.gridx = 0;
         gbc.gridy = 1;
         ptf.add(jt, gbc);
         gbc.gridx = 1;
         gbc.gridy = 1;
         ptf.add(jt2, gbc);
         gbc.gridx = 2;
         gbc.gridy = 1;
         ptf.add(jt3, gbc);
         gbc.gridx = 3;
         gbc.gridy = 1;
         ptf.add(jt4, gbc);
         
         gbc2.gridx = 0;
         gbc2.gridy = 0;
         ptf.add(t, gbc2);
         gbc2.gridx = 1;
         gbc2.gridy = 0;
         ptf.add(t2, gbc2);
         gbc2.gridx = 2;
         gbc2.gridy = 0;
         ptf.add(t3, gbc2);
         gbc2.gridx = 3;
         gbc2.gridy = 0;
         ptf.add(t4, gbc2);
               
         add(ptf, BorderLayout.NORTH);
         add(p, BorderLayout.SOUTH);
         add(p2, BorderLayout.CENTER);
         add(p3, BorderLayout.SOUTH);
         //add(p4, BorderLayout.NORTH);
         //add(p5, BorderLayout.SOUTH);
         
      //}
      //private JComponent makeTextPanel(String string) {
      // TODO Auto-generated method stub
       //  return null;
         
      //}
      
      btn1.addActionListener(
              new ActionListener() {
              
                 @Override
                 public void actionPerformed(ActionEvent e) 
                 {
                 // TODO Auto-generated method stub
                    //PhysicsCalc.force();
                    p2.setVisible(false);
                    p3.setVisible(false);
                    p4.setVisible(true);
                    p5.setVisible(true);
                    add(p4, BorderLayout.NORTH);
                    add(p5, BorderLayout.SOUTH);
                 }
              });
        btn2.addActionListener(
              new ActionListener() {
              
                 @Override
                 public void actionPerformed(ActionEvent e) 
                 {
                 // TODO Auto-generated method stub
                    PhysicsCalc.iYVel();
                    //dispose();
                 }
              });
        btn3.addActionListener(
              new ActionListener() {
              
                 @Override
                 public void actionPerformed(ActionEvent e) 
                 {
                 // TODO Auto-generated method stub
                    p2.setVisible(false);
                    p3.setVisible(false);
                    p31.setVisible(true);
                    p32.setVisible(true);
                    p33.setVisible(true);
                    add(p31, BorderLayout.SOUTH);
                    add(p32, BorderLayout.NORTH);
                    add(p33, BorderLayout.SOUTH);
                 }
              });
        btn4.addActionListener(
              new ActionListener() {
                 @Override
                 public void actionPerformed(ActionEvent e) 
                 {
                 // TODO Auto-generated method stub
                    PhysicsCalc.graph();
                    //dispose();
                 }
              });
        
        btn5.addActionListener(
                new ActionListener() {
                
                   @Override
                   public void actionPerformed(ActionEvent e) 
                   {
                   // TODO Auto-generated method stub
                      p2.setVisible(true);
                      p3.setVisible(true);
                      p4.setVisible(false);
                      p5.setVisible(false);
                      PhysicsCalc.force1();
                      xVel = PhysicsCalc.getxVel();
                      yVel = PhysicsCalc.getyVel();
                      
                   }
                });
          btn6.addActionListener(
                new ActionListener() {
                
                   @Override
                   public void actionPerformed(ActionEvent e) 
                   {
                   // TODO Auto-generated method stub

                      p2.setVisible(true);
                      p3.setVisible(true);
                      p4.setVisible(false);
                      p5.setVisible(false);
                      PhysicsCalc.force2();
                      tVel = PhysicsCalc.gettVel();
                      tVel = Math.round(tVel*100)/100.0d;
                      t4.setText("Total Velocity: " + tVel);
                   }
                });
          btn31.addActionListener(
                  new ActionListener() {
                  
                     @Override
                     public void actionPerformed(ActionEvent e) 
                     {
                     // TODO Auto-generated method stub
                         p31.setVisible(false);
                         p32.setVisible(false);
                         p33.setVisible(false);
                         p2.setVisible(true);
                         p3.setVisible(true);
                        PhysicsCalc.xTravel1();
                     }
                  });
            btn32.addActionListener(
                  new ActionListener() {
                  
                     @Override
                     public void actionPerformed(ActionEvent e) 
                     {
                     // TODO Auto-generated method stub
                         p31.setVisible(false);
                         p32.setVisible(false);
                         p33.setVisible(false);
                         p2.setVisible(true);
                         p3.setVisible(true);
                    	 PhysicsCalc.force2();                    	 
                     }
                  });
            jt.addActionListener(new ActionListener()
            {
            	 public void actionPerformed(ActionEvent e)
            	 {
            		 String a1 = jt.getText();
            		 a = Double.parseDouble(a1);
            		 System.out.println(a);
            		 t.setText("Angle: " + a);
            	 }
            });
            jt2.addActionListener(new ActionListener()
            {
            	 public void actionPerformed(ActionEvent e)
            	 {
            		 String xVel1 = jt2.getText();
            		 xVel = Double.parseDouble(xVel1);
            		 t2.setText("X Velocity: " + xVel);
            	 }
            });
            jt3.addActionListener(new ActionListener()
            {
            	 public void actionPerformed(ActionEvent e)
            	 {
            		 String yVel1 = jt3.getText();
            		 yVel = Double.parseDouble(yVel1);
            		 t3.setText("Y Velocity: " + yVel);
            	 }
            });
            jt4.addActionListener(new ActionListener()
            {
            	 public void actionPerformed(ActionEvent e)
            	 {
            		 String tVel1 = jt4.getText();
            		 tVel = Double.parseDouble(tVel1);
            		 t4.setText("Total Velocity: " + tVel);
            		 
            	 }
            });
   }
      public static double getA()
      {
    	  return a;
      }
      public static double getXVel()
      {
    	  return xVel;
      }
      public static double getYVel()
      {
    	  return yVel;
      }
      public static double getTVel()
      {
    	  return tVel;
      }
   }

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1