Zelaron Gaming Forum  
Stats Arcade Portal Forum FAQ Community Calendar Today's Posts Search
Go Back   Zelaron Gaming Forum > The Zelaron Nexus > Science and Art > Tech Help

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next

 
JAVA help
Reply
Posted 2006-04-09, 07:18 PM
I'm having some trouble in my java class at school. We are making a calculator program. I have the display and buttons and everything good. The only thing i need help on is getting the numbers up to the text field after i press the button. We arn't worrying about multiplication, addition or anything yet, so i dont think this will be too hard. The numbers just have to appear up in the text field. This is what i have so far.

Code:
 import java.applet.*;
import java.awt.*;


public class Calculator extends Applet {

  private TextField screen;

  public void init () {
 
    this.setLayout(new GridLayout(3, 1, 3, 3));
    Panel A1 = new Panel();
    this.add(A1);
    Panel A2 = new Panel();
    this.add(A2);
    Panel A3 = new Panel();
    this.add(A3);
    A1.setLayout(new GridLayout(2, 1));
    screen = new TextField(12);
    A1.add(screen);
    Panel B1 = new Panel();
    B1.setLayout(new GridLayout(1, 4, 3, 3));
    B1.add(new Button("C"));
    B1.add(new Button("="));
    B1.add(new Button("/"));
    B1.add(new Button("*"));
    A1.add(B1);
    A2.setLayout(new GridLayout(2, 4, 3, 3));
    A2.add(new Button("7"));
    A2.add(new Button("8"));
    A2.add(new Button("9"));
    A2.add(new Button("C"));
    A2.add(new Button("4"));
    A2.add(new Button("5"));
    A2.add(new Button("6"));
    A2.add(new Button("+"));
    A3.setLayout(new GridLayout(1, 2, 3, 3));
    // 1, 2 and 0
    Panel B2 = new Panel();
    B2.setLayout(new GridLayout(2, 1, 3, 3));
    // 1 and 2
    Panel C1 = new Panel();
    C1.setLayout(new GridLayout(1, 2, 3, 3));
    C1.add(new Button("1"));
    C1.add(new Button("2"));
    B2.add(C1);
    B2.add(new Button("0"));
    // 3, . and =
    Panel B3 = new Panel();
    B3.setLayout(new GridLayout(1, 2, 3, 3));
    // 3 and .
    Panel C2 = new Panel();
    C2.setLayout(new GridLayout(2, 1, 3, 3));
    C2.add(new Button("3"));
    C2.add(new Button("."));
    B3.add(C2);
    B3.add(new Button("="));
    A3.add(B2);
    A3.add(B3);

  }

  public Insets getInsets() {
    return new Insets(5, 5, 5, 5);
  }

}
Old
Profile PM WWW Search
platnum is neither ape nor machine; has so far settled for the in-betweenplatnum is neither ape nor machine; has so far settled for the in-between
 
 
platnum
 



 

Bookmarks

« Previous Thread | Next Thread »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules [Forum Rules]
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -6. The time now is 04:08 PM.
'Synthesis 2' vBulletin 3.x styles and 'x79' derivative
by WetWired the Unbound and Chruser
Copyright ©2002-2008 zelaron.com
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
This site is best seen with your eyes open.