Results 1 to 3 of 3
  1. #1
    l3eater is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Default Creating a Main Menu - Importing

    Hello,

    The main part of my program is some-what completed (It's a converter) but the problem I have is making a main menu; I have little knowledge as to how to import my program to a button on the main menu that would open my program when clicked.

    Basically, I need help making a button that would open my program.

    As well, when my program (prior to what I've posted above) is executed, there is really nothing that tells the users which textfield is to convert which. E.g, there are two textfields but there are no headers/titles above them that indicates it's Canadian dollars to British Pounds. How would I add something like a header into the program?

    Java Code:
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    
    public class GameApp extends Applet
    {
    
        private TextField input1;
        private TextField output1;
    
        private TextField input2;
        private TextField output2;
    
        public void init ()
        {
            //First textfield and buttons
            this.input1 = new TextField (20);
            this.output1 = new TextField (30);
            Button A = new Button ("Convert");
    
            this.add (input1);
            this.add (A);
            this.add (output1);
    
            FirstAction fa = new FirstAction (input1, output1);
            A.addActionListener (fa);
            this.input1.addActionListener (fa);
    
            //Second textfield and buttons
            this.input2 = new TextField (20);
            this.output2 = new TextField (30);
            Button B = new Button ("Convert");
    
            this.add (input2);
            this.add (B);
            this.add (output2);
    
            SecondAction sa = new SecondAction (input2, output2);
            B.addActionListener (sa);
            this.input2.addActionListener (sa);
    
        }
    }
    
    //Canadian Dollars to British Pounds
    class FirstAction implements ActionListener
    {
        private TextField in;
        private TextField out;
    
        public FirstAction (TextField in, TextField out)
        {
            this.in = in;
            this.out = out;
        }
    
    
        public void actionPerformed (ActionEvent fa)
        {
    
            double Con1 = 0.627;
            double total;
            String num = in.getText ();
            double stringInt = Double.parseDouble (num);
            //double doubleInt = (int) (Con1);
            total = stringInt * Con1;
            //double round = Round(total, 3);
            String intString = Double.toString (total);
            out.setText (intString + " in British Pounds");
    
        }
    }
    
    class SecondAction implements ActionListener
    {
        private TextField in;
        private TextField out;
    
        public SecondAction (TextField in, TextField out)
        {
            this.in = in;
            this.out = out;
        }
    
    
        public void actionPerformed (ActionEvent fa)
        {
    
            double Con1 = 0.752;
            double total;
            String num = in.getText ();
            double stringInt = Double.parseDouble (num);
            //double doubleInt = (int) (Con1);
            total = stringInt * Con1;
    
            String intString = Double.toString (total);
            out.setText (intString + " in Euros");
    
        }
    }

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    786
    Rep Power
    5

    Default

    Use Labels ? Or use Swing instead of AWT, then you could use Tooltips + Labels :D

  3. #3
    l3eater is offline Member
    Join Date
    Dec 2010
    Posts
    2
    Rep Power
    0

    Default

    Quote Originally Posted by eRaaaa View Post
    Use Labels ? Or use Swing instead of AWT, then you could use Tooltips + Labels :D
    Hey, that worked! Thank you, now my convert has titles so it won't be that confusing - more user friendly!

    As for my importing question, are you able to answer it? I just basically need to know how to make a button so that when it's clicked, the code posted on my first post would appear.

Similar Threads

  1. Creating menu screen for games
    By sahildave1991 in forum AWT / Swing
    Replies: 1
    Last Post: 07-02-2010, 05:36 PM
  2. Replies: 2
    Last Post: 04-04-2009, 05:03 PM
  3. Replies: 0
    Last Post: 10-28-2008, 09:28 PM
  4. Help making a main menu.
    By pbd2 in forum Java Applets
    Replies: 2
    Last Post: 10-17-2008, 10:53 AM
  5. Replies: 3
    Last Post: 12-15-2007, 11:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •