Re: Please thiHelp
From: Mary (Mary_at_discussions.microsoft.com)
Date: 06/11/04
- Previous message: Mary: "Re: Please thiHelp"
- In reply to: George Birbilis [MVP J#] [9880]: "Re: Please thiHelp"
- Next in thread: Lars-Inge Tønnessen: "Re: Please thiHelp"
- Reply: Lars-Inge Tønnessen: "Re: Please thiHelp"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 10 Jun 2004 19:19:01 -0700
How do i make a Calculator in J#
"George Birbilis [MVP J#] [9880]" wrote:
> grab the book "Thinking in Java" from www.eckel-objects.com (Bruce Eckel has
> it for free there)
> see the "Applet" section on how to make Java applets
>
> you don't use a "public static void main" method in an Applet class (unless
> you also want it to be runnable from the command line as an application)
> just do something like:
>
> import java.applet.Applet;
>
> public class MyClass
> extends Applet
> {
>
> public void init(){
>
> }
>
> public void start(){
>
> }
>
> public void stop(){
>
> }
>
> public void destroy(){
>
> }
>
> }
>
> and fill-in the (optional) init/start/stop/destroy methods there, init is
> called when applet is initialized after class loading, start when visible
> area is created for the applet and its ready to interact with user, stop
> when you go back/forward in the browser and applet should say stop playing
> sounds etc. since it's not visible anymore, destroy is called if
> windows/browser closes. Start/Stop may be called many times in between if
> user goes back/forward a page (some browsers may even call destroy and then
> init in such scenario, instead of keeping the applet alive when user goes
> back/forward in page navigation history)
>
> cheers,
> George
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> George Birbilis <birbilis@kagi.com> [MVP J#] [9880]
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> + QuickTime VCL and ActiveX controls (for PowerPoint/VB/Delphi etc.)
> + Plugs VCL and ActiveX controls (InterProcess/Internet communication)
> + TransFormations, VB6 forms to ASP.net WebForms convertion
> http://www.kagi.com/birbilis
> + Robotics
> http://www.mech.upatras.gr/~robgroup
> .........................................................................
>
> > I tried your applet for the calculation and it worked in java sun but how
> do I make the calculations work
> > How would i get this one to work with an applet?
> > import java.io.*;
> >
> > class savingsacct
> > public static void main (String[] args) throws IOException {
> >
> > BufferedReader stdin = new BufferedReader
> > (new InputStreamReader(System.in));
> > // declares three integers
> > double num1, num2, sum, dollars; // declares a number that can
> >
> > have decimals
> >
> > System.out.print ("What is the amount of your Withdrawl? $");
> > System.out.flush();
> >
> > // read a line, and then converts it to an integer
> > num1=Double.parseDouble(stdin.readLine());
> >
> > System.out.print ("What is the amount of your Deposit? $");
> > System.out.flush();
> > num2 = Double.parseDouble(stdin.readLine());
> >
> > sum = num1 - num2; // Adds the two numbers;
> > dollars = 1000.09 - sum;
> > System.out.println("Your Balance is : $" + dollars);
> > } // method main
> > }
> >
> >
> > "Lars-Inge Tonnessen" wrote:
> >
> > >
> > > You can't put windows forms in an applet. Please must use awt and layout
> > > managers. Java is not as "friendly" as windows when it comes to GUI
> > > design. If you don't use layout managers, your applet will look funny on
> other
> > > operating systems like Macs and Unix/Linuxes.
> > >
> > > ( Did serialization (save/load) work for your desktop app? )
> > >
> > >
> > >
> > > Call this file "gui.java"
> > >
> > > import java.applet.*;
> > > import java.awt.*;
> > > import java.awt.event.*;
> > >
> > > // ActionListener is for the "caclulate" button.
> > > public class gui extends java.applet.Applet implements ActionListener
> > > {
> > > private Label label_header;
> > >
> > > private TextField text_deposit;
> > > private TextField text_withdrawl;
> > > private TextField text_Interest;
> > > private TextField text_Balance;
> > >
> > > private Label label_Deposit;
> > > private Label label_Withdrawl;
> > > private Label label_Interest;
> > > private Label label_Balance;
> > >
> > > private Button but_calc;
> > >
> > > public void init( )
> > > {
> > > text_deposit = new TextField();
> > > text_withdrawl = new TextField();
> > > text_Interest = new TextField();
> > > text_Balance = new TextField();
> > >
> > > but_calc = new Button("Calculate");
> > > but_calc.addActionListener( this );
> > >
> > > label_header = new Label("Status: Ready");
> > > label_Deposit = new Label("Deposit :");
> > > label_Withdrawl = new Label("Withdrawl :");
> > > label_Interest = new Label("Interest :");
> > > label_Balance = new Label("Balance :");
> > >
> > > setLayout( new GridLayout(7,1) );
> > > add( label_header );
> > >
> > > Panel deposit_Panel = new Panel();
> > > deposit_Panel.setLayout( new GridLayout(1,3) );
> > > deposit_Panel.add( label_Deposit );
> > > deposit_Panel.add( text_deposit );
> > > deposit_Panel.add( new Label() );
> > > add( deposit_Panel );
> > >
> > > Panel withdrawl_Panel = new Panel();
> > > withdrawl_Panel.setLayout( new GridLayout(1,3) );
> > > withdrawl_Panel.add( label_Withdrawl );
> > > withdrawl_Panel.add( text_withdrawl );
> > > withdrawl_Panel.add( new Label() );
> > > add( withdrawl_Panel );
> > >
> > > Panel button_Panel = new Panel();
> > > button_Panel.setLayout( new GridLayout(1,3) );
> > > button_Panel.add( new Label("") );
> > > button_Panel.add( but_calc );
> > > button_Panel.add( new Label("") );
> > > add( button_Panel );
> > >
> > > Panel interest_Panel = new Panel();
> > > interest_Panel.setLayout( new GridLayout(1,3) );
> > > interest_Panel.add( label_Interest );
> > > interest_Panel.add( text_Interest );
> > > interest_Panel.add( new Label() );
> > > add( interest_Panel );
> > >
> > > Panel balance_Panel = new Panel();
> > > balance_Panel.setLayout( new GridLayout(1,3) );
> > > balance_Panel.add( label_Balance );
> > > balance_Panel.add( text_Balance );
> > > balance_Panel.add( new Label() );
> > > add( balance_Panel );
> > >
> > > }
> > >
> > >
> > > // The calculate button was pushed....
> > > public void actionPerformed( java.awt.event.ActionEvent event )
> > > {
> > > Button source = (Button)event.getSource();
> > >
> > > if ( source == but_calc )
> > > {
> > > label_header.setText("Calc button!!!");
> > > }
> > > }
> > >
> > >
> > > }
> > >
> > >
> > >
> > > <HTML>
> > > <BODY>
> > > <center>Banking</center>
> > > <BR>
> > > </BR>
> > > <CENTER>
> > > <APPLET CODE="gui.class" WIDTH="200" HEIGHT="150" VIEWASTEXT>Error!
> Please enable
> > > Java </APPLET>
> > > </CENTER>
> > > </BODY>
> > > </HTML>
> > >
> > >
> > >
> > >
> > > Regards,
> > > Lars-Inge Tonnessen
> > >
> > >
> > >
>
>
>
- Previous message: Mary: "Re: Please thiHelp"
- In reply to: George Birbilis [MVP J#] [9880]: "Re: Please thiHelp"
- Next in thread: Lars-Inge Tønnessen: "Re: Please thiHelp"
- Reply: Lars-Inge Tønnessen: "Re: Please thiHelp"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|