-
Need Debug Help
Ok this compiles fine only thing is its not right ... the layout is all screwed up ????? got this code from my book so i have no clue whats wrong the code might be screwed up in the book to it said to "S" where the first "5" is in this snipt of code "constraints.insets = new Insets(5,5,5,5);" any ideas
Code:
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class List extends Applet implements ActionListener
{
Label lblDept = new Label("Department:");
Label lblName = new Label("Name:");
Label lblPhone = new Label("Extension:");
TextField txtDept = new TextField(15);
TextField txtName = new TextField(25);
TextField txtPhone = new TextField(5);
TextArea txaPhoneList = new TextArea(10,30);
Button btnAdd = new Button("Add to List");
String strDept;
String strName;
String strPhone;
public void init()
{
DesignLayout();
txtDept.requestFocus();
btnAdd.addActionListener(this);
txtDept.addActionListener(this);
txtName.addActionListener(this);
txtPhone.addActionListener(this);
}
public void DesignLayout()
{
GridBagLayout gridbag = new GridBagLayout();
GridBagConstraints constraints = new GridBagConstraints();
setLayout(gridbag);
constraints.insets = new Insets(5,5,5,5);
//Row 1 Label
constraints.gridx = 0;
constraints.gridy = 0;
constraints.anchor = GridBagConstraints.EAST;
gridbag.setConstraints(lblDept,constraints);
add(lblDept);
//Row 1 TextField
constraints.gridx = 1;
constraints.anchor = GridBagConstraints.WEST;
gridbag.setConstraints(txtDept,constraints);
add(txtDept);
//Row2 Label
constraints.gridy = 1;
constraints.gridx = 0;
constraints.anchor = GridBagConstraints.EAST;
gridbag.setConstraints(lblName,constraints);
add(lblName);
//Row2 TextField
constraints.gridx = 1;
constraints.anchor = GridBagConstraints.WEST;
gridbag.setConstraints(txtName,constraints);
add(txtName);
//Row3 Label
constraints.gridx = 0;
constraints.gridy = 2;
constraints.anchor = GridBagConstraints.EAST;
gridbag.setConstraints(txtPhone,constraints);
add(txtPhone);
//Row3 TextField
constraints.gridx = 1;
constraints.anchor = GridBagConstraints.WEST;
gridbag.setConstraints(txtPhone,constraints);
add(txtPhone);
//Row 4 Button
constraints.gridy = 3;
gridbag.setConstraints(btnAdd,constraints);
add(btnAdd);
//Row5 TextArea
constraints.gridx = 4;
gridbag.setConstraints(txaPhoneList,constraints);
add(txaPhoneList);
}
public void actionPerformed(ActionEvent p1)
{
String strOutPutLine;
strDept = txtDept.getText();
strName = txtName.getText();
strPhone = txtPhone.getText();
strOutPutLine = strDept + "\t" + strName + "\t" + strPhone;
txaPhoneList.append(strOutPutLine + "\n");
txtDept.setText("");
txtName.setText("");
txtPhone.setText("");
txtDept.requestFocus();
}
}
-
-
Hey 308. What is the user interface supposed to look like? And what does it look like now? I want to run your code but i have to goto work soon so ill have to wait till later. :)
-
is all off centered and looks like a mess it all saposed to be all lined up anc centered