Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

beginner question for java appelets regarding positioning.

800740Sep 26 2010 — edited Oct 3 2010
I am creating a java appelet, and I am having issues positioning labels, text boxes , buttons. Is there a way I can specify where each is positioned?

Thank you!

for example here is my code:
import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;

public class AdditionOfFractions extends Applet implements ActionListener {
    Label Num1Lbl = new Label("num1");
    Label Num2Lbl = new Label("num2");
    Label Den1Lbl = new Label("den1");
    Label Den2Lbl = new Label("den2");
    Label ResultLbl = new Label("Result");

    TextField Num1Text = new TextField(4);
    TextField Num2Text = new TextField(4);
    TextField Den1Text = new TextField(4);
    TextField Den2Text = new TextField(4);
    TextField ResultText = new TextField(4);

    Button ComputeBtn  = new Button("Compute");
    Button ExitBtn  = new Button("Exit");

    public void actionPerformed(ActionEvent thisEvent)throws NumberFormatException {

        if(ComputeBtn.hasFocus()){
            System.out.println("test");

            int num1 = Integer.parseInt(Num1Text.getText());
            int num2 = Integer.parseInt(Num2Text.getText());
            int den1 = Integer.parseInt(Den1Text.getText());
            int den2 = Integer.parseInt(Den2Text.getText());
            int newDen = 0;

            if(den1 != den2){

            }
        }
    }

    public void init()
    {   
        //initialise
        ResultText.setEditable(false);
        ComputeBtn.addActionListener(this);
        ExitBtn.addActionListener(this);

        //add components
        add(Num1Lbl);
        add(Num1Text);
        add(Den1Lbl);
        add(Den1Text);
        add(Num2Lbl);
        add(Num2Text);
        add(Den2Lbl);
        add(Den2Text);
        add(ResultLbl);
        add(ResultText);
        add(ComputeBtn);
        add(ExitBtn);


    }

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 31 2010
Added on Sep 26 2010
10 comments
512 views