Adblock breaks this site

My First Java Program

Discussion in 'Programming General' started by Music Man, Jun 7, 2008.

  1. Music Man

    Music Man Active Member
    Banned

    Joined:
    May 17, 2008
    Posts:
    156
    Referrals:
    0
    Sythe Gold:
    0
    My First Java Program

    Well I'm in 8th grade and we are going over arc length and how to solve it.
    So I made a goal, that as my first program I would like one that solves arc length.

    Remember this is my first program, and its not the best. I am a beginning java programmer, also I'm still learning how to make the gui look neater. Anyways constructive criticism is appreciated as well as improvement tips.
    This is just basic math that the program does, but it's the first program I have made that is maybe slightly useful.



    Anyways heres the program and code -

    http://rapidshare.com/files/120881674/ArcSolver.jar.html

    class file - http://rapidshare.com/files/120881593/ArcSolver.class.html

    Dont distribute as your own copyrighted to me lol

    code -

    Code:
    import java.awt.*; 
    import javax.swing.*; 
    import java.awt.event.*; 
    
    public class ArcSolver extends JFrame implements ActionListener, 
        Runnable  { 
        Thread go; 
        JLabel central = new JLabel("Enter the Radius");
    	JLabel centralangle = new JLabel("Enter the C.A.");
    	JLabel know = new JLabel ("Do you know the Radius or Diameter of the circle?");
    	JLabel key = new JLabel ("Key  -    C.A. = Central Angle of the circle in degrees   NOTE: Replace 'Units' with the indicated measurement in your problem");
    	JLabel answer = new JLabel("The answer will be displayed here");
        JTextField centralangleinput = new JTextField(3); 
    	JTextField centralangle2 = new JTextField(3);
         JButton display = new JButton("Solve");
    	 JButton clear = new JButton("Clear");
         ButtonGroup option = new ButtonGroup(); 
         JCheckBox quickpick = new JCheckBox("Radius", true); 
          JCheckBox personal = new JCheckBox("Diameter", false);
    	  int longer = 0;
    	  double circumference;
    	  double cir2;
    	  double cir3;
    	  double cir4;
    	  double cir5 = 360;
    	  String measurement;
         
    	  
        ArcSolver() { 
            super("Edward's Arc Length Solver"); 
             setSize(730, 170); 
             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
             Container content = getContentPane(); 
             BorderLayout bord = new BorderLayout(); 
    		 BorderLayout bord2 = new BorderLayout();
             content.setLayout(bord);
    		 clear.addActionListener(this);
            display.addActionListener(this);
            quickpick.addActionListener(this); 
    		personal.addActionListener(this); 
            centralangleinput.addActionListener(this);		
             JPanel topPanel = new JPanel(); 
    		 JPanel leftPanel = new JPanel();
    		 JPanel eddie = new JPanel();
    		 JPanel inside = new JPanel();
    		 JPanel inside2 = new JPanel();
    		 leftPanel.setLayout(bord2);
    		 //topPanel.setLayout(lay);
    		 //eddie.add(cool);
    		 eddie.add(key);
            topPanel.add(central);
            topPanel.add(centralangleinput); 
    		topPanel.add(centralangle); 
    		topPanel.add(centralangle2);
    		JPanel secondtop = new JPanel();
             topPanel.add(display); 
    		 topPanel.add(clear);
    		 inside.add(know);
    		 inside.add(quickpick);
    		 inside.add(personal);
    		 inside2.add(answer);
    		 option.add(quickpick); 
             option.add(personal);
    		 leftPanel.add(inside, BorderLayout.NORTH);
    		 leftPanel.add(inside2, BorderLayout.SOUTH);
            content.add(topPanel, BorderLayout.NORTH);  
            content.add(leftPanel, BorderLayout.CENTER);
            content.add(eddie, BorderLayout.SOUTH);		
            setVisible(true); 
         } 
     
        public void actionPerformed(ActionEvent evt) { 
             Object source = evt.getSource();
    		 if(source == personal){		 
             central.setText("Enter the Diameter");
    		 longer += 1;
    
            }else if(source == quickpick) {
            central.setText("Enter the Radius");
    		longer -= 1;
    
            }else if(source == display) {		
            display.setEnabled(false);
            centralangleinput.setEnabled(false);	
            centralangle2.setEnabled(false);
            personal.setEnabled(false);	
    		quickpick.setEnabled(false);
            if (go == null) { 
                 go = new Thread(this); 
                 go.start(); 	 
    			 
            }  
        }else if(source == clear){
        go = null;
    	personal.setEnabled(true);
    	quickpick.setEnabled(true);
    	display.setEnabled(true);
    	centralangleinput.setEnabled(true);	
        centralangle2.setEnabled(true);
    	centralangleinput.setText(null);
    	centralangle2.setText(null);
    	circumference = 0;
    	answer.setText("The answer will be displayed here");
    	if(longer == 0){
    		central.setText("Enter the Radius");
            		}else if(longer == 1) {
    				central.setText("Enter the Diameter");
    				}
    	
    	   }
    }
    	
    	
    	
    	
    	
    
       public void run() { 
                    int radiusin = Integer.parseInt(centralangleinput.getText());
    		int centralin = Integer.parseInt(centralangle2.getText());
                    if(centralin > 360 || centralin < 0) {
                    
                    centralangle2.setEnabled(false);
                    answer.setText("Please enter a valid Central Angle, remember this is from a circle so the most it can be is 360, press clear to try again");
    
                    }else
    		if(longer == 0){
    		circumference = radiusin * 2;
    		cir2 = circumference * Math.PI;
    		cir3 = cir2 * centralin;
    		cir4 = cir3 / cir5;
    		answer.setText("The Arc Length is " + cir4 + " Units");
                        
            		}else if(longer == 1) {
    				circumference = radiusin * Math.PI;
    				cir2 = circumference * centralin;
    				cir3 = cir2 / cir5;
    				answer.setText("The Arc Length is " + cir3 + "Units");
    				}
        } 
    
          public static void main(String[] arguments) { 
          ArcSolver frame = new ArcSolver ();
         } 
     } 
    
     
  2. Kin Kong

    Kin Kong Forum Addict
    Banned

    Joined:
    Feb 4, 2008
    Posts:
    356
    Referrals:
    0
    Sythe Gold:
    0
    My First Java Program

    It's Decent. How many Classes can you currently do ?
     
  3. the pawesome owner

    the pawesome owner Member

    Joined:
    Nov 23, 2007
    Posts:
    60
    Referrals:
    0
    Sythe Gold:
    0
    My First Java Program

    Hmm... good for your first try. ;)
     
< Benchmark test - VB6/VC6/Delphi6/Java | How was runescape made? >


 
 
Adblock breaks this site